Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…configuration under jenkins 'manager jenkins' is not saved.

2. Remove deprecated and unused parameters from Configure System page: -rcDebug, -rcLog
3. Add parameter -browserTimeout
4. Set correct description for parameter -timeout (it was changed since selenium v2.21)
5. Remove code which terminates starting selenium node in #startSeleniumNode() in case getHostName() returns null. Reason: node hostname can be manually configured on node in case it is non-discoverable from master. In such case node will successfully starts.
  • Loading branch information
kool79 committed Dec 9, 2014
1 parent 2e3ff94 commit 1e3486b
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 55 deletions.
69 changes: 51 additions & 18 deletions src/main/java/hudson/plugins/selenium/PluginImpl.java
Expand Up @@ -44,6 +44,7 @@
import hudson.plugins.selenium.configuration.global.hostname.HostnameResolver;
import hudson.plugins.selenium.configuration.global.hostname.HostnameResolverDescriptor;
import hudson.plugins.selenium.configuration.global.hostname.JenkinsRootHostnameResolver;
import hudson.plugins.selenium.configuration.global.hostname.StaticHostnameResolver;
import hudson.plugins.selenium.configuration.global.matcher.SeleniumConfigurationMatcher;
import hudson.plugins.selenium.configuration.global.matcher.SeleniumConfigurationMatcher.MatcherDescriptor;
import hudson.plugins.selenium.configuration.global.matcher.MatchAllMatcher;
Expand Down Expand Up @@ -80,6 +81,8 @@

import jenkins.model.Jenkins;

import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.StaplerRequest;
Expand All @@ -90,11 +93,12 @@
import org.openqa.grid.internal.Registry;
import org.openqa.grid.internal.RemoteProxy;
import org.openqa.grid.internal.TestSlot;
import org.openqa.selenium.WebDriver;
import org.springframework.util.StringUtils;

/**
* Starts Selenium Grid server in another JVM.
*
*
* @author Kohsuke Kawaguchi
* @author Richard Lavoie
* @author Ryan Thomas Correia Ortega
Expand All @@ -120,12 +124,11 @@ public class PluginImpl extends Plugin implements Action, Serializable, Describa
* Exclusion pattern for nodes. Nodes matching this pattern will not have a selenium node running on them.
*/
private String exclusionPatterns;
private Integer newSessionWaitTimeout = -1;
private Integer timeout = 30;
private Integer newSessionWaitTimeout = -1; //ms or -1
private Integer timeout = 300; //sec // default value as defined in WebDriver
private Integer browserTimeout = 0; //sec // default value as defined in WebDriver
private boolean throwOnCapabilityNotPresent = false;
private String hubLogLevel = "INFO";
private boolean rcDebug;
private String rcLog;

private HostnameResolver hostnameResolver = new JenkinsRootHostnameResolver();

Expand All @@ -134,6 +137,8 @@ public class PluginImpl extends Plugin implements Action, Serializable, Describa
private transient Boolean rcBrowserSessionReuse;
private transient Boolean rcTrustAllSSLCerts;
private transient Boolean rcBrowserSideLog;
private transient boolean rcDebug;
private transient String rcLog;

private List<SeleniumGlobalConfiguration> configurations = new ArrayList<SeleniumGlobalConfiguration>();

Expand All @@ -148,17 +153,42 @@ public class PluginImpl extends Plugin implements Action, Serializable, Describa

@Override
public void postInitialize() throws Exception {
load();

startHub();

Hudson.getInstance().getActions().add(this);
}

@Override
public void start() throws Exception {
load();
}

@Override
public void configure(StaplerRequest req, JSONObject formData)
throws IOException, ServletException, Descriptor.FormException {
super.configure(req, formData);

LOGGER.warning(formData.toString());
port = formData.optInt("port", 4444);
exclusionPatterns = formData.getString("exclusionPatterns");
hubLogLevel = formData.getString("hubLogLevel");
newSessionWaitTimeout = formData.optInt("newSessionWaitTimeout", -1);
timeout = formData.optInt("timeout", 300000);
browserTimeout = formData.optInt("browserTimeout", 0);
throwOnCapabilityNotPresent = formData.getBoolean("throwOnCapabilityNotPresent");

LOGGER.warning(formData.getJSONObject("hostnameResolver").toString());

hostnameResolver = req.bindJSON(HostnameResolver.class, formData.getJSONObject("hostnameResolver"));

save();
}

/**
* @throws IOException
* @throws InterruptedException
*
*
*/
private void startHub() throws IOException, InterruptedException {

Expand All @@ -178,6 +208,10 @@ private void startHub() throws IOException, InterruptedException {
args.add("-timeout");
args.add(getTimeout().toString());
}
if (getBrowserTimeout() != null) {
args.add("-browserTimeout");
args.add(getBrowserTimeout().toString());
}
if (getThrowOnCapabilityNotPresent()) {
args.add("-throwOnCapabilityNotPresent");
args.add(Boolean.toString(getThrowOnCapabilityNotPresent()));
Expand Down Expand Up @@ -239,6 +273,11 @@ public Integer getTimeout() {
return timeout;
}

@Exported
public Integer getBrowserTimeout() {
return browserTimeout;
}

@Exported
public String getHubLogLevel() {
return hubLogLevel != null ? hubLogLevel : "INFO";
Expand Down Expand Up @@ -280,7 +319,7 @@ public Collection<SeleniumTestSlotGroup> getRemoteControls() throws IOException,
Collection<SeleniumTestSlotGroup> rcs = channel.call(new Callable<Collection<SeleniumTestSlotGroup>, RuntimeException>() {

/**
*
*
*/
private static final long serialVersionUID = 1791985298575049757L;

Expand Down Expand Up @@ -385,7 +424,7 @@ public Object readResolve() {

/**
* Returns either the object, or the default value is null.
*
*
* @param object
* Object to return
* @param defaultObject
Expand Down Expand Up @@ -441,12 +480,6 @@ public static void startSeleniumNode(Computer c, TaskListener listener, String c
return;
}

String nodehost = c.getHostName();
if (nodehost == null) {
LOGGER.warning("Unable to determine node's hostname. Skipping");
return;
}

listener.getLogger().println("Starting Selenium nodes on " + ("".equals(c.getName()) ? "(master)" : c.getName()));

for (SeleniumGlobalConfiguration config : confs) {
Expand Down Expand Up @@ -499,7 +532,7 @@ public SeleniumGlobalConfiguration getConfiguration(String name) {
}

/**
*
*
* @param req
* StaplerRequest
* @param rsp
Expand All @@ -521,15 +554,15 @@ public void validateAdmin() {

/**
* Return true if the user has selenium admin access.
*
*
* @return True if the user is a selenium admin, false otherwise
*/
public boolean isAdmin() {
return Hudson.getInstance().hasPermission(getRequiredPermission());
}

/**
*
*
* @param req
* StaplerRequest
* @param rsp
Expand Down
@@ -1,26 +1,32 @@
/**
*
*
*/
package hudson.plugins.selenium.configuration.global.hostname;

import hudson.Extension;
import hudson.model.Hudson;
import org.kohsuke.stapler.DataBoundConstructor;

import java.net.MalformedURLException;
import java.net.URL;

/**
* @author Richard Lavoie
*
*
*/
public class JenkinsRootHostnameResolver extends HostnameResolver {

/**
*
*
*/
private static final long serialVersionUID = 7865004453289102894L;

public String retrieveHost() {
@DataBoundConstructor
public JenkinsRootHostnameResolver() {
}


public String retrieveHost() {
String rootUrl = Hudson.getInstance().getRootUrl();
if (rootUrl == null)
return "localhost";
Expand Down
@@ -1,30 +1,36 @@
/**
*
*
*/
package hudson.plugins.selenium.configuration.global.hostname;

import hudson.Extension;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* @author Richard Lavoie
*
*
*/
public class StaticHostnameResolver extends HostnameResolver {

/**
*
*
*/
private static final long serialVersionUID = -6854399632708036684L;

private String hostname;

@DataBoundConstructor
public StaticHostnameResolver(String hostname) {
this.hostname = hostname;
}

public String retrieveHost() {
return hostname;
}
public String retrieveHost() {
return hostname;
}

public String getHostname() {
return hostname;
}

@Extension
public static final class StaticHostnameRetrieverDescriptor extends HostnameResolverDescriptor {
Expand Down
Expand Up @@ -4,7 +4,7 @@
<j:set var="descriptor" value="${it.descriptor}"/>
<j:set var="configurationType" value="${ct}"/>
<f:section title="Selenium">
<f:entry title="${%Selenium Grid Port}" field="port">
<f:entry title="${%Selenium Hub Port}" field="port">
<f:textbox />
</f:entry>
<f:advanced>
Expand All @@ -24,16 +24,12 @@
<f:entry title="${%Set -timeout}" field="timeout">
<f:textbox />
</f:entry>
<f:entry title="${%Enable -throwOnCapabilityNotPresent}" field="throwOnCapabilityNotPresent">
<f:checkbox />
<f:entry title="${%Set -browserTimeout}" field="browserTimeout">
<f:textbox />
</f:entry>

<f:entry title="${%Enable -debug}" field="rcDebug">
<f:entry title="${%Enable -throwOnCapabilityNotPresent}" field="throwOnCapabilityNotPresent">
<f:checkbox />
</f:entry>
<f:entry title="${%Set -log}" field="rcLog">
<f:textbox />
</f:entry>
<f:entry title="${%Hostname}">
<table style="width:100%">
<f:descriptorRadioList title="${%Hostname resolver}" varName="hostnameResolver" instance="${it.hostnameResolver}" descriptors="${it.resolverTypes}"/>
Expand All @@ -42,4 +38,4 @@
</f:advanced>
</f:section>
</j:scope>
</j:jelly>
</j:jelly>
@@ -0,0 +1,10 @@
<div>
Starting from selenium v2.21.0
<br/>Controls how long the browser is allowed to hang (value in <b>seconds</b>)
<br/>
The grid does not act on this value by itself, but passes the value on to the nodes, which do.
Should be higher than the socket lock timeout (45 seconds) and generally higher than values used in webDriver.manage().timeouts()
<br/><br/>
See also
<br/><a href="https://code.google.com/p/selenium/wiki/Grid2">https://code.google.com/p/selenium/wiki/Grid2</a>
</div>
@@ -1,5 +1,5 @@
<div>
Time in ms after which a new test waiting for a node to become available will
time out.When that happens, the test will throw an exception before starting
a browser.
</div>
Time in <b>ms</b> after which a new test waiting for a node to become available will
time out.When that happens, the test will throw an exception before starting
a browser.
</div>

This file was deleted.

This file was deleted.

@@ -1,3 +1,17 @@
<div>
Specify the number of seconds that the server will wait for the browser to respond to the previous command, or for the client driver to issue a new request.
</div>
Controls how long (value in <b>seconds</b>) the client is allowed to be gone before the session is reclaimed.
Typically takes care of the client crashes. Working together with cleanup cycle (default is 5sec).
Worst case scenario, a session can be idle for timeout + cleanup cycle before the timeout is detected.
<br/>
When elapsed the browser will be released for another test to use.
To remove the timeout completely, specify -timeout 0 and the hub will never release the node.
(Can be used when doing step-by-step debugging of client code)
<br/>
Default value is 30sec.
<br/>
Replaces the -nodeTimeout parameter starting from selenium v2.21.0
<br/><br/>
See also:
<br/> <a href="https://code.google.com/p/selenium/wiki/Grid2">https://code.google.com/p/selenium/wiki/Grid2</a>
<br/> <a href="https://code.google.com/p/selenium/wiki/RemoteWebDriverServer">https://code.google.com/p/selenium/wiki/RemoteWebDriverServer</a>
</div>

1 comment on commit 1e3486b

@sne11ius
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also fix #39?

Please sign in to comment.