Table of Contents
- Overview
- Solution Outline
- Solution Outline
- Prerequisites
- Sauce Labs Test Setup
- Prerequisites
- Project Setup
Overview
The following repository: https://github.com/saucelabs-training/demo-java, allows you to quickly run simple automated tests in order to validate your Java 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!
The demo scripts in this repository allow you to run simple automated tests in order to validate your Java Selenium environment and your saucelabs.com account credentials.
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.
Solution Outline
The repository has several demonstration scripts that fit various use cases, such as:
If you just wish to get up and running quickly with Sauce Labs, please follow the instructions below.
Prerequisites
In order to run this demo on your local machine, you must download, install, and configure the prerequisite software.
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
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)
Run a Maven test:
mvn test -Dtest=Module2TestNGTest -pl on-boarding-modules/testng
Sauce Labs Test Setup
Real Devices
- iOS real device, native app, Junit4, Unified Platform
- iOS real device, native app, Junit4, Cucumber
- Set test status on mobile, Junit4
Emulators and Simulators
Visual E2E automation
Prerequisites
- Install Git
- Install IntelliJ (or another IDE)
- Install JDK
- Install Maven
Select the button below to try this demo in Gitpod
Click here to see how to setup your Sauce Labs credentials in Gitpod
Project Setup
Import the Project
- Create a directory on your machine.
- Clone this repository into said directory.
$ git clone https://github.com/saucelabs-training/demo-java.git
- Import the project into your IntelliJ (or IDE of your choice) as a Maven Project.
- Click through the prompts, and confirm when it asks to Import from Sources
- Choose the demo-java directory as the root directory of the project.
Set Your Sauce Labs Credentials
-
Copy your Sauce Labs username and accessKey in the User Settings section of the Sauce Labs Dashboard.
-
Open a Terminal window (command prompt for Windows) and set your Sauce Labs Environment variables:
Mac OSX:
$ export SAUCE_USERNAME="username" $ export SAUCE_ACCESS_KEY="accessKey"
Windows:
> set SAUCE_USERNAME="username" > set SAUCE_ACCESS_KEY="accessKey"
To set an environment variables permanently in Windows, you must append it to the
PATH
variable.Go to Control Panel > System > Windows version > Advanced System Settings > Environment Variables > System Variables > Edit > New
Then set the "Name" and "Value" for each variable
-
Test the environment variables
Mac OSX:
$ echo $SAUCE_USERNAME $ echo $SAUCE_ACCESS_KEY
***WARNING FOR UNIX USERS!***: If you have problems setting your environment variables, run the following commands in your terminal:
$ launchctl setenv SAUCE_USERNAME $SAUCE_USERNAME $ launchctl setenv SAUCE_ACCESS_KEY $SAUCE_ACCESS_KEY
Windows:
> echo %SAUCE_USERNAME% > echo %SAUCE_ACCESS_KEY%
Run a Maven Test
-
Run the following command to update any package dependencies:
$ mvn dependency:resolve
-
Then run the following command to compile your test code:
$ mvn test-compile
-
Finally, run the following test to see if you've properly configured the test environment:
$ mvn test -Dtest=Module2TestNGTest -pl on-boarding-modules/testng
If you wish to run a specific test/sub-module in this emusim_testng use the following command:
# for running a specific test: mvn test -Dtest=testname # for running a specific sub-module mvn test -pl subproject/
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
andheadless-examples
, may require a different account tier beyond free trial. Please contact the Sauce Labs Sales Team for support and information.
Solution Outline
- Tests that can help you quickly and easily get started with Sauce Labs
- Tests that use the Headless feature of Sauce Labs (not included with basic tier or free trial customers)
- Web Examples using Selenium on Sauce Labs
- Mobile Examples using Appium on Sauce Labs
Prerequisites
Before attempting an automated test, ensure you've installed the following software:
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
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)
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
Table of Contents
Overview
The following repository: https://github.com/saucelabs-training/demo-ruby, allows you to quickly run simple automated tests in order to validate your Ruby 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
andheadless-examples
, may require a different account tier beyond free trial. Please contact the Sauce Labs Sales Team for support and information.
Solution Outline
In order to complete these exercises you must complete the following prerequisite installation and configuration steps:
Prerequisites
Before attempting an automated test, ensure you've installed the following software:
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
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)
Install dependencies and run a ruby test:
gem install bundler && / bundle install --path .bundle && / bundle exec rspec
Sauce Labs Test Setup
-
Execute the
bundle
Command:-
Use the following to install the required
gems
:$ bundle install --path .bundle
-
-
Run the Test Scripts
-
In order to run the tests on www.saucelabs.com, you need to export your Sauce Labs account credentials as environment variables, or hard code (not recommended) the values of
SAUCE_USERNAME
andSAUCE_ACCESS_KEY
in each script. For example:https://SAUCE_USERNAME:SAUCE_ACCESS_KEY@ondemand.saucelabs.com:443/wd/hub'
-
Run the following command to have
rspec
search and execute 'specs' in your project directories:$ bundle exec rspec
-
You may also use 'Run Configurations' in your IDE. For directions on how to setup Run/Debug Configurations refer to Documentation:
-
- Overview
- What You'll Need
- Sauce Labs Test Setup
- Framework Examples
- Framework examples
Overview
The following repository: https://github.com/saucelabs-training/demo-js, allows you to quickly run simple automated tests in order to validate your NodeJS 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!
Node.js based automation frameworks locally and or in Sauce Labs.
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
What You'll Need
In order to run this demo on your local machine, you must download, install, and configure the prerequisite software.
Sauce Labs Test Setup
This example script follows the best practice of using environment variables in place of hardcoded authentication credentials. Once you've been able to successfully run the instant test with hardcoded credentials, you can use this test to make sure that you've correctly set up your environment variables for authentication.
Framework Examples
Issues regarding these scripts should be submitted through GitHub. These scripts are maintained by the Technical Services team at Sauce Labs.
Please contact the Sauce Labs Sales Team for support and information.
Most of the Sauce Labs features will be explained with WebdriverIO, the preferred Node.js framework when using Sauce Labs.
Framework examples
- WebdriverIO with Jasmine*
- WebdriverIO with Appium for Native/Hybrid Apps
- WebdriverIO with Appium for Mobile Web (Chrome/Safari)
- WebdriverIO for Desktop Web (Selenium, but officially WebDriver)
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
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)
- Navigate to the desired directory and review the README.md file for instructions on how to get each test running.
Table of Contents
What You'll Need
- Install Visual Studio Community Edition
- Create a Basic Project File
- Your Sauce Labs Account Credentials
Test Project Setup
In this step, you add the NuGet packages you need to run your automated web tests on Sauce Labs.
In the Solution Explorer panel to the right of the Visual Studio frame, right-click References.
Select Manage NuGet Packages.
The NuGet window opens.In the Search field, enter Selenium Support.
A list of Selenium packages appears.Select Selenium Support, then click Install.
When the Preview Changes dialog box opens, click OK.
The package is installed.Search for Selenium.WebDriver.ChromeDriver. Follow the same steps to install it.
Search for NUnit and install it.
Search for NUnit 3 Test Adapter and install it.
Search for DotNetSeleniumExtras.WaitHelpers and install it.
If you want to check that all the packages are installed, in Solution Explorer, click packages.config.
An XML page appears that shows all the installed packages.Close the NuGet window.
Adding the Test Script
In this step, you download and run a C# test script from Sauce Labs. The script opens up the Sauce Labs sample web application (a simulated online store) and simulates a login with a sample user.
Download/copy the following test script from Instant Sauce Test:
Delete the text in the VS file you created and paste in the script you downloaded.
Scroll down the script until you see
sauceUsername
and update the test script with your Sauce Labs Credentials like so:var sauceUserName = "********"; var sauceAccessKey = "************";
Best Practices - Use Environment Variables
You can hardcode the values like this example below, but the best practice is to use environment variables like in this script:
var sauceUserName = Environment.GetEnvironmentVariable("SAUCE_USERNAME", EnvironmentVariableTarget.User); var sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY", EnvironmentVariableTarget.User);
- Save the File.
Running the Test Script
You’re now ready to run your test on Sauce Labs!
In VS, click Test, point to Windows and click Test Explorer.
In the Test Explorer panel, select your test and click Run All.
You'll see that the test starts running.Log in to the Sauce Labs web interface and click Automated Tests.
You'll see that the test ShouldOpenOnSafari is running.
To see the details of the test when it completes, click ShouldOpenOnSafari.
You'll see that Test Success is selected.
Click the Play button.
You'll see a video of the entire test run. The test opens up the Sauce Labs sample application. It then logs in to the application and clicks the LogIn button.Go back to VS.
In the Test Explorer pane, you'll see a green check mark next to your test, which means the test completed successfully. You can also click the Output tab to see some details.
More Examples
Below are more common use case and Sauce Labs-specific examples:
- Parallel, cross-browser, NUnit, Selenium
- Real Devices, Native App, Appium 4,
- Frontend Performance Testing
- Visual End to End Testing, NUnit
Example Only
The code 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 could set up your tests with Sauce Labs, and is not directly supported by Sauce.
Prerequisites
You need to have these components installed to set up testing on Sauce with PHP:
- You must have PHP set up on your system before you start testing.
Mac OS X comes with PHP installed, as long as you're running version 5.3 or higher, you're ready to go! If you're a Windows user, you can find instructions for setting up PHP on Windows at PHP.net. - Windows users must also enable the PHP curl library and OpenSSL support to get the best performance from your PHP setup.
For more information, see Installing Extensions for Windows on the php.net website as well as these setup topics: - If you want to set up your tests to use a PHP framework, you can check out our repository of testing framework examples in our GitHub repo.
Quick Start
You can set up any PHP test you've already written to run on Sauce, regardless of the testing framework it uses. All you need to do is change the test from running locally, to running on the Sauce cloud by defining the sauce URL, your authentication credentials, and a set of desired capabilities for the test.
This example shows how you could edit the existing test to run on Sauce. You can use the Platform Configurator to specify the desired capabilities for any browser/platform combination you want.
You can also clone this script directly from our GitHub repo.
<?php // Setup: $ php composer.phar require facebook/webdriver require_once('vendor/autoload.php'); use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\WebDriverBy; $web_driver = RemoteWebDriver::create( "https://YOUR_SAUCE_USERNAME:YOUR_SAUCE_ACCESS_KEY@ondemand.saucelabs.com:443/wd/hub", array("platform"=>"Windows 7", "browserName"=>"chrome", "version"=>"40") ); $web_driver->get("https://saucelabs.com/test/guinea-pig"); /* Test actions here... */ $web_driver->quit(); ?>
Running Local Tests
Running Tests in Parallel
You can run your tests in parallel at two levels, and you can run your tests in parallel across multiple browsers. For example, if you have 10 tests and want to run on five browsers, this would be parallelism of five. You can also run tests across browsers and each test in parallel. Using our previous example this would be more like 50 parallel tests. Doing this requires that your tests are written in a way that they do not collide with one another, as described in our Best Practice topics avoiding external test dependencies and avoiding dependencies between tests.
Check out Using Frameworks to Run Tests in Parallel for more information, and examples of framework setups for Java, Python, and other programming languages.
For more information, check out the example scripts in our GitHub repo.
Reporting Test Results
By default, Sauce Labs doesn't know how to display the name of your test. Sausage comes up with a good name (TestClass::testFunction
) and reports it with your test so it's easy to find on your dashboard. Similarly, Sauce has no way to know if a particular test passed or failed. Sausage catches any failed assertions and reports the status of the test to Sauce after it's complete. Upon test failure Sausage will generate an authorized link to the failed job report on the Sauce Labs website, to facilitate reporting to people who need to know the details of the test. The job remains private (unless you change the status yourself), but others can follow the link without needing to log in with your credentials. See the topic Building Sharable Links to Test Results for more information.
You should also follow our recommended best practice of adding build numbers, tags, and other identifying information to your tests so you can easily find and manage them in your test results and archives pages, and associate tests with build numbers in your continuous integration pipeline.
Got questions?
As these scripts are not maintained by Sauce support, the best way to get help help – and help us improve – is to submit an issue on GitHub.