The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Sauce Labs is a cloud platform for executing automated and manual mobile and web tests. Sauce Labs supports running automated tests with Selenium WebDriver (for web applications) and Appium (for native and mobile web applications). This tutorial will show you how to get started with testing with Python on Sauce.  

Note
titleExample Only

The information in this topic is presented as an example only, since your tests and testing environments may require specialized scripting. This information should be taken only as an illustration of how you would set up Python tests with Sauce Labs, and is not directly supported by Sauce.

Table of Contents

Prerequisites

Before getting started, you should read the Best Practices for Running Tests with Sauce Labs.

  • You will need to install the Selenium WebDriver client driver to your local Python environment
    You can either download the driver from the link, or use pip to install it.

    Code Block
    pip install selenium
  • You should also install the Sauce Python client, which provides features for reporting job information to the Sauce Labs dashboard. 

    Code Block
    pip install sauceclient

Code Example

This simple Python test script tests the Google front page. Despite its simplicity, it contains everything you need to know in order to run an automated test on Sauce Labs.

...

Tip
titleWait!

The explicit wait method tells the browser to wait a set amount of time (in seconds) for elements to appear on the page before giving up. Using explicit waits is one of our recommended best practices.

Analyzing the Code

If you look at the code closely, you'll see that basics for setting up a test to run on sauce are very straightforward, and really only require two elements.

...

You can use the Platform Configurator to specify the desired capabilities for any browser/platform combination you want. 

Running the Test

  1. Copy the example code and save it into a file called first_test.py.
    Make sure your username and access key are included in the URL passed through to the command_executor.
  2. Open a command line terminal and navigate to the directory where the file is located.
  3. Execute the test:

    Code Block
    python first_test.py

    Check your dashboard and you will see that your test has just run on Sauce!

Running Local Tests

Developing apps on localhost is quick and efficient. The drawback is that localhost is not a publicly-accessible address on the Internet, so the browsers in the Sauce Labs cloud can't load and test your app. The solution is to use Sauce ConnectSauce Connect uses a secure tunnel protocol that gives specific Sauce machines access to your local network. You can also use it to test applications that are inside your corporate firewall. Sauce Connect is not required to run tests on Sauce Labs, only in situations where the application or website you want to test is on your local machine or behind a firewall. 

Running Tests in Parallel

Now that you’re running tests on Sauce, you may wonder how you can run your tests faster. One way to increase speed is by running tests in parallel across multiple virtual machines.

...

See the topics under Running Tests in Parallel with Python for more information and examples of setting up popular Python testing frameworks to run tests in parallel on Sauce 

Reporting on Test Results

"Wait," you might be asking, "My test says 'Complete' but what happens if it fails?"

...