public class SauceLabsWebDriverHelper extends Object implements com.saucelabs.common.SauceOnDemandSessionIdProvider
Helper class for RemoteWebDriver
when writing Selenium tests making use of Saucelabs
or Sauce OnDemand.
Saucelabs properties need to be set as JVM arguments. See the SAUCE_ Constants defined below. Required saucelabs
parameters are: REMOTE_DRIVER_SAUCELABS_PROPERTY
(master use saucelabs flag), SAUCE_USER_PROPERTY
,
SAUCE_KEY_PROPERTY
, SAUCE_VERSION_PROPERTY
.
An example:
-Dremote.public.url=env14.rice.kuali.org -Dremote.driver.saucelabs -Dsaucelabs.user=YOUR-SAUCELABS-USER
-Dsaucelabs.key=YOUR-SAUCELABS-KEY -Dsaucelabs.browser.version=22 -Dsaucelabs.platform=linux -Dsaucelabs.browser=ff
-Dremote.public.user=admin -Drice.version=42222
To make use of SauceLabsWebDriverHelper, call its setUp(java.lang.String, java.lang.String)
with the Test Class and Test Name and retrieve the configured
WebDriver using getDriver()
You'll also need to call getSessionId()
which you'll pass into the tearDown(boolean, java.lang.String, java.lang.String, java.lang.String)
(along with the tests passed state).
In your test setUp:
SauceLabsWebDriverHelper saucelabs = new SauceLabsWebDriverHelper();
saucelabs.setUp(className, testName);
driver = saucelabs.getDriver();
In your test tearDown:
SauceLabsWebDriverHelper.tearDown(passed, sessionId);
Also includes the Sauce JUnit helper classes, which will use the Sauce REST API to mark the Sauce Job as passed/failed.
In order to use SauceOnDemandTestWatcher
the SauceOnDemandSessionIdProvider
interface is implemented.
Modifier and Type | Field and Description |
---|---|
com.saucelabs.common.SauceOnDemandAuthentication |
authentication
Constructs a
SauceOnDemandAuthentication instance using the supplied user name/access key. |
static String |
REMOTE_DRIVER_SAUCELABS_PROPERTY
Use Saucelabs flag, required.
|
static String |
SAUCE_BROWSER_PROPERTY
Saucelabs browser, default is Firefox.
|
static String |
SAUCE_BUILD_PROPERTY
Suacelabs build displayed as saucelabs build, default is unknown.
|
static String |
SAUCE_DOWNLOAD_SCRIPT_PROPERTY
Create a unix shell script to download saucelab resources, default is false.
|
static String |
SAUCE_IDLE_TIMEOUT_SECONDS_PROPERTY
Saucelabs idle timeout in seconds, default is 180.
|
static String |
SAUCE_IE_INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS_PROPERTY
Saucelabs ignore security domains in IE, which can introduce flakiness, default is true.
|
static String |
SAUCE_KEY_PROPERTY
Saucelabs key, required.
|
static String |
SAUCE_MAX_DURATION_SECONDS_PROPERTY
Saucelabs max duration in seconds, default is 480.
|
static String |
SAUCE_PLATFORM_PROPERTY
Saucelabs platform (OS) replace spaces with underscores, default is Linux.
|
static String |
SAUCE_POPUP_PROPERTY
Saucelabs popup disable setting, default is false (not disabled).
|
static String |
SAUCE_REST_API_DELAY_MS
Saucelabs REST API delay in milliseconds, default is 5000.
|
static String |
SAUCE_SHARE_PROPERTY
Saucelabs share setting, default is public restricted.
|
static String |
SAUCE_USER_PROPERTY
Saucelabs user, required.
|
static String |
SAUCE_VERSION_PROPERTY
Saucelabs browser Version, required.
|
Constructor and Description |
---|
SauceLabsWebDriverHelper() |
Modifier and Type | Method and Description |
---|---|
org.openqa.selenium.WebDriver |
getDriver()
Returns the (RemoteWebDriver) driver.
|
String |
getSessionId() |
void |
setUp(String className,
String testName)
Saucelabs setUp.
|
void |
tearDown(boolean passed,
String sessionId,
String className,
String testName)
Saucelabs tearDown, flag the tests as passed or failed.
|
public static final String REMOTE_DRIVER_SAUCELABS_PROPERTY
Use Saucelabs flag, required.
For ease of disabling saucelabs without having to remove other saucelabs property settings, if not present saucelabs will not be used.
-Dremote.driver.saucelabs
public static final String SAUCE_BROWSER_PROPERTY
Saucelabs browser, default is Firefox.
-Dsaucelabs.browser=
public static final String SAUCE_BUILD_PROPERTY
Suacelabs build displayed as saucelabs build, default is unknown.
-Drice.version=
public static final String SAUCE_DOWNLOAD_SCRIPT_PROPERTY
Create a unix shell script to download saucelab resources, default is false.
Note - saucelabs history only goes back so far, if you run enough tests the resources will no longer be available for downloading.
-Dsaucelabs.download.script=false
public static final String SAUCE_IDLE_TIMEOUT_SECONDS_PROPERTY
Saucelabs idle timeout in seconds, default is 180.
-Dsaucelabs.idle.timeout.seconds=
public static final String SAUCE_KEY_PROPERTY
Saucelabs key, required.
-Dsaucelabs.key=
public static final String SAUCE_MAX_DURATION_SECONDS_PROPERTY
Saucelabs max duration in seconds, default is 480.
-Dsaucelabs.max.duration.seconds=
public static final String SAUCE_PLATFORM_PROPERTY
Saucelabs platform (OS) replace spaces with underscores, default is Linux.
-Dsaucelabs.platform=
public static final String SAUCE_IE_INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS_PROPERTY
Saucelabs ignore security domains in IE, which can introduce flakiness, default is true.
See InternetExplorerDriver FAQ
-Dsaucelabs.ie.ignore.domains=false
public static final String SAUCE_POPUP_PROPERTY
Saucelabs popup disable setting, default is false (not disabled).
-Dsaucelabs.pop.disable=
public static final String SAUCE_SHARE_PROPERTY
Saucelabs share setting, default is public restricted.
See Job Sharing. Valid values are: public, public restricted, team, share, and private.
-Dsaucelabs.share=
public static final String SAUCE_USER_PROPERTY
Saucelabs user, required.
-Dsaucelabs.user=
public static final String SAUCE_VERSION_PROPERTY
Saucelabs browser Version, required.
See Saucelabs Resources 0 or null is current version of Chrome. If using a browser other than Chrome this must be set else an Exception will be thrown.
-Dsaucelabs.version=
public static final String SAUCE_REST_API_DELAY_MS
Saucelabs REST API delay in milliseconds, default is 5000.
-Dsaucelabs.rest.api.delay.ms=
public com.saucelabs.common.SauceOnDemandAuthentication authentication
Constructs a SauceOnDemandAuthentication
instance using the supplied user name/access key.
To use the authentication supplied by environment variables or from an external file, use the no-arg
SauceOnDemandAuthentication
constructor.
public SauceLabsWebDriverHelper()
public void setUp(String className, String testName) throws Exception
Saucelabs setUp.
Creates a RemoteWebDriver
instance with the DesiredCapabilities as configured
using the JVM arguments described as SAUCE_ Constants in this class. After setUp the WebDriver can be accessed via
getDriver()
. You'll also need getSessionId()
for when you call tearDown(boolean, java.lang.String, java.lang.String, java.lang.String)
className
- class name of the test being setup as a StringtestName
- test name of the test being setup as a StringException
public void tearDown(boolean passed, String sessionId, String className, String testName) throws Exception
Saucelabs tearDown, flag the tests as passed or failed.
Uses the SauceREST API to register a test as passed or failed. SAUCE_REST_API_DELAY_MS
passed
- true if passed, falsed if failed, as a booleansessionId
- saucelabs test session id, as a StringException
public org.openqa.selenium.WebDriver getDriver()
Returns the (RemoteWebDriver) driver.
public String getSessionId()
getSessionId
in interface com.saucelabs.common.SauceOnDemandSessionIdProvider
Copyright © 2005–2014 The Kuali Foundation. All rights reserved.