How MediaWiki, software that runs Wikipedia, is tested
by Željko Filipin
Yesterday I gave a talk titled How MediaWiki, software that runs Wikipedia, is tested at DORS/CLUC 2013 conference. The talk consisted of a few parts, each lasting a few minutes. The video of the talk (in Croatian) is available (I start at 32:25).
Part One
A few words about myself. I have showed this site and DORS/CLUC 2013 article (I was liveblogging).
Part Two
Short version of Quim Gil’s How to hack on Wikipedia talk (sources: FOSDEM 2013, MediaWiki).
Part Three
Short Selenium + Ruby live coding demo. The example at the talk was slightly different.
I have first opened a test site manually, clicked Print/export
link (sidebar at the left hand side) so Download as PDF
link appears.
Print/export
Download as PDF
I have then click Download as PDF
link and showed that Download the file
link should appear (after a while) at the page that opens.
Please wait while the document is being generated.
Download the file
Next we did the same with Selenium. I like irb for live coding, so the first step is to open it.
I like Watir API better than the official Selenium Ruby bindings (selenium-webdriver gem) so the examples use watir-webdriver gem.
Open Firefox browser.
Go to the test site.
Click Print/export
and Download as PDF
links.
Check if Download the file
link appeared.
Close the browser.
Now, do the same thing in Chrome, just because we can.
Please notice that except the line that opens the browser, everything else is the same. Just for fun, let’s do the same thing in PhantomJS.
Before closing the browser, let’s take a screenshot. Screenshot of a headless browser? There is a joke here somewhere. If only I could find it.
PhantomJS screenshot
It would be crazy to type this stuff all the time, so let’s create a script that we can just run. I have executed Click on Download as PDF link scenario. From pdf_readonly.feature file.
The scenario failed.
The problem is that the test waits 15 seconds for Download the file
link to appear, and sometimes it takes longer. This time it took longer and the test failed.
Part Four
A short overview of the complete browser test automation solution that we have developed. The code is hosted at Gerrit (qa/browsertests) and there is GitHub mirror (wikimedia/qa-browsertests). We use RVM to manage Ruby versions and gemsets. .ruby-version file.
.ruby-gemset file.
We use Bundler to manage project dependencies. Gemfile file.
From Gemfile.lock file.
We use Cucumber (features folder) as a tool for communication between people that know what needs to be tested and people that know how to write browser test automation code. Cucumber is one of the really important tools in our toolchain. I have showed Cucumber code for Click on Download as PDF link scenario. From pdf_readonly.feature file.
Then I showed how Given I am at random page step is implemented. From search_steps.rb file.
As you can see, the implementation is trivial. RandomPage is also pretty simple. From random_page.rb file.
URL module is simple too. url_module.rb file.
I have explained that we use the Page Object pattern and page-object gem. Page object pattern is another important tool. It allows us to write maintainable code.
A slightly more complicated step is When I click on Download as PDF
.
From pdf_steps.rb file.
From random_page.rb file.
We use Jenkins continuous integration server. It is also one of the important tools. Jenkins that runs our browser test automation is hosted by CloudBees at wmf.ci.cloudbees.com. I have showed a job that is sometimes failing because of the timeout problem that I have mentioned previously. I have showed a couple of nice Jenkins features, Test Result Trend chart and Build Time Trend chart.
Test Result Trend
Build Time Trend
Then I showed a build that failed and test results saying timed out after 15 seconds, waiting for {:text=>"Download the file", :tag_name=>"a"} to become present
.
I have ended the talk with showing Sauce Labs (Selenium in the cloud) job for the failed Jenkins job. Sauce Labs job has logs, screens shots and video of the entire test.
Part Five
There were a few questions from the audience, and I did my best to answer them.
Part Six
At the next break I was handing out t-shirts, pens, stickers, badges and talking with people about my talk and related things.
Ideas for the next talk
A few ideas came to my mind after the talk. It would be fun to show how to run the test on my machine but instead of running the browser there too, run the browser at Sauce Labs. For those interested in playing with the code themselves, show MediaWiki-Vagrant and puppet/modules/browsertests, the complete environment in a virtual machine. Setting everything up is as easy as installing a couple of applications and cloning a repository. If you want to get involved, join qa@lists.wikimedia.org mailing list and introduce yourself.
The screen shot shows a Mac desktop. On the right hand side you can see two Mac windows (Terminal, VirtualBox). On the left hand side you can see Firefox window forwarded from a Linux virtual machine. Magic.
tags: code - event - facebook - photo - selenium - speaker - testing - testival - video - wikimedia - youtube