Skip to content

Commit

Permalink
Implement the w3c timeouts command
Browse files Browse the repository at this point in the history
Well, not quite, because "page load" isn't valid, but you
get the idea.
  • Loading branch information
shs96c committed Mar 16, 2017
1 parent c7d36d9 commit 441bf30
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -833,22 +833,19 @@ protected class RemoteTimeouts implements Timeouts {

public Timeouts implicitlyWait(long time, TimeUnit unit) {
execute(DriverCommand.SET_TIMEOUT, ImmutableMap.of(
"type", "implicit",
"ms", TimeUnit.MILLISECONDS.convert(time, unit)));
"implicit", 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)));
"script", TimeUnit.MILLISECONDS.convert(time, unit)));
return this;
}

public Timeouts pageLoadTimeout(long time, TimeUnit unit) {
execute(DriverCommand.SET_TIMEOUT, ImmutableMap.of(
"type", "page load",
"ms", TimeUnit.MILLISECONDS.convert(time, unit)));
"page load", TimeUnit.MILLISECONDS.convert(time, unit)));
return this;
}
} // timeouts class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.InvalidArgumentException;
import org.openqa.selenium.remote.DriverCommand;

import java.util.Map;
Expand Down Expand Up @@ -147,6 +148,18 @@ public JsonHttpCommandCodec() {
.put("handle", "current")
.build();

case DriverCommand.SET_TIMEOUT:
if (parameters.size() != 1) {
throw new InvalidArgumentException(
"The JSON wire protocol only supports setting one time out at a time");
}
Map.Entry<String, ?> entry = parameters.entrySet().iterator().next();
String type = entry.getKey();
if ("pageLoad".equals(type)) {
type = "page load";
}
return ImmutableMap.of("type", type, "ms", entry.getValue());

case DriverCommand.SWITCH_TO_WINDOW:
return ImmutableMap.<String, Object>builder()
.put("name", parameters.get("handle"))
Expand Down
5 changes: 3 additions & 2 deletions java/client/test/org/openqa/selenium/PageLoadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public void testShouldNotHangIfDocumentOpenCallIsNeverFollowedByDocumentCloseCal
@Ignore(value = {HTMLUNIT, SAFARI, PHANTOMJS, FIREFOX},
reason = "Safari: see issue 687, comment 41; PHANTOMJS: not tested", issues = {687})
@NeedsLocalEnvironment
@NotYetImplemented(MARIONETTE)
@NoDriverAfterTest
@Test
public void testPageLoadTimeoutCanBeChanged() {
Expand Down Expand Up @@ -539,8 +540,8 @@ private void testPageLoadTimeoutIsEnforced(long webDriverPageLoadTimeout) {

long start = System.currentTimeMillis();
try {
driver
.get(appServer.whereIs("sleep?time=" + (webDriverPageLoadTimeout + pageLoadTimeBuffer)));
driver.get(appServer.whereIs(
"sleep?time=" + (webDriverPageLoadTimeout + pageLoadTimeBuffer)));
fail("I should have timed out after " + webDriverPageLoadTimeout + " seconds");
} catch (RuntimeException e) {
long end = System.currentTimeMillis();
Expand Down

0 comments on commit 441bf30

Please sign in to comment.