-
Notifications
You must be signed in to change notification settings - Fork 61
Home
The goal of the helper classes is to provide the maximum amount of functionality while minimizing the amount of changes to existing tests. They will record the Sauce Job as passed/failed based on the test outcome, populate the username/access key based on environment variables, and print the Sauce OnDemand session id to the System out (which will be parsed by the Sauce OnDemand plugins for Jenkins, Hudson and Bamboo).
The JUnit helper can be included by implementing an interface and adding two variables, eg:
public class WebDriverTest implements SauceOnDemandSessionIdProvider {
public SauceOnDemandAuthentication authentication = new SauceOnDemandAuthentication();
public @Rule SauceOnDemandTestWatcher resultReportingTestWatcher = new SauceOnDemandTestWatcher(this, authentication);
//required by SauceOnDemandSessionIdProvider interface
@Override
public String getSessionId() {
return ((RemoteWebDriver)driver).getSessionId().toString();;
}
//rest of test class as per usual...
}
The TestNG helper can be included by referencing a test listener and implementing an interface, eg.
@Listeners({SauceOnDemandTestListener.class})
public class WebDriverTest implements SauceOnDemandSessionIdProvider, SauceOnDemandAuthenticationProvider {
public SauceOnDemandAuthentication authentication = new SauceOnDemandAuthentication();
//required by SauceOnDemandSessionIdProvider interface
@Override
public String getSessionId() {
return ((RemoteWebDriver)driver).getSessionId().toString();;
}
//required by SauceOnDemandAuthenticationProvider interface
@Override
public SauceOnDemandAuthentication getAuthentication() {
return authentication;
}
//rest of test class as per usual...
}
The helper classes have been deployed to the Sauce Labs Maven repository, and can be referenced by a Maven project by including the following dependency:
<!-- for JUnit -->
<dependency>
<groupId>com.saucelabs</groupId>
<artifactId>sauce_junit</artifactId>
<version>LATEST</version>
<scope>test</scope>
</dependency>
<!-- for TestNG -->
<dependency>
<groupId>com.saucelabs</groupId>
<artifactId>sauce_testng</artifactId>
<version>LATEST</version>
<scope>test</scope>
</dependency>