This directory contains example scripts and dependencies for the Parallel Testing Workshop. Use these scripts to test your Sauce Labs authentication credentials, setup your automated testing environment, try out Sauce Labs features, and complete the in-class Selenium examples. Download the zip file or clone the entire directory to your local environment.
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.
These procedures will show you to set up a Selenium environment for Java. The scripts in this repository allow you run a simple automated test to validate your Selenium environment and your saucelabs.com account credentials.
In order to participate in the hands-on portion of the workshop you must complete the following prerequisite installation and configuration steps:
- Install Git
- Install IntelliJ (or another IDE)
- Install JDK
- Install Maven
Project Setup consists of the following steps:
WARNING! In order to run the scripts and participate in this workshop you must have a valid Sauce Labs account with the relevant amount of VM concurrency.
For this workshop, we will run between 1 and 40 threads simultaneously, and while we understand that a free account won't give you enough concurrency to run these directly, the instructor will adequately demonstrate the the system behavior. As long as you can execute even a single test against the Sauce Labs platform with this code, you can have confidence that the code will scale to as many threads as you care to execute.
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.
- Go to https://git-scm.com/downloads.
- Under Downloads, click Mac OS X.
- When the download completes, double-click the
.dmg
file open the installer package. - 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.
- Click Continue for the installation, and enter your local password to authorize the installation.
- Go to https://git-scm.com/downloads
- Under Downloads, click on Windows.
- When the dialog opens asking if you want to allow the app to make changes to your device, click Yes.
- Follow the steps in the setup wizard to complete the installation. You should accept all the default settings.
IntelliJ is an integrated development environment that incorporates several tools for developing and running Java code. You will be using IntelliJ to write and edit the sample Selenium scripts used in the exercises. For these exercises you only need to download the free Community edition.
- Go to https://www.jetbrains.com/idea/
- Click Download.
- On the Downloads page, select macOS.
- Under Community, click Download.
- When the download completes, double-click the .dmg file open the installer package.
- Double-click the installer package to begin the installation.
- Drag and drop the IntelliJ icon into the Applications folder.
- Go to https://www.jetbrains.com/idea/
- Click Download.
- On the Downloads page, select Windows.
- Under Community, click Download.
- When the download completes, double-click the
.exe
file to launch the installation wizard. You should accept all the default settings.
The Java SE Developer Kit lets you develop and deploy Java applications on desktops and servers. It is needed to compile our test code.
This project requires JDK version 1.8 at the least.
- Go to the JDK downloads page, locate the latest release, select the download button.
- Under Java SE Development Kit {version}, select the Accept License Agreement radio button.
- Click the download link for Mac OS.
- When the download completes, double-click the
.dmg
file open the installer package. Double-click the installer package to begin the installation.
- Go to the JDK downloads page, locate the latest release, select the download button.
- Under Java SE Development Kit {version}, select the Accept License Agreement radio button.
- Click the download link for Windows x64.
- When the download completes, double-click the
.exe
file open the installer package. - Double-click the installer package to begin the installation. You should accept all the default settings.
Maven is a build automation and project management tool use for managing project builds, dependencies, and documentation. It uses a project object model (pom.xml) to manage Java-based projects. With our use case, it's very useful for configuring and managing test suites.
-
Go to Maven Apache website and download the following package:
apache-maven-<version>-bin.tar.gz
-
Extract the archive
$ tar -xvf apache-maven-<version>-bin.zip
-
Add the
bin
directory of the extracted directory (apache-maven-<version>
) to thePATH
variable:$ export M2=$M2_HOME/bin $ export PATH=$M2:$JAVA_HOME/bin:$PATH
WARNING!: Make sure you've set
JAVA_HOME
othewisemvn
commands won't run. For instructions on how to setJAVA_HOME
, visit this link -
Check to see if maven installed correctly:
$ mvn -version
- Go to Maven Apache website and download the following package:
apache-maven-<version>-bin.zip
- Unpack the archive using an archive tool (for example WinZip)
- Add the unpacked distribution’s
bin
directory to your userPATH
environment variable by:- Open up the system properties (WinKey + Pause)
- Select the Advanced tab, and the Environment Variables button
- Add/Select the
PATH
variable in the user variables with the value:C:\Program Files\apache-maven-3.6.0\bin
- Open a new command prompt (Winkey + R then type cmd) and run
mvn -v
to verify the installation.
- Create a directory on your machine.
- Clone this repository into said directory.
$ git clone https://github.com/saucelabs-training/saucecon19-parallel-workshop.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 saucedemo-parallel directory as the root directory of the project.
-
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:
$ export SAUCE_USERNAME="username" $ export SAUCE_ACCESS_KEY="accessKey"
> set SAUCE_USERNAME="username" > set SAUCE_ACCESS_KEY="accesKey"
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
$ echo $SAUCE_USERNAME $ echo $SAUCE_ACCESS_KEY
> echo %SAUCE_USERNAME% > echo %SAUCE_ACCESS_KEY%
WARNING FOR UNIX USERS!: If you have problems setting your environment variables, try the following options:
Run the following commands in your terminal:
$ launchctl setenv SAUCE_USERNAME $SAUCE_USERNAME $ launchctl setenv SAUCE_ACCESS_KEY $SAUCE_ACCESS_KEY
Refresh your bash session by running the following command:
$ source ~/.bashrc
Update
.bash_profile
to globally set environment variables. For example your file may look something like this:export JAVA_HOME=$(/usr/libexec/java_home) export PATH="$PATH:/usr/local/bin" export PATH=$M2:$JAVA_HOME/bin:$PATH export M2_HOME=/usr/local/apache-maven-<version> export M2=$M2_HOME/bin export SAUCE_USERNAME="xxx" export SAUCE_ACCESS_KEY="XXXXXXX-XXXX-XXXX-XXXXXXXXXXX"
- 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:
$ mvn test -Dtest=LoginTest