The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree
Skip to end of metadata
Go to start of metadata

Health Check

CircleCI

Table of Contents

Overview

The following repository: https://github.com/saucelabs-training/demo-python, allows you to quickly run simple automated tests in order to validate your Python test environment with your saucelabs.com account credentials. Below are the steps to configure your test environment and run a simple automated test.

For Demonstration Purposes Only!

Disclaimer

The code in these scripts 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. These scripts are provided for educational and demonstration purposes only, and should not be used in production. Issues regarding these scripts should be submitted through GitHub. These scripts are maintained by the Technical Services team at Sauce Labs.

Some examples in this repository, such as appium-examples and headless-examples, may require a different account tier beyond free trial. Please contact the Sauce Labs Sales Team for support and information.

Solution Outline

Prerequisites

Before attempting an automated test, ensure you've installed the following software:

 Click here to view the prerequisite software installation guide


Install Git

Git is a version control system that lets you check out code from a repository, work with that code on your own branch, and then merge that code with any changes that have been made by other developers. Git is an essential tool for distributed development teams, and is a critical component of the continuous integration/continuous development toolchain.

MacOSX:
  1. Go to https://git-scm.com/downloads.
  2. Under Downloads, click Mac OS X.
  3. When the download completes, double-click the .dmg file open the installer package.
  4. Double-click the installer package to begin the installation.

    Security Warning

    You may see a warning message that the package can't be opened because it's not from a recognized developer. If this happens, go to System Preferences > Security and Privacy Settings, and click Open Anyway.

  5. Click Continue for the installation, and enter your local password to authorize the installation.
Windows:
  1. Go to https://git-scm.com/downloads
  2. Under Downloads, click on Windows.
  3. When the dialog opens asking if you want to allow the app to make changes to your device, click Yes.
  4. Follow the steps in the setup wizard to complete the installation. You should accept all the default settings.

Install Python and PIP

MacOSX:
  1. Using brew install python:

    $ brew install python3
    

    Python 2.7 is included by default on recent versions of Mac OSs. If it somehow not included, install it by running brew install python

  2. (Optional) Install pip to manage packages. Modern versions of Python come with pip included. To verify if you have pip installed, run

    pip -V
    

    in your command prompt. You should see something like this:

    pip 18.1 from /path/of/python/installation
    

    If you get an error or "pip not found" message, you can install pip separately using the following commands:

    $ curl -O http://python-distribute.org/distribute_setup.py
    $ python distribute_setup.py
    $ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
    $ python get-pip.py
    
  3. Install virtualenv in order to manage projects that have different or conflicting dependencies--it also prevents you from accidentally installing global python dependencies.

    $ pip install virtualenv
    
Windows:
  1. Go to https://www.python.org/downloads/.
  2. Click the "Download Python <version>" button.
  3. Download the package and extract it on you system.
  4. Open the executable and follow the prompts to complete installation.

Install a Test Framework

A testing framework is a set of guidelines/rules for desiging test cases. Frameworks themselves consist of test and reporting classes that allow QA engineers to test efficiently. This repo only supports pytest and unittest.

For more information regarding other libraries, checkout our GitHub repo that catalogs all sample test frameworks.


Install Pytest
  1. Open a terminal (OSX) or command prompt (Windows)
  2. Navigate to the pytest directory:
    cd on-boarding-modules/pytest-examples/
    
  3. Resolve the package dependencies:
    sudo pip install -r requirements.txt 
    
  4. Run tests:
    pytest
    

Install UnitTest

unittest is an included test module in the Python standard library. Its API will be familiar to anyone who has used any of the JUnit/nUnit/CppUnit series of tools.

  1. Open a terminal (OSX) or command prompt (Windows)
  2. Navigate to the unittest-examples directory:
    cd on-boarding-modules/unittest-examples
    
  3. Resolve the package dependencies:
    sudo pip install -r requirements.txt 
    
  4. Run tests:
    python -m unittest
    

Install an IDE

It's recommended to install and Integrated Developer Environment, or a text editor, to help manage package dependencies, interperters, and overall code execution. There are several options available, some of them are free and some require payment:

  • PyCharm community edition is free, Professional version requires subscription.
  • Visual Studio Code free text editor from Microsoft with a wide variety of extensions.
  • Komodo Edit, free, text editor, stripped down version of Komodo IDE (paid version).

Setup a python interpreter:


Use a Pre-built Workspace

If you want to skip the prerequisite setup, you can try this demo in a cloud-based IDE hosted by gitopd.io

  1. After the session launches, navigate to the terminal and use the following commands to export your Sauce Labs credentials:

    eval $(gp env -e SAUCE_USERNAME=******)
    eval $(gp env -e SAUCE_ACCESS_KEY=******)


    Note: If you start a new session or terminal in gitpod you have to re-apply environment variables. For more information consult the 
    gitpod documentation.

    eval $(gp env -e)
  2. Install dependencies and run a python test:

    pip install -r requirements.txt && /
    python on-boarding-modules/python-examples/test_module2.py

Sauce Labs Test Setup


Run the Onboarding Scripts

If you would like to get started with using Python and Sauce Labs with some guidance, please look at the Onboarding scripts provided in the on-boarding-modules directory.


Run the Sauce Examples

In addition to onboarding, we have also included some samples of using Sauce Labs with some common Python test tools. In particular, we have examples using

  • Pytest
  • Robotframework

and these cover using

  • Sauce Labs Virtual Device Cloud (VDC), which includes desktop browsers and emulator/simulator devices (EMUSIM)
  • Sauce Labs Real Device Cloud (RDC).

These samples are executed using Pipenv for simplicity. You can find a list of available executions in the Pipfile for executing tests written in the test tools. These executions demonstrate how to run tests in parallel on the various Sauce Labs platforms.

The organization of these samples are as follows:

-- driver (appium or selenium) 
   |- test tooling
      |- test environment (virtual or real devices)
         |- additional resources needed (if any)
            |- sample test framework

For example, to run tests with pytest:

sudo pip install pipenv
pipenv install
pipenv run pytest-vdc-us