Sauce Labs On Demand has a great plugin for Jenkins (https://saucelabs.com/jenkins/5). Their approach is pretty simple: you check/uncheck what OSs and browsers you to test and Jenkins sets environment variables for your tests to pick up. Below is a complete example of using Spring's @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 don't want to use them, you should be able to switch out the last part that constructs the URL ("http://" + username + ":" + accessKey + "@ondemand.saucelabs.com:80/wd/hub") the actual server URL you want to point to ("http://mydomain.com").
The trick is basically to replace hard-coded browser/capability names with environment provided ones and then have your build runner (ant/maven/etc) set environment variables for each of the OS/browser combos you want to test and "loop" over those somehow. SauceLabs plugins just makes it easy to do the looping. You can still provide default fallback values in case 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 it helps.