Announcing pytest-mozwebqa 1.0

Finally I can announce that I have released version 1.0 of the pytest plugin used by Mozilla’s Web QA team! It’s been in use for several months now, but I’ve paid off some long standing technical debt, and now consider it stable!

I should say that although this plugin was primarily developed for Mozilla’s Web QA team, anyone that wants to write test automation for websites in Python can take advantage of it. There’s very little that is specific to Mozilla, and this can easily be overridden on the command line, or you could simply fork the project and create your own version of the plugin. Anyway, as I haven’t previously announced the plugin, it’s probably a good idea for me to explain what it actually does…

Selenium integration
The primary feature of the plugin is the ability for it to launch and interact with a web browser. It does this by integrating with either the RC or WebDriver APIs provided by the Selenium browser automation framework. The browser is launched ahead of every test, unless the test is specifically decorated to indicate that the test does not require a browser:

def test_with_browser(self, mozwebqa):
@pytest.mark.skip_selenium
def test_without_browser(self, mozwebqa):

The plugin works with a local WebDriver instance, with a remote server (RC or WebDriver), and with Selenium Grid (also RC or WebDriver).

Sauce Labs integration

You can also use this plugin to run your tests in the cloud using your Sauce Labs account. The integration allows you to specify a build identifier and tags, which help when filtering the Sauce Labs jobs. To enable Sauce Labs integration, you simply need to specify a credentials file on the command line, which is a YAML file in the following format:

username: value
api-key: value

When tests are run using Sauce Labs, there will also be additional items in the HTML report, such as the video of the test and a link to the job.

If you don’t have a Sauce Labs account already, you can sign up for one here. Sauce Labs is used by Mozilla whenever we need to run on browser/platform combinations that our own Selenium Grid doesn’t support, or whenever we need boost up the number of testruns such as before a big deployment.

Credentials
The plugin allows you to store your application’s credentials in a YAML file as specified on the command line. This is an important feature for Mozilla, where the credentials files are stored in a private repository. Anyone wanting to contribute or run the tests themselves, simply has to create an account and a YAML file.

Fail fast
Have you ever been frustrated when you’ve kicked off your suite of several hundred tests, just for every single one of them to launch a browser despite the application under test being unavailable? It’s happened to me enough times that I added an initial check to ensure the base URL of the application is responding with a 200 OK; This saves so much time.

Protect sensitive sites
I’ll leave the debate on whether you should be running your tests against sensitive environments such as production for someone else, but if you do decide to do this, the plugin gives you a little bit of extra protection. For a start, all tests are considered destructive and therefore will not run by default. You can explicitly mark tests as non-destructive. Having an opt-in system is more maintenance (I know it’s a pain), but much lower risk. I’d rather accidentally not be running a non-destructive test against production than accidentally run a destructive one, and I have felt this pain before!

def test_implied_destructive(self, mozwebqa):
@pytest.mark.nondestructive
def test_explicitly_nondestructive(self, mozwebqa):

Of course, for some environments, you will want to run your destructive tests, and you can do so by specifying the --destructive command line option.

There’s also a final safety net just in case you try running destructive tests against a sensitive environment. This skips any destructive tests that are run against a URL that matches a regular expression. For Mozilla, this defaults to mozilla\.(com|org) and any skipped tests will give a suitable reason in your reports.

HTML report

Digging through console logs or JUnit reports can be a little frustrating when investigating failures, so the plugin provides a nicely formatted HTML report. This shows the options used when running the tests, a short summary of the results, and then lists each test along with timings and additional resources where appropriate.

I call the additional resources the test’s “death rattle” as it’s only captured for failing tests (it’s not particularly useful for passing tests, and consumes unnecessary resources). For tests that use Selenium this should at least include a screenshot, the HTML, and the current URL when the failure occurred. If you’re running in Sauce Labs then you should also see the video of the test and a link to the test job.

For full details and documentation of the plugin, take a look over the project’s README file on github. If you find any bugs or have any feature requests please raise them in github issues.

5 thoughts on “Announcing pytest-mozwebqa 1.0”

  1. Pingback: A Smattering of Selenium #96 « Official Selenium Blog

  2. Hello!
    This is a really usefull plugin.
    I wanted to try it on my own website and there is basic authentication and I got a problem with it.
    When I put basic auth credentials to baseurl in mozwebqa.cfg (baseurl = http://login:password@website.com/) it returns me an error: AssertionError: Base URL did not return status code 200. Response: 401
    And If I type http://login:password@website.com/ manually in browser address bar it works normally.
    Any advice would thankful.

    Thanks

    1. Hey Artem,

      Thanks for your comment! I thought I had fixed this issue but apparently not. Please raise a new issue here and I will get this resolved for the upcoming release.

      Dave.

  3. Hey Dave,
    I really like this nice-looking reports that your plugin generate.
    Will you convert this plugin to other languages?
    If not – are there any analogs for ruby language? Because I have no possibility to develop scripts in python.

    1. Hi George, thanks for commenting! I have no plans currently to port this plugin to other languages or frameworks. I suspect there are suitable frameworks in Ruby that would allow you to generate a custom report, and please feel free to reuse the report format. Good luck! 🙂

Leave a Reply to Dave Cancel reply

Your email address will not be published. Required fields are marked *