Skip to content

Commit

Permalink
JENKINS-12880 Changed the browser selection to a multi select list
Browse files Browse the repository at this point in the history
  • Loading branch information
rossrowe committed Feb 25, 2012
1 parent 7b136e0 commit a3949e2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Expand Up @@ -37,10 +37,13 @@
import hudson.remoting.Callable;
import hudson.tasks.BuildWrapper;
import hudson.util.Secret;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.File;
Expand Down Expand Up @@ -69,17 +72,17 @@ public class SauceOnDemandBuildWrapper extends BuildWrapper implements Serializa
private int seleniumPort;
private Credentials credentials;
private SeleniumInformation seleniumInformation;
private String browser;
private List<String> browsers;

@DataBoundConstructor
public SauceOnDemandBuildWrapper(Credentials
credentials, SeleniumInformation seleniumInformation, String seleniumHost, int seleniumPort, boolean enableSauceConnect, String browser) {
credentials, SeleniumInformation seleniumInformation, String seleniumHost, int seleniumPort, boolean enableSauceConnect, List<String> browsers) {
this.credentials = credentials;
this.seleniumInformation = seleniumInformation;
this.enableSauceConnect = enableSauceConnect;
this.seleniumHost = seleniumHost;
this.seleniumPort = seleniumPort;
this.browser = browser;
this.browsers = browsers;
}


Expand All @@ -100,9 +103,29 @@ public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener l

@Override
public void buildEnvVars(Map<String, String> env) {
if (browser != null) {
Browser browserInstance = BrowserFactory.getInstance().forKey(browser);
env.put("SELENIUM_DRIVER", browserInstance.getUri());

if (browsers != null && !browsers.isEmpty()) {
if (browsers.size() == 1) {
Browser browserInstance = BrowserFactory.getInstance().forKey(browsers.get(0));
env.put("SELENIUM_DRIVER", browserInstance.getUri());
}

JSONArray browsersJSON = new JSONArray();
for (String browser : browsers) {
Browser browserInstance = BrowserFactory.getInstance().forKey(browser);
JSONObject config = new JSONObject();
try {
config.put("os", browserInstance.getOs());
config.put("browser", browserInstance.getBrowserName());
config.put("browser-version", browserInstance.getVersion());
} catch (JSONException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
browsersJSON.put(config);

}

env.put("SAUCE_ONDEMAND_BROWSERS", StringEscapeUtils.escapeJava(browsersJSON.toString()));
}
env.put("SAUCE_ONDEMAND_HOST", getHostName());
env.put("SAUCE_ONDEMAND_PORT", Integer.toString(getPort()));
Expand Down Expand Up @@ -214,12 +237,12 @@ public void setEnableSauceConnect(boolean enableSauceConnect) {
this.enableSauceConnect = enableSauceConnect;
}

public String getBrowser() {
return browser;
public List<String> getBrowsers() {
return browsers;
}

public void setBrowser(String browser) {
this.browser = browser;
public void setBrowsers(List<String> browsers) {
this.browsers = browsers;
}

private interface ITunnelHolder {
Expand Down
Expand Up @@ -7,11 +7,10 @@
<f:checkbox title="${%Enable Sauce Connect?}" default="checked"/>
</f:entry>
<f:entry title="${%Operating System/Browser/Version}">
<select name="browser">
<select name="browsers" multiple="multiple">
<j:forEach var="b" items="${descriptor.browsers}">

<j:choose>
<j:when test="${instance.browser==b.key}">
<j:when test="${instance.browsers.contains(b.key)}">
<option value="${b.key}" selected="selected">${b.name}</option>
</j:when>
<j:otherwise>
Expand Down

0 comments on commit a3949e2

Please sign in to comment.