Skip to content
Permalink
Browse files

JENKINS-12880 Enable the selection of the browser/version/os at the J…

…ob level
  • Loading branch information
rossrowe committed Feb 24, 2012
1 parent a496e5f commit 737028336ce982c3313e5752f6812b79e686de8c

This file was deleted.

@@ -75,6 +75,11 @@ public String getDisplayName() {
}
}

/**
* Adds the browser URI to the environment map. Will override any values set in {@link SauceOnDemandBuildWrapper#setUp(hudson.model.AbstractBuild, hudson.Launcher, hudson.model.BuildListener)}
* @param value
* @param map
*/
public void addBuildVariable(String value, Map<String,String> map) {
com.saucelabs.ci.Browser b = BrowserFactory.getInstance().forKey(value);
if (b!=null) // should never be null, but let's be defensive in case of downgrade.
@@ -24,6 +24,8 @@
package hudson.plugins.sauce_ondemand;

import com.michelin.cio.hudson.plugins.copytoslave.MyFilePath;
import com.saucelabs.ci.Browser;
import com.saucelabs.ci.BrowserFactory;
import com.saucelabs.ci.sauceconnect.SauceConnectUtils;
import com.saucelabs.ci.sauceconnect.SauceTunnelManager;
import com.saucelabs.hudson.HudsonSauceManagerFactory;
@@ -33,18 +35,20 @@
import hudson.Util;
import hudson.model.*;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.tasks.BuildWrapper;
import hudson.util.Secret;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.json.JSONException;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
@@ -65,15 +69,17 @@
private int seleniumPort;
private Credentials credentials;
private SeleniumInformation seleniumInformation;
private String browser;

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


@@ -94,6 +100,10 @@ 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());
}
env.put("SAUCE_ONDEMAND_HOST", getHostName());
env.put("SAUCE_ONDEMAND_PORT", Integer.toString(getPort()));
if (getStartingURL() != null) {
@@ -204,6 +214,14 @@ public void setEnableSauceConnect(boolean enableSauceConnect) {
this.enableSauceConnect = enableSauceConnect;
}

public String getBrowser() {
return browser;
}

public void setBrowser(String browser) {
this.browser = browser;
}

private interface ITunnelHolder {
void close(TaskListener listener);
}
@@ -215,14 +233,6 @@ public TunnelHolder(String username) {
this.username = username;
}

public Object writeReplace() {
if (Channel.current() == null) {
return this;
} else {
return Channel.current().export(ITunnelHolder.class, this);
}
}

public void close(TaskListener listener) {

try {
@@ -291,5 +301,18 @@ public ITunnelHolder call() throws IOException {
public String getDisplayName() {
return "Sauce OnDemand Support";
}

public List<Browser> getBrowsers() {
try {
return BrowserFactory.getInstance().values();
} catch (IOException e) {
logger.error("Error retrieving browsers from Saucelabs", e);
} catch (JSONException e) {
logger.error("Error parsing JSON response", e);
}
return Collections.emptyList();
}
}


}
@@ -3,28 +3,46 @@

<f:block>
<f:section title="Sauce Connect Options">
<f:entry field="enableSauceConnect">
<f:checkbox title="${%Enable Sauce Connect?}" default="checked"/>
</f:entry>
<f:entry field="enableSauceConnect">
<f:checkbox title="${%Enable Sauce Connect?}" default="checked"/>
</f:entry>
<f:entry title="${%Operating System/Browser/Version}">
<select name="browser">
<j:forEach var="b" items="${descriptor.browsers}">

<f:optionalBlock field="seleniumInformation" checked="${instance.seleniumInformation != null}" title="${%Will Selenium 1 tests be run?}">
<j:set var="seleniumInformation" value="${instance.seleniumInformation}"/>
<j:choose>
<j:when test="${instance.browser==b.key}">
<option value="${b.key}" selected="selected">${b.name}</option>
</j:when>
<j:otherwise>
<option value="${b.key}">${b.name}</option>
</j:otherwise>
</j:choose>

<f:entry title="${%Starting URL}" field="startingURL">
<f:textbox value="${seleniumInformation.startingURL}"/>
</j:forEach>
</select>
</f:entry>

</f:optionalBlock>
<f:optionalBlock field="seleniumInformation" checked="${instance.seleniumInformation != null}"
title="${%Will Selenium 1 tests be run?}">
<j:set var="seleniumInformation" value="${instance.seleniumInformation}"/>

<f:optionalBlock field="credentials" checked="${instance.credentials != null}" title="${%Override default authentication?}">
<j:set var="credentials" value="${instance.credentials}"/>
<f:entry title="${%Username}" field="username">
<f:textbox value="${credentials.username}"/>
</f:entry>
<f:entry title="${%API Access Key}" field="apiKey">
<f:password value="${credentials.apiKey}"/>
</f:entry>
</f:optionalBlock>
<f:entry title="${%Starting URL}" field="startingURL">
<f:textbox value="${seleniumInformation.startingURL}"/>
</f:entry>

</f:optionalBlock>

<f:optionalBlock field="credentials" checked="${instance.credentials != null}"
title="${%Override default authentication?}">
<j:set var="credentials" value="${instance.credentials}"/>
<f:entry title="${%Username}" field="username">
<f:textbox value="${credentials.username}"/>
</f:entry>
<f:entry title="${%API Access Key}" field="apiKey">
<f:password value="${credentials.apiKey}"/>
</f:entry>
</f:optionalBlock>
</f:section>
<f:section title="Sauce Connect Advanced Options">
<f:advanced>
@@ -3,7 +3,6 @@
import com.saucelabs.rest.Credential;
import com.saucelabs.sauce_ondemand.driver.SauceOnDemandSelenium;
import com.saucelabs.selenium.client.factory.SeleniumFactory;
import com.thoughtworks.selenium.Selenium;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import org.junit.Assert;
@@ -46,7 +45,7 @@ public String doTest() throws IOException, InterruptedException {
}
System.setProperty("SELENIUM_STARTING_URL", url);

System.setProperty("SELENIUM_DRIVER", Browser.Firefox3_0_Linux.getUri());
System.setProperty("SELENIUM_DRIVER", new com.saucelabs.ci.Browser("Firefox3_0_Linux", "linux", "firefox", "3.0", "firefox").getUri());

SauceOnDemandSelenium selenium = (SauceOnDemandSelenium) SeleniumFactory.create();
selenium.start();

0 comments on commit 7370283

Please sign in to comment.
You can’t perform that action at this time.