Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Mozilla WebQA plugin for py.test.
Pull request Compare This branch is 141 commits behind mozilla:master.


pytest_mozwebqa is a plugin for py.test that provides additional features needed for Mozilla's WebQA projects.


  • py.test
  • selenium
  • pyyaml
  • requests


$ python install

Running tests with pytest_mozwebqa

For full usage details run the following command:

$ py.test --help

   --webqareport=path  create mozilla webqa custom report file at given path. default is 'results/index.html'

  --baseurl=url        base url for the application under test.
  --api=api            version of selenium api to use. 'rc' uses selenium rc.
                       'webdriver' uses selenium webdriver (the default).
  --host=str           host that selenium server is listening on.
  --port=num           port that selenium server is listening on.
  --driver=str         webdriver implementation.
  --chromepath=path    path to the google chrome driver executable.
  --chromeopts=str     json string of google chrome options to set (webdriver).
  --firefoxpath=path   path to the target firefox binary.
  --firefoxpref=str    json string of firefox preferences to set (webdriver).
  --browser=str        target browser (standalone rc server).
  --environment=str    target environment (grid rc).
  --browsername=str    target browser name (webdriver).
  --browserver=str     target browser version (webdriver).
  --platform=str       target platform (webdriver).
  --timeout=num        timeout (in seconds) for page loads, etc.
  --capturenetwork     capture network traffic to test_method_name.json
                       (selenium rc). (disabled by default).

  --sensitiveurl=str   regular expression for identifying sensitive urls.
  --destructive        include destructive tests (tests not explicitly marked
                       as 'nondestructive'). (disabled by default).

  --credentials=path  location of yaml file containing user credentials.
  --saucelabs=path    credendials file containing sauce labs username and api key.


You can also create a mozwebqa.cfg file that will be used to set defaults. This is so that projects can keep this alongside the tests to simplify running them via the command line. The options are currently limited to those that could be project specific.

baseurl: ''
api: 'rc'
tags: 'tag1, tag2'

The tags entry is an optional comma separated list of tags that are set when using Sauce Labs. This is useful for filtering the list of jobs based on the application under test or similar.


Run tests against a standalone RC server using Firefox in the default location:

$ py.test --baseurl= --api=rc --browser="*firefox"

Run tests against a grid server with an RC node environment named 'Firefox 5 on Mac OS X':

$ py.test --baseurl= --api=rc --environment="Firefox 5 on Mac OS X"

Run tests against a local webdriver using Firefox:

$ py.test --baseurl= --driver=firefox --firefoxpath=/Applications/

Run tests against a local webdriver using Google Chrome:

$ py.test --baseurl= --driver=chrome --chromepath=/Applications/chromedriver

Run tests against a remote webdriver server either directly or via grid:

$ py.test --baseurl= --browsername=firefox --browserver=5 --platform=mac

Run tests against Sauce Labs using RC API using Firefox 5 on Windows 2003:

$ py.test --baseurl= --api=rc --browsername=firefox --browserver=5.0 --platform="Windows 2003" --saucelabs=sauce_labs.yaml

Run tests against Sauce Labs using webdriver API using Firefox 5 on Windows:

$ py.test --baseurl= --browsername=firefox --browserver=5.0 --platform=WINDOWS --saucelabs=sauce_labs.yaml

Writing tests for pytest_mozwebqa

You will need to include the mozwebqa in the method signature for your tests, and pass it when constructing page objects.


def test_new_user_can_register(self, mozwebqa):
    home_pg = home_page.HomePage(mozwebqa)

    registration_pg = registration_page.RegistrationPage(mozwebqa)
    Assert.equal(registration_pg.page_title, "Sign Up Complete!")

Destructive tests

In order to prevent accidentally running destructive tests, only tests marked as nondestructive will run by default. If you want to mark a test as nondestructive then add the appropriate marker as shown below:

Example (mark test as nondestructive)

import pytest
def test_safely(self, mozwebqa):

If you want to run destructive tests then you can specify the --destructive command line option.

Sensitive environments

If running against a sensitive (production) environment any destructive tests will be skipped with an appropriate error message. You can specify a regular expression that matches your sensitive environments using the --sensitiveurl command line option.

Setting Firefox preferences

If you're using WebDriver and Firefox it's possible to set custom preferences. These are specified using a JSON string:

Example (disable addon compatibility checking)


Setting Google Chrome options

If you're using WebDriver and Google Chrome then you can set various options on the command line using a JSON string.

Valid keys are:

  • arguments: a list of command-line arguments to use when starting Google Chrome.
  • binary_location: path to the Google Chrome executable to use.
  • extensions: a list of Google Chrome extensions to install on startup.

For more details on Google Chrome options see:

Example (set initial homepage)


Using credentials files

The credentials files use YAML syntax, and the usage will vary depending on the project. A typical file will contain at least one user with a unique identifier and login credentials:


# admin:
#   email:
#   username: admin
#   password: password

Custom report

By default a custom HTML report will be written to results/index.html. If you wish this to be located elsewhere, or have a different filename, you can specify the --webqareport command line option.


By default log files are not captured as these may contain confidential data such as user credentials. If you are confident that a test does not contain such data, you can explicitly set the test as public:


import pytest

def test_public(self, mozwebqa):
    home_pg = home_page.HomePage(mozwebqa)

You can also explicitly mark the test as private, which sets the test appopriately in Sauce Labs jobs.


import pytest

def test_private(self, mozwebqa):
    home_pg = home_page.HomePage(mozwebqa)
Something went wrong with that request. Please try again.