public final class SauceLabs extends Object
SauceBrowserDriver
.
The getAll()
and getLatest()
methods return an array of usable capabilities.
Recommend using jUnit or testNG to run multiple capabilities in parallel or in sequence as a test
suite. For example:
import java.util.Arrays;
import java.util.Collection;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import edu.uci.qa.browserdriver.BrowserDriver;
import edu.uci.qa.browserdriver.sauce.*;
import edu.uci.qa.browserdriver.testing.*;
@RunWith(Parameterized.class)
public class SauceLabsTest implements BrowserProvider {
@Rule
public SauceTestWatcher resultReportingTestWatcher = new SauceTestWatcher(this);
private SauceCapabilities capabilities;
private BrowserDriver driver;
public SauceLabsTest(SauceCapabilities capabilities) {
this.capabilities = capabilities;
}
@Parameterized.Parameters
public static Collection <SauceCapabilities > browserCapabilities() {
return SauceLabs.getLatest();
}
@Before
public void createBrowser() {
this.capabilities.name(this.capabilities.toString());
this.capabilities.build("example");
driver = BrowserDriver.createBrowser(capabilities);
}
@After
public void quitBrowser() {
driver.quit();
}
@Test
public void testGoogleSearch() {
driver.get("http://www.google.com");
driver.sendKeys(By.xpath("//*[ @name='q']"), "webdriver").submit();
driver.waitUntil(ExpectedConditions.presenceOfElementLocated(
By.xpath("//*[ @id='rso' or @id='resultStats']")));
Assert.assertEquals("webdriver - Google Search", driver.getTitle());
}
@Override
public BrowserDriver getBrowser() {
return driver;
}
}
Note that SauceLabs relies on an username and accessKey to authenticate and determine what
account to instantiate and run tests. In order for this class to work, ensure you have the
username and accessKey specified either in a .sauce-ondemand
file in your user
folder, or the SAUCE_USERNAME
and SAUCE_ACCESS_KEY
environment
variables set. See also the SauceOnDemandAuthentication.java
file from saucelabs for
more information about their authentication.
Modifier and Type | Class and Description |
---|---|
static class |
SauceLabs.Orientation |
Modifier and Type | Field and Description |
---|---|
static edu.uci.qa.browserdriver.sauce.SauceLabs.Query |
query |
Constructor and Description |
---|
SauceLabs() |
Modifier and Type | Method and Description |
---|---|
static URL |
createUrl() |
static SauceCapabilities |
get(Browser browser)
Gets the
SauceCapabilities for the specified browser. |
static SauceCapabilities |
get(Browser browser,
Platform platform)
Gets the
SauceCapabilities for the specified browser and platform at the latest browser
version. |
static SauceCapabilities |
get(Browser browser,
Platform platform,
String version)
Gets the
SauceCapabilities for the specified browser, platform, and version. |
static SauceCapabilities |
get(Browser browser,
String version)
Gets the
SauceCapabilities for the specified browser and browser version. |
static SauceCapabilities |
get(Device device)
Gets the
SauceCapabilities for the specified device. |
static SauceCapabilities |
get(Device device,
SauceLabs.Orientation orientation)
Gets the
SauceCapabilities for the specified device and orientation at the latest
version. |
static SauceCapabilities |
get(Device device,
SauceLabs.Orientation orientation,
String version)
Gets the
SauceCapabilities for the specified device, orientation, and version. |
static SauceCapabilities |
get(Device device,
String version)
Gets the
SauceCapabilities for the specified device and device version. |
static Collection<SauceCapabilities> |
getAll()
Gets the array of every possible browser/device combination to run on SauceLabs.
|
static Collection<SauceCapabilities> |
getAll(Browser... browsers)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(Browser browser,
Platform... platforms)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(Browser browser,
String... versions)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(Device... devices)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(Device device,
SauceLabs.Orientation... orientations)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(Device device,
String... versions)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(Object o)
Gets an array of all
SauceCapabilities that contain the specified parameter. |
static Collection<SauceCapabilities> |
getAll(Platform... platforms)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(Platform platform,
Browser... browsers)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(Platform platform,
String... versions)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(SauceLabs.Orientation... orientations)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(SauceLabs.Orientation orientation,
Device... devices)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(SauceLabs.Orientation orientation,
String... versions)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(String... versions)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(String version,
Browser... browsers)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(String version,
Device... devices)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(String version,
Platform... platforms)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(String version,
SauceLabs.Orientation... orientations)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(String version,
Usable... browsers)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getAll(Usable... browsers)
Gets an array of all
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getLatest()
Gets the array of the latest versions of every possible browser/device and platform combination
to run on SauceLabs.
|
static Collection<SauceCapabilities> |
getLatest(Browser... browsers)
Gets an array of the latest
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getLatest(Browser browser,
Platform... platforms)
Gets an array of the latest
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getLatest(Device... devices)
Gets an array of the latest
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getLatest(Device device,
SauceLabs.Orientation... orientations)
Gets an array of the latest
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getLatest(Object o)
Gets an array of the latest
SauceCapabilities that contain the specified parameter. |
static Collection<SauceCapabilities> |
getLatest(Platform... platforms)
Gets an array of the latest
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getLatest(Platform platform,
Browser... browsers)
Gets an array of the latest
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getLatest(SauceLabs.Orientation... orientations)
Gets an array of the latest
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getLatest(SauceLabs.Orientation orientation,
Device... devices)
Gets an array of the latest
SauceCapabilities that contain the specified parameters. |
static Collection<SauceCapabilities> |
getLatest(Usable... usables)
Gets an array of the latest
SauceCapabilities that contain the specified parameters. |
static String |
getPublicJobLink(BrowserDriver driver)
Gets the job link for the test ran on the specified SauceLabs vm.
|
static String |
getPublicJobLink(String sessionId)
Generates a link to the job page on Saucelabs.com, which can be accessed without the user's
credentials.
|
static void |
refreshApi()
Refreshes the current SauceREST object.
|
static void |
updateJobInfo(String jobId,
Map<String,Object> updates)
Invokes the Sauce REST API to update the details of a Sauce job, using the details included in
the
updates parameter. |
public static URL createUrl()
public static SauceCapabilities get(Browser browser, Platform platform, String version)
SauceCapabilities
for the specified browser, platform, and version. Use
get(Browser, Platform)
to obtain the latest browser version for the given browser and
platform.
It should be noted that this method does not check to see if the specified
browser
, platform
, and version
are a valid
SauceLabs configuration. If invalid, an exception will be thrown when attempting to instantiate
the browser.
If platform is set to a generic type, the latest version of that platform will be determined
browser
- The Browser
to get the capabilities ofplatform
- The Platform
to run the browser on. Will determine the latest platform
to use if set to Platform.Windows
, Platform.Mac
, or Platform.Any
version
- The specific version of the browser that you want to useSauceCapabilities
for the specified browser, platform, and versionIllegalArgumentException
- if Browser.family()
is not Family.DESKTOP
public static SauceCapabilities get(Browser browser, Platform platform)
SauceCapabilities
for the specified browser and platform at the latest browser
version. Use get(Browser)
or get(Browser, String)
to use the latest platform
available.
It should be noted that this method does not check to see if the specified
browser
and platform
are a valid SauceLabs configuration. If invalid,
an exception will be thrown when attempting to instantiate the browser.
If platform is set to a generic type, the latest version of that platform will be determined
browser
- The Browser
to get the capabilities ofplatform
- The Platform
to run the browser on. Will determine the latest platform
to use if set to Platform.Windows
, Platform.Mac
, or Platform.Any
SauceCapabilities
for the specified browser and platform at the latest versionIllegalArgumentException
- if Browser.family()
is not Family.DESKTOP
public static SauceCapabilities get(Browser browser, String version)
SauceCapabilities
for the specified browser and browser version. Use
get(Browser)
or get(Browser, Platform)
to use the latest browser version
and/or platform available.
It should be noted that this method does not check to see if the specified
browser
and version
are a valid SauceLabs configuration.
If invalid, an exception will be thrown when attempting to instantiate the browser.
If version is set to "latest", the latest version of that browser will be determined.
browser
- The Browser
to get the capabilities ofversion
- The specific version of the browser that you want to useSauceCapabilities
for the specified browser and versionIllegalArgumentException
- if Browser.family()
is not Family.DESKTOP
public static SauceCapabilities get(Browser browser)
SauceCapabilities
for the specified browser. Will automatically obtain the
most recent platform and latest browser version for the given browser.browser
- The Browser
to get the capabilities ofSauceCapabilities
for the specified browserpublic static SauceCapabilities get(Device device, SauceLabs.Orientation orientation, String version)
SauceCapabilities
for the specified device, orientation, and version. Use
get(Device, Orientation)
or get(Device)
to use the latest device version.
It should be noted that this method does not check to see if the specified
device
, orientation
and version
are a valid SauceLabs
configuration. If invalid, an exception will be thrown when attempting to instantiate the
browser.
Note that if the device
is set to Device.iOS
or
Device.Android
It will default to the respected OS's phone.
Device.Any
defaults to Device.AndroidPhone
.
device
- The Device
to get the capabilities oforientation
- The SauceLabs.Orientation
that you want the device to be in. If this is set to
SauceLabs.Orientation.Any
, it will default to SauceLabs.Orientation.Portrait
version
- The specific OS version of the deviceSauceCapabilities
for the specified browser, orientation, and versionpublic static SauceCapabilities get(Device device, SauceLabs.Orientation orientation)
SauceCapabilities
for the specified device and orientation at the latest
version. Use get(Device)
or get(Device, String)
to use the default
orientation.
It should be noted that this method does not check to see if the specified
device
and orientation
are a valid SauceLabs configuration.
If invalid, an exception will be thrown when attempting to instantiate the browser.
Note that if the device
is set to Device.iOS
or
Device.Android
It will default to the respected OS's phone.
Device.Any
defaults to Device.AndroidPhone
.
device
- The Device
to get the capabilities oforientation
- The SauceLabs.Orientation
that you want the device to be in. If this is set to
SauceLabs.Orientation.Any
, it will default to SauceLabs.Orientation.Portrait
SauceCapabilities
for the specified browser and orientationpublic static SauceCapabilities get(Device device, String version)
SauceCapabilities
for the specified device and device version. Use
get(Device)
or get(Device, Orientation)
for the most recent version.
It should be noted that this method does not check to see if the specified
device
and version
are a valid SauceLabs configuration.
If invalid, an exception will be thrown when attempting to instantiate the browser.
Note that if the device
is set to Device.iOS
or
Device.Android
It will default to the respected OS's phone.
Device.Any
defaults to Device.AndroidPhone
. If version
is set to "latest", it will try to find the latest version for that device.
device
- The Device
to get the capabilities ofversion
- The specific OS version of the deviceSauceCapabilities
for the specified browser and versionpublic static SauceCapabilities get(Device device)
SauceCapabilities
for the specified device. Will automatically obtain the
latest device version and set Orientation to the default.
Note that if the device
is set to Device.iOS
or
Device.Android
It will default to the respected OS's phone.
Device.Any
defaults to Device.AndroidPhone
.
device
- The Device
to get the capabilities ofSauceCapabilities
for the specified browserpublic static Collection<SauceCapabilities> getAll(Browser browser, String... versions)
SauceCapabilities
that contain the specified parameters.
Parameters are a single Browser
, and a set of versions of the specified browser.browser
- The Browser
to get all capabilities ofversions
- The set of versions to get of the browser
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(String version, Browser... browsers)
SauceCapabilities
that contain the specified parameters.
Parameters are a single version and a set of Browsers
with the specified
version.version
- The version to get of the browser
browsers
- The set of Browsers
to get capabilities ofSauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(Device device, String... versions)
SauceCapabilities
that contain the specified parameters.
Parameters are a single Device
and a set of versions of the specified device.device
- The Device
to get all capabilities ofversions
- The set of versions to get of the device
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(String version, Device... devices)
SauceCapabilities
that contain the specified parameters.
Parameters are a single version and a set of Devices
with the specified version.version
- The version to get of the set of devices
devices
- The set of Devices
to get capabilities ofSauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(String version, Usable... browsers)
SauceCapabilities
that contain the specified parameters.
Parameters are a single version and a mix of Devices
and Browsers
with the specified version.version
- The version to get of the set of browsers
browsers
- The mix of Devices
and Browsers
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(String version, Platform... platforms)
SauceCapabilities
that contain the specified parameters.
Parameters are a single version and a set of Platforms
.version
- The browser version to getplatforms
- The set of Platforms
to get all browsers given the version.SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(Platform platform, String... versions)
SauceCapabilities
that contain the specified parameters.
Parameters are a single Platform
and a set of versionsplatform
- The Platform
to get SauceCapabilities
fromversions
- The set of browser versions to getSauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(SauceLabs.Orientation orientation, String... versions)
SauceCapabilities
that contain the specified parameters.
Parameters are a single SauceLabs.Orientation
and a set of versionsorientation
- The SauceLabs.Orientation
to get all tests as.versions
- The set of device versions to obtainSauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(String version, SauceLabs.Orientation... orientations)
SauceCapabilities
that contain the specified parameters.
Parameters are a single version and a set of Orientations
version
- The device version to getorientations
- The set of Orientations
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(Device device, SauceLabs.Orientation... orientations)
SauceCapabilities
that contain the specified parameters.
Parameters are a single Device
and a set of Orientations
device
- The Device
to get all SauceCapabilities
oforientations
- The set of Orientations
to getSauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(SauceLabs.Orientation orientation, Device... devices)
SauceCapabilities
that contain the specified parameters.
Parameters are a single SauceLabs.Orientation
and a set of Devices
orientation
- The SauceLabs.Orientation
to get the SauceCapabilities
ofdevices
- The set of Devices
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(Browser browser, Platform... platforms)
SauceCapabilities
that contain the specified parameters.
Parameters are a single Browser
and a set of Platforms
browser
- The single Browser
to get all SauceCapabilities
asplatforms
- The set of Platforms
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(Platform platform, Browser... browsers)
SauceCapabilities
that contain the specified parameters.
Parameters are a single Platform
and a set of Browsers
platform
- The single Platform
to get all SauceCapabilities
forbrowsers
- The set of Browsers
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(Object o)
SauceCapabilities
that contain the specified parameter. Parameter
can be a Browsers
, Devices
, Platforms
, or
Orientations
.o
- The Browsers
, Devices
, Platforms
, or
Orientations
.SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(String... versions)
SauceCapabilities
that contain the specified parameters.
Parameters are a set of versions.versions
- The set of versionsSauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(Platform... platforms)
SauceCapabilities
that contain the specified parameters.
Parameters are a set of Platforms
platforms
- The set of Platforms
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(Browser... browsers)
SauceCapabilities
that contain the specified parameters.
Parameters are a set of Browsers
browsers
- The set of Browsers
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(Usable... browsers)
SauceCapabilities
that contain the specified parameters.
Parameters are a mix of Browsers
and Devices
.browsers
- The mix of Browsers
and Devices
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(Device... devices)
SauceCapabilities
that contain the specified parameters.
Parameters are a set of Devices
devices
- The set of Devices
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll(SauceLabs.Orientation... orientations)
SauceCapabilities
that contain the specified parameters.
Parameters are a set of Orientations
orientations
- The set of Orientations
SauceCapabilities
for the given parameterspublic static Collection<SauceCapabilities> getAll()
SauceCapabilities
public static Collection<SauceCapabilities> getLatest()
SauceCapabilities
public static Collection<SauceCapabilities> getLatest(Object o)
SauceCapabilities
that contain the specified parameter.
Parameter can be a Browsers
, Devices
, Platforms
, or Orientations
.o
- The Browsers
, Devices
, Platforms
, or
Orientations
.SauceCapabilities
for the given parameters or null if not a
valid parameterpublic static Collection<SauceCapabilities> getLatest(Browser... browsers)
SauceCapabilities
that contain the specified parameters.browsers
- A set of Browser
SauceCapabilities
for the given parameters.public static Collection<SauceCapabilities> getLatest(Usable... usables)
SauceCapabilities
that contain the specified parameters.usables
- A mix of Browser
and Platform
SauceCapabilities
for the given parameters.public static Collection<SauceCapabilities> getLatest(Device... devices)
SauceCapabilities
that contain the specified parameters.devices
- A set of Device
SauceCapabilities
for the given parameters.public static Collection<SauceCapabilities> getLatest(Platform... platforms)
SauceCapabilities
that contain the specified parameters.platforms
- A set of Platform
SauceCapabilities
for the given parameters.public static Collection<SauceCapabilities> getLatest(SauceLabs.Orientation... orientations)
SauceCapabilities
that contain the specified parameters.orientations
- A set of SauceLabs.Orientation
SauceCapabilities
for the given parameters.public static Collection<SauceCapabilities> getLatest(Browser browser, Platform... platforms)
SauceCapabilities
that contain the specified parameters.browser
- A single Browser
platforms
- A set of Platform
SauceCapabilities
for the given parameters.public static Collection<SauceCapabilities> getLatest(Platform platform, Browser... browsers)
SauceCapabilities
that contain the specified parameters.platform
- A single Platform
browsers
- A set of Browser
SauceCapabilities
for the given parameters.public static Collection<SauceCapabilities> getLatest(Device device, SauceLabs.Orientation... orientations)
SauceCapabilities
that contain the specified parameters.device
- A single Device
orientations
- A set of SauceLabs.Orientation
SauceCapabilities
for the given parameters.public static Collection<SauceCapabilities> getLatest(SauceLabs.Orientation orientation, Device... devices)
SauceCapabilities
that contain the specified parameters.orientation
- A single SauceLabs.Orientation
devices
- A set of Device
SauceCapabilities
for the given parameters.public static void refreshApi()
public static String getPublicJobLink(BrowserDriver driver)
driver
- The BrowserDriver
that was ran on SauceLabspublic static String getPublicJobLink(String sessionId)
sessionId
- the Sauce Job Id, typically equal to the Selenium/WebDriver sessionIdCopyright © 2019. All rights reserved.