Skip to content

Commit

Permalink
Handle the timeout commands in the W3C codec
Browse files Browse the repository at this point in the history
Almost, but not quite, what was in the JSON wire protocol.
  • Loading branch information
shs96c committed Oct 12, 2016
1 parent b5dd949 commit 3c808f6
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static org.openqa.selenium.remote.DriverCommand.SET_ALERT_VALUE;
import static org.openqa.selenium.remote.DriverCommand.SET_CURRENT_WINDOW_POSITION;
import static org.openqa.selenium.remote.DriverCommand.SET_CURRENT_WINDOW_SIZE;
import static org.openqa.selenium.remote.DriverCommand.SET_TIMEOUT;
import static org.openqa.selenium.remote.DriverCommand.SUBMIT_ELEMENT;

import com.google.common.base.Charsets;
Expand Down Expand Up @@ -199,13 +200,31 @@ public W3CHttpCommandCodec() {
parameters.get("x"),
parameters.get("y"));

case SET_TIMEOUT:
String timeoutType = (String) parameters.get("type");
Number duration = (Number) parameters.get("ms");

if (timeoutType == null) {
// Assume a local end that Knows What To Do according to the spec
return parameters;
}

return ImmutableMap.<String, Object>builder()
.putAll(
parameters.entrySet().stream()
.filter(e -> !timeoutType.equals(e.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
.put(timeoutType, duration)
.build();

case SUBMIT_ELEMENT:
return toScript(
"var form = arguments[0];\n" +
"while (form.nodeName != \"FORM\" && form.parentNode) {\n" +
" form = form.parentNode;\n" +
"}\n" +
"if (form == null) { throw Error('Unable to find containing form element'); }\n" +
"if (!form) { throw Error('Unable to find containing form element'); }\n" +
"if (!form.ownerDocument) { throw Error('Unable to find owning document'); }\n" +
"var e = form.ownerDocument.createEvent('Event');\n" +
"e.initEvent('submit', true, true);\n" +
"if (form.dispatchEvent(e)) { form.submit() }\n",
Expand Down

0 comments on commit 3c808f6

Please sign in to comment.