Skip to content

Commit

Permalink
SimonStewart: Start moving all timeout configuration to use a single …
Browse files Browse the repository at this point in the history
…end-point rather than a range.

r15880
  • Loading branch information
shs96c committed Feb 13, 2012
1 parent 5b8b7c0 commit d2e5c39
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 109 deletions.
35 changes: 31 additions & 4 deletions java/client/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

package org.openqa.selenium.firefox;

import static org.openqa.selenium.Platform.WINDOWS;
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_SSL_CERTS;
import static org.openqa.selenium.remote.CapabilityType.LOGGING_PREFS;
import static org.openqa.selenium.remote.CapabilityType.PROXY;
import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.OutputType;
Expand All @@ -46,6 +43,12 @@

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static org.openqa.selenium.Platform.WINDOWS;
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_SSL_CERTS;
import static org.openqa.selenium.remote.CapabilityType.LOGGING_PREFS;
import static org.openqa.selenium.remote.CapabilityType.PROXY;


/**
Expand Down Expand Up @@ -146,6 +149,30 @@ protected RemoteWebElement newRemoteWebElement() {
});
}

@Override
public Options manage() {
return new RemoteWebDriverOptions() {
@Override
public Timeouts timeouts() {
return new Timeouts() {
public Timeouts implicitlyWait(long time, TimeUnit unit) {
execute(DriverCommand.SET_TIMEOUT, ImmutableMap.of(
"type", "implicit",
"ms", TimeUnit.MILLISECONDS.convert(time, unit)));
return this;
}

public Timeouts setScriptTimeout(long time, TimeUnit unit) {
execute(DriverCommand.SET_TIMEOUT, ImmutableMap.of(
"type", "script",
"ms", TimeUnit.MILLISECONDS.convert(time, unit)));
return this;
}
};
}
};
}

@Override
protected void startClient() {
LazyCommandExecutor exe = (LazyCommandExecutor) getCommandExecutor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public interface DriverCommand {
String GET_ALERT_TEXT = "getAlertText";
String SET_ALERT_VALUE = "setAlertValue";

String SET_TIMEOUT = "setTimeout";
String IMPLICITLY_WAIT = "implicitlyWait";
String SET_SCRIPT_TIMEOUT = "setScriptTimeout";

Expand Down
103 changes: 2 additions & 101 deletions java/client/src/org/openqa/selenium/remote/HttpCommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,107 +56,7 @@
import java.util.Map;

import static org.apache.http.protocol.ExecutionContext.HTTP_TARGET_HOST;
import static org.openqa.selenium.remote.DriverCommand.ACCEPT_ALERT;
import static org.openqa.selenium.remote.DriverCommand.ADD_COOKIE;
import static org.openqa.selenium.remote.DriverCommand.CLEAR_APP_CACHE;
import static org.openqa.selenium.remote.DriverCommand.CLEAR_ELEMENT;
import static org.openqa.selenium.remote.DriverCommand.CLEAR_LOCAL_STORAGE;
import static org.openqa.selenium.remote.DriverCommand.CLEAR_SESSION_STORAGE;
import static org.openqa.selenium.remote.DriverCommand.CLICK;
import static org.openqa.selenium.remote.DriverCommand.CLICK_ELEMENT;
import static org.openqa.selenium.remote.DriverCommand.CLOSE;
import static org.openqa.selenium.remote.DriverCommand.DELETE_ALL_COOKIES;
import static org.openqa.selenium.remote.DriverCommand.DELETE_COOKIE;
import static org.openqa.selenium.remote.DriverCommand.DISMISS_ALERT;
import static org.openqa.selenium.remote.DriverCommand.DOUBLE_CLICK;
import static org.openqa.selenium.remote.DriverCommand.DRAG_ELEMENT;
import static org.openqa.selenium.remote.DriverCommand.ELEMENT_EQUALS;
import static org.openqa.selenium.remote.DriverCommand.EXECUTE_ASYNC_SCRIPT;
import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT;
import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SQL;
import static org.openqa.selenium.remote.DriverCommand.FIND_CHILD_ELEMENT;
import static org.openqa.selenium.remote.DriverCommand.FIND_CHILD_ELEMENTS;
import static org.openqa.selenium.remote.DriverCommand.FIND_ELEMENT;
import static org.openqa.selenium.remote.DriverCommand.FIND_ELEMENTS;
import static org.openqa.selenium.remote.DriverCommand.GET;
import static org.openqa.selenium.remote.DriverCommand.GET_ACTIVE_ELEMENT;
import static org.openqa.selenium.remote.DriverCommand.GET_ALERT;
import static org.openqa.selenium.remote.DriverCommand.GET_ALERT_TEXT;
import static org.openqa.selenium.remote.DriverCommand.GET_ALL_COOKIES;
import static org.openqa.selenium.remote.DriverCommand.GET_APP_CACHE;
import static org.openqa.selenium.remote.DriverCommand.GET_APP_CACHE_STATUS;
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_URL;
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_WINDOW_HANDLE;
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_ATTRIBUTE;
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_LOCATION;
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW;
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_SIZE;
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_TAG_NAME;
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_TEXT;
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_VALUE;
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_VALUE_OF_CSS_PROPERTY;
import static org.openqa.selenium.remote.DriverCommand.GET_LOCAL_STORAGE_ITEM;
import static org.openqa.selenium.remote.DriverCommand.GET_LOCAL_STORAGE_KEYS;
import static org.openqa.selenium.remote.DriverCommand.GET_LOCAL_STORAGE_SIZE;
import static org.openqa.selenium.remote.DriverCommand.GET_LOCATION;
import static org.openqa.selenium.remote.DriverCommand.GET_PAGE_SOURCE;
import static org.openqa.selenium.remote.DriverCommand.GET_SCREEN_ORIENTATION;
import static org.openqa.selenium.remote.DriverCommand.GET_SESSION_STORAGE_ITEM;
import static org.openqa.selenium.remote.DriverCommand.GET_SESSION_STORAGE_KEYS;
import static org.openqa.selenium.remote.DriverCommand.GET_SESSION_STORAGE_SIZE;
import static org.openqa.selenium.remote.DriverCommand.GET_TITLE;
import static org.openqa.selenium.remote.DriverCommand.GET_WINDOW_HANDLES;
import static org.openqa.selenium.remote.DriverCommand.GET_WINDOW_SIZE;
import static org.openqa.selenium.remote.DriverCommand.GET_WINDOW_POSITION;
import static org.openqa.selenium.remote.DriverCommand.GO_BACK;
import static org.openqa.selenium.remote.DriverCommand.GO_FORWARD;
import static org.openqa.selenium.remote.DriverCommand.HOVER_OVER_ELEMENT;
import static org.openqa.selenium.remote.DriverCommand.IME_ACTIVATE_ENGINE;
import static org.openqa.selenium.remote.DriverCommand.IME_DEACTIVATE;
import static org.openqa.selenium.remote.DriverCommand.IME_GET_ACTIVE_ENGINE;
import static org.openqa.selenium.remote.DriverCommand.IME_GET_AVAILABLE_ENGINES;
import static org.openqa.selenium.remote.DriverCommand.IME_IS_ACTIVATED;
import static org.openqa.selenium.remote.DriverCommand.IMPLICITLY_WAIT;
import static org.openqa.selenium.remote.DriverCommand.IS_BROWSER_ONLINE;
import static org.openqa.selenium.remote.DriverCommand.IS_BROWSER_VISIBLE;
import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_DISPLAYED;
import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_ENABLED;
import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_SELECTED;
import static org.openqa.selenium.remote.DriverCommand.GET_LOGS;
import static org.openqa.selenium.remote.DriverCommand.MOUSE_DOWN;
import static org.openqa.selenium.remote.DriverCommand.MOUSE_UP;
import static org.openqa.selenium.remote.DriverCommand.MOVE_TO;
import static org.openqa.selenium.remote.DriverCommand.NEW_SESSION;
import static org.openqa.selenium.remote.DriverCommand.QUIT;
import static org.openqa.selenium.remote.DriverCommand.REFRESH;
import static org.openqa.selenium.remote.DriverCommand.REMOVE_LOCAL_STORAGE_ITEM;
import static org.openqa.selenium.remote.DriverCommand.REMOVE_SESSION_STORAGE_ITEM;
import static org.openqa.selenium.remote.DriverCommand.SCREENSHOT;
import static org.openqa.selenium.remote.DriverCommand.SEND_KEYS_TO_ELEMENT;
import static org.openqa.selenium.remote.DriverCommand.SEND_KEYS_TO_ACTIVE_ELEMENT;
import static org.openqa.selenium.remote.DriverCommand.SET_ALERT_VALUE;
import static org.openqa.selenium.remote.DriverCommand.SET_BROWSER_ONLINE;
import static org.openqa.selenium.remote.DriverCommand.SET_BROWSER_VISIBLE;
import static org.openqa.selenium.remote.DriverCommand.SET_LOCAL_STORAGE_ITEM;
import static org.openqa.selenium.remote.DriverCommand.SET_LOCATION;
import static org.openqa.selenium.remote.DriverCommand.SET_SCREEN_ORIENTATION;
import static org.openqa.selenium.remote.DriverCommand.SET_SCRIPT_TIMEOUT;
import static org.openqa.selenium.remote.DriverCommand.SET_SESSION_STORAGE_ITEM;
import static org.openqa.selenium.remote.DriverCommand.SET_WINDOW_POSITION;
import static org.openqa.selenium.remote.DriverCommand.SET_WINDOW_SIZE;
import static org.openqa.selenium.remote.DriverCommand.STATUS;
import static org.openqa.selenium.remote.DriverCommand.SUBMIT_ELEMENT;
import static org.openqa.selenium.remote.DriverCommand.SWITCH_TO_FRAME;
import static org.openqa.selenium.remote.DriverCommand.SWITCH_TO_WINDOW;
import static org.openqa.selenium.remote.DriverCommand.TOUCH_DOUBLE_TAP;
import static org.openqa.selenium.remote.DriverCommand.TOUCH_DOWN;
import static org.openqa.selenium.remote.DriverCommand.TOUCH_FLICK;
import static org.openqa.selenium.remote.DriverCommand.TOUCH_LONG_PRESS;
import static org.openqa.selenium.remote.DriverCommand.TOUCH_MOVE;
import static org.openqa.selenium.remote.DriverCommand.TOUCH_SCROLL;
import static org.openqa.selenium.remote.DriverCommand.TOUCH_SINGLE_TAP;
import static org.openqa.selenium.remote.DriverCommand.TOUCH_UP;
import static org.openqa.selenium.remote.DriverCommand.UPLOAD_FILE;
import static org.openqa.selenium.remote.DriverCommand.*;

public class HttpCommandExecutor implements CommandExecutor {

Expand Down Expand Up @@ -292,6 +192,7 @@ public HttpCommandExecutor(URL addressOfRemoteServer) {
get("/session/:sessionId/element/:id/css/:propertyName"))
.put(IMPLICITLY_WAIT, post("/session/:sessionId/timeouts/implicit_wait"))
.put(SET_SCRIPT_TIMEOUT, post("/session/:sessionId/timeouts/async_script"))
.put(SET_TIMEOUT, post("/session/:sessionId/timeouts"))
.put(EXECUTE_SQL, post("/session/:sessionId/execute_sql"))
.put(GET_LOCATION, get("/session/:sessionId/location"))
.put(SET_LOCATION, post("/session/:sessionId/location"))
Expand Down
20 changes: 17 additions & 3 deletions java/client/test/org/openqa/selenium/ImplicitWaitTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
Copyright 2012 WebDriver committers
Copyright 2012 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package org.openqa.selenium;

import static org.openqa.selenium.testing.Ignore.Driver.ANDROID;
Expand All @@ -15,9 +32,6 @@

import java.util.List;

/**
* @author jmleyba@gmail.com (Jason Leyba)
*/
@NeedsLocalEnvironment(reason =
"Executing these tests over the wire doesn't work, because they relies on 100ms-specific timing")
public class ImplicitWaitTest extends AbstractDriverTestCase {
Expand Down
2 changes: 1 addition & 1 deletion java/client/test/org/openqa/selenium/SingleTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static Test suite() throws Exception {
.using(browser)
.keepDriverInstance()
.includeJavascriptTests()
.onlyRun("PageLoadingTest")
.onlyRun("ImplicitWaitTest")
// .method("testFindingElementsOnElementByXPathShouldFindTopLevelElements")
.outputTestNames()
.leaveRunning()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openqa.selenium.remote.server.handler.ClearElement;
import org.openqa.selenium.remote.server.handler.ClickElement;
import org.openqa.selenium.remote.server.handler.CloseWindow;
import org.openqa.selenium.remote.server.handler.ConfigureTimeout;
import org.openqa.selenium.remote.server.handler.DeleteCookie;
import org.openqa.selenium.remote.server.handler.DeleteNamedCookie;
import org.openqa.selenium.remote.server.handler.DeleteSession;
Expand Down Expand Up @@ -374,6 +375,8 @@ private void setupMappings(DriverSessions driverSessions, Logger logger) {
postMapper.bind("/session/:sessionId/window/:windowHandle/position", SetWindowPosition.class)
.on(ResultType.SUCCESS, emptyResponse);

postMapper.bind("/session/:sessionId/timeouts", ConfigureTimeout.class)
.on(ResultType.SUCCESS, emptyResponse);
postMapper.bind("/session/:sessionId/timeouts/implicit_wait", ImplicitlyWait.class)
.on(ResultType.SUCCESS, emptyResponse);
postMapper.bind("/session/:sessionId/timeouts/async_script", SetScriptTimeout.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2012 WebDriver committers
Copyright 2012 Software Freedom Conservancy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package org.openqa.selenium.remote.server.handler;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.server.JsonParametersAware;
import org.openqa.selenium.remote.server.Session;
import org.openqa.selenium.remote.server.rest.ResultType;

import java.util.Map;
import java.util.concurrent.TimeUnit;

public class ConfigureTimeout extends WebDriverHandler implements JsonParametersAware {

private volatile String type;
private volatile long millis;

public ConfigureTimeout(Session session) {
super(session);
}

public void setJsonParameters(Map<String, Object> allParameters) throws Exception {
type = (String) allParameters.get("type");
millis = ((Number) allParameters.get("ms")).longValue();
}

public ResultType call() throws Exception {
if ("implicit".equals(type)) {
getDriver().manage().timeouts().implicitlyWait(millis, TimeUnit.MILLISECONDS);
} else if ("script".equals(type)) {
getDriver().manage().timeouts().setScriptTimeout(millis, TimeUnit.MILLISECONDS);
} else {
throw new WebDriverException("Unknown wait type: " + type);
}
return ResultType.SUCCESS;
}

@Override
public String toString() {
return String.format("[implicitly wait: %s]", millis);
}
}
3 changes: 3 additions & 0 deletions javascript/firefox-driver/extension/components/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ Dispatcher.prototype.init_ = function() {
on(Request.Method.GET, Dispatcher.executeAs('getSpeed')).
on(Request.Method.POST, Dispatcher.executeAs('setSpeed'));

this.bind_('/session/:sessionId/timeouts').
on(Request.Method.POST, Dispatcher.executeAs('setTimeout'));

this.bind_('/session/:sessionId/timeouts/implicit_wait').
on(Request.Method.POST, Dispatcher.executeAs('implicitlyWait'));
this.bind_('/session/:sessionId/timeouts/async_script').
Expand Down
17 changes: 17 additions & 0 deletions javascript/firefox-driver/extension/components/firefoxDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,23 @@ FirefoxDriver.prototype.deleteAllCookies = function(respond) {
};


FirefoxDriver.prototype.setTimeout = function(respond, parameters) {
switch (parameters.type) {
case 'implicit':
respond.session.setImplicitWait(parameters.ms);
break;

case 'script':
respond.session.setScriptTimeout(parameters.ms);
break;

default:
break;
}
respond.send();
};


FirefoxDriver.prototype.implicitlyWait = function(respond, parameters) {
respond.session.setImplicitWait(parameters.ms);
respond.send();
Expand Down
14 changes: 14 additions & 0 deletions wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,20 @@ def main():
'[#Actual_Capabilities capabilities].').
Delete('Delete the session.'))

resources.append(
SessionResource('/session/:sessionId/timeouts').
Post('''
Configure the amount of time that a particular type of operation can execute \
for before they are aborted and a |Timeout| error is returned to the \
client.''').
AddJsonParameter('type', '{string}',
'The type of operation to set the timeout for. Valid \
values are: "script" for script timeouts and "implicit" for modifying the \
implicit wait timeout.').
AddJsonParameter('ms', '{number}',
'The amount of time, in milliseconds, that time-limited'
' commands are permitted to run.'))

resources.append(
SessionResource('/session/:sessionId/timeouts/async_script').
Post('''Set the amount of time, in milliseconds, that asynchronous \
Expand Down

0 comments on commit d2e5c39

Please sign in to comment.