Page MenuHomePhabricator

investigate using API to set up test data for browser tests
Closed, ResolvedPublic


Using a browser to create a new page in a test wiki and to populate that page with test data is prohibitively expensive and takes a long time.

Using the API to create pages at runtime containing particular text and/or data should be significantly faster and more reliable.

Version: unspecified
Severity: normal
See Also:



Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 2:24 AM
bzimport set Reference to bz58939.

jhall wrote:

Building off the work that Aaron Arcos did for Bug 58555, we can use this Python library for Mediawiki interaction:

…and then create a script as simple as this to create a new wiki article:

import mwclient
site = mwclient.Site('')
site.login('<username>', '<password>')
page = site.Pages['Dune Messiah']
text = page.edit() + u'\nDune Messiah is a book by Frank Herbert.', summary = 'Page created via API call')

While we could also do this via Ruby, it seems that we might want to use Python instead for consistency with the API test(s) that Aaron has already developed. Added bonus is that the "mwclient" library for Python seems to be actively maintained, while most of the Ruby libraries listed here do not appear to be actively maintained:

Change 103764 had a related patch set uploaded by Jhall:
WIP Script to create new article with random page title

jhall wrote:

Changing bug status since task in still WIP.

jhall wrote:

I modified a single page file in this WIP Gerrit commit:

With this modification, when either the "aftv5.feature" or "page_edit.feature" tests are run, the "aftv5_page.rb" script calls a Python script (which in turn calls the Mediawiki API) and creates a new, randomly-named page via that API call. Each test step from the feature file is then run against that newly-created page.

Note: The Python script does assume that the environment variable API_URL has been defined, so it knows what environment to run against.

A few items we'll want to consider:

  1. Python was chosen for the API client calls due to previous API test work done by Aaron Aarcos in Python, but we could almost certainly do the same thing from Ruby (or another language) if there are objections to Python.
  1. Per a conversation with Chris, if this initial approach seems fine, then we should also write a script to create a new user login via the API, and modify tests so that they use both the newly-ceated user account and the newly-created wiki article when they run.

Change 103764 abandoned by Jhall:
WIP Script to create new article with random page title

Abandoning this commit so that I can start fresh on the all-Ruby solution (bye-bye Python).

jhall wrote:

Yep, this one is resolved, and documentation on the new test setup methods has been added to