Welcome to Java Demo Scripts designed by Solution Architects to provide examples of how to use Sauce Labs technologies. This repository contains
Table of Contents
- Overview
- Solution Outline
- Most Popular
- 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.
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
-
Popular Examples
-
Real Devices
-
Emulators and Simulators
-
-
Automation Best Practices
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/
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-example
,parallel-testing
, andheadless
, may require a different account tier beyond free trial. Please contact the Sauce Labs Sales Team for support and information.
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
This repository will hold multiple Node.js based automation frameworks and examples which will help you run tests with 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 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. Please contact the Sauce Labs Sales Team for support and information.
Table of Contents
What You'll Need
In order to run these scripts you must complete the following prerequisite steps:
Use a Preconfigured Environment with Gitpod
Select the button below to try these scripts in Gitpod
After the gitpod session launches, navigate to the terminal and run the following commands to save your Sauce Labs Credentials to gitpod as environment variables:
eval $(gp env -e SAUCE_USERNAME=******) eval $(gp env -e SAUCE_ACCESS_KEY=******)
Click the following link if you're unsure how to access your Sauce Labs credentials.
Also, if you start a new terminal in gitpod, you have to run the following command to reset environment variables:
eval $(gp env -e)
For more information on how to use gitpod, please consult the documentation.
Run A Sample Test
1. Clone the Repository and set your Sauce Labs Credentials:
git clone https://github.com/saucelabs-training/demo-js.git export SAUCE_USERNAME=******** export SAUCE_ACCESS_KEY=*******
2. Please check all README.md files in each framework example to see what you need to do to get the tests running.
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:
-
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.