isonic1 / Python-Pytest-with-Pytest-Selenium

A sample Python test framework using Sauce, Pytest and the pytest-selenium plugin for Pytest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python-Pytest-Using-pytest-selenium

This code shows an example of how to write tests using Pytest with the pytest-selenium plugin with Sauce Labs. The pytest-selenium plugin provides fixtures and functionality to start and stop a browser session in a clean, straightforward way, and has good support for both local browsers and cloud services like Sauce Labs.

As well, this sample works the same with Python 3.6 and Python 2.7.

This code is provided on an "AS-IS” basis without warranty of any kind, either express or implied, including without limitation any implied warranties of condition, uninterrupted use, merchantability, fitness for a particular purpose, or non-infringement. Your tests and testing environments may require you to modify this framework. Issues regarding this framework should be submitted through GitHub. For questions regarding Sauce Labs integration, please see the Sauce Labs documentation at https://wiki.saucelabs.com/. This framework is not maintained by Sauce Labs Support.

Environment Setup

  1. Global Dependencies

    $ brew install python
    
    • Install pip for package installation
  2. Sauce Credentials

    • In the terminal export your Sauce Labs Credentials as environmental variables:
    $ export SAUCE_USERNAME=<your Sauce Labs username>
    $ export SAUCE_ACCESS_KEY=<your Sauce Labs access key>
    
  3. Project

    • The recommended way to run your tests would be in virtualenv. It will isolate the build from other setups you may have running and ensure that the tests run with the specified versions of the modules specified in the requirements.txt file. $ pip install virtualenv
    • Create a virtual environment in your project folder the environment name is arbitrary. $ virtualenv venv
    • Activate the environment: $ source venv/bin/activate
    • Install the required packages: $ pip install -r requirements.txt

Running Tests:

  • Tests in Parallel: To run tests in parallel against a single browser, run one of:
      make chrome_case
      make firefox_case
      make safari_case
      make android_case
    
    and to run all tests in parallel, run
      make run_all_in_parallel
    

Sauce Labs Dashboard

Advice/Troubleshooting

There may be additional latency when using a remote webdriver to run tests on Sauce Labs. Timeouts or Waits may need to be increased. * Selenium tips regarding explicit waits

Resources

Sauce Labs Documentation
Selenium Documentation
Python 2.7 Documentation
Python 3.6 Documentation
Pytest Documentation
pytest-selenium Documentation
Stack Overflow
  • A great resource to search for issues not explicitly covered by documentation.

About

A sample Python test framework using Sauce, Pytest and the pytest-selenium plugin for Pytest


Languages

Language:Python 87.7%Language:Makefile 12.3%