Sauce Labs On Demand has a great plugin for Jenkins ( https://saucelabs.com/jenkins/5 ). Their approach is quite simple: you check / take off which OS and browsers you test, and Jenkins sets environment variables for your tests. The following is a complete example of using Spring @Configuration:
package com.acme.test; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import org.springframework.core.env.Environment; @Configuration public class SauceLabsWebDriverConfiguration { @Autowired private Environment environment; @Bean @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public WebDriver webDriver() throws MalformedURLException { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("version", environment.getProperty("SELENIUM_VERSION", "17.0.1")); capabilities.setCapability("platform", environment.getProperty("SELENIUM_PLATFORM", "XP")); capabilities.setCapability("browserName", environment.getProperty("SELENIUM_BROWSER", "firefox")); String username = environment.getProperty("SAUCE_USER_NAME", "enter_your_username_here"); String accessKey = environment.getProperty("SAUCE_API_KEY", "enter_your_api_here"); return new RemoteWebDriver(new URL("http://" + username + ":" + accessKey + "@ondemand.saucelabs.com:80/wd/hub"), capabilities); } }
Sauce Labs has some free plans, but if you do not want to use them, you should be able to disable the last part, which creates the URL ("http: //" + username + ":" + accessKey + "@ ondemand.saucelabs .com: 80 / wd / hub ") the actual URL of the server you want to point to (" http://mydomain.com ").
The trick is basically replacing the names of hard-coded browsers / features with the provided environments, and then you have a build runner (ant / maven / etc) that sets the environment variables for each combo version of the OS / browser that you want to test and "loop" over them somehow. SauceLabs plugins simply simplify looping. You can still provide fallback defaults if you want to run a simple local test.
// Before DesiredCapabilities firefoxCapabs = DesiredCapabilities.firefox(); capabillities.setCapability("version", "26"); capabillities.setCapability("platform", Platform.WINDOWS); // After DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("version", environment.getProperty("SELENIUM_VERSION", "17.0.1")); capabilities.setCapability("platform", environment.getProperty("SELENIUM_PLATFORM", "XP")); capabilities.setCapability("browserName", environment.getProperty("SELENIUM_BROWSER", "firefox"));
Hope this helps.
source share