[QA] Create test data at run time via API

Chris McMahon cmcmahon at wikimedia.org
Fri Jan 24 22:34:15 UTC 2014


Jeff has done a great job with this.  He and I met in person today to make
some improvements. We are very close to checking it in, but we encountered
some anomalous behavior having to do with login and edit credentials among
various users and various wikis, beta labs, test2wiki, and local
environments.  Until we figure out what's causing that behavior we're not
quite ready to push this out completely.

However, it does do the right thing, and the architecture is sound.
 WARNING: if your user does not login to the target wiki properly, let us
know at https://bugzilla.wikimedia.org/show_bug.cgi?id=60407

You can play with it by reviewing https://gerrit.wikimedia.org/r/#/c/106548/

SCENARIOS

In your foo.feature file, you can now specify in a Scenario:

   Given I create a wiki page with title MY TEST WIKI PAGE and with content
STUFF MY TEST EXPECTS TO FIND IN THE PAGE

and it will Just Work.

* If the page does not exist in the target wiki, it will be created.
* If the page exists in the target wiki *with the same content*, it will
*not* be updated.
* If the content specified in the foo.feature file is different than the
existing wiki page, the page will be updated, the update will show
correctly in Recent Changes, View History, etc.
* Your test will not proceed until the target wiki acknowledges the
transaction, so tests should be safe from race conditions.

STEPS

The step that implements creating a wiki page invokes a method
create_wiki_article that accepts four arguments to be passed to the
Mediawiki API in order to create an article:

  create_wiki_article(ENV["MEDIAWIKI_USER"], ENV["MEDIAWIKI_PASSWORD"],
api_title, api_content)

SUPPORT

Note that there is no foo.page file associated with an API call.  (The API
is not a page, has no page elements, etc., so need for a PageObject file to
invoke it.)

Instead the create_wiki_article code is kept in a file /support/article.rb.
 We use require_relative in the steps file for access to the article API
call. Ultimately this will reside in the mediawiki/selenium Ruby gem.

CREATING AN ARTICLE FROM A TEST

In order to create an article from a test, the following environment
variables are required:

MEDIAWIKI_USER (standard)
MEDIAWIKI_PASSWORD (standard)
MEDIAWIKI_URL (standard)
API_URL (new: usually of the form http://test2.wikipedia.org/w/api.php

and the page is created with the following data:

Title set in the .feature file
Page set in the .feature file
Summary is hard coded as "Article created via an API 'edit' call."
A category is added to each page [[Category:Browsertest article]] for
future reference.

RANDOM VALUES FOR TITLE AND CONTENT

If random values are required for a test, we recommend manipulating those
in the .steps file and passing those values to create_wiki_article in the
.steps file.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wikimedia.org/pipermail/qa/attachments/20140124/0858502b/attachment-0001.html>


More information about the QA mailing list