Skip to content

Commit b37476f

Browse files
committed
Normalise handling of remaining methods in RemoteWebDriver
1 parent 11798fe commit b37476f

File tree

6 files changed

+39
-31
lines changed

6 files changed

+39
-31
lines changed

java/client/src/org/openqa/selenium/remote/DriverCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public interface DriverCommand {
159159

160160
// Window API
161161
String SET_CURRENT_WINDOW_POSITION = "setWindowPosition";
162-
String GET_WINDOW_POSITION = "getWindowPosition";
162+
String GET_CURRENT_WINDOW_POSITION = "getWindowPosition";
163163

164164
// W3C compatible Window API
165165
String SET_CURRENT_WINDOW_SIZE = "setCurrentWindowSize";

java/client/src/org/openqa/selenium/remote/RemoteWebDriver.java

+4-19
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,7 @@ public List<WebElement> findElementsByXPath(String using) {
490490
// Misc
491491

492492
public String getPageSource() {
493-
if (getW3CStandardComplianceLevel() == 0) {
494-
return (String) execute(DriverCommand.GET_PAGE_SOURCE).getValue();
495-
}
496-
String script = "var source = document.documentElement.outerHTML; \n"
497-
+ "if (!source) { source = new XMLSerializer().serializeToString(document); }\n"
498-
+ "return source;";
499-
return (String) executeScript(script);
493+
return (String) execute(DriverCommand.GET_PAGE_SOURCE).getValue();
500494
}
501495

502496
public void close() {
@@ -879,14 +873,9 @@ public Dimension getSize() {
879873
@SuppressWarnings({"unchecked"})
880874
Map<String, Object> rawPoint;
881875
public Point getPosition() {
882-
if (getW3CStandardComplianceLevel() == 0) {
883-
Response response = execute(DriverCommand.GET_WINDOW_POSITION,
884-
ImmutableMap.of("windowHandle", "current"));
885-
rawPoint = (Map<String, Object>) response.getValue();
886-
} else {
887-
rawPoint = (Map<String, Object>) executeScript(
888-
"return {x: window.screenX, y: window.screenY}");
889-
}
876+
Response response = execute(DriverCommand.GET_CURRENT_WINDOW_POSITION,
877+
ImmutableMap.of("windowHandle", "current"));
878+
rawPoint = (Map<String, Object>) response.getValue();
890879

891880
int x = ((Number) rawPoint.get("x")).intValue();
892881
int y = ((Number) rawPoint.get("y")).intValue();
@@ -960,10 +949,6 @@ public WebDriver parentFrame() {
960949
}
961950

962951
public WebDriver window(String windowHandleOrName) {
963-
if (getW3CStandardComplianceLevel() == 0) {
964-
execute(DriverCommand.SWITCH_TO_WINDOW, ImmutableMap.of("name", windowHandleOrName));
965-
return RemoteWebDriver.this;
966-
}
967952
try {
968953
execute(DriverCommand.SWITCH_TO_WINDOW, ImmutableMap.of("handle", windowHandleOrName));
969954
return RemoteWebDriver.this;

java/client/src/org/openqa/selenium/remote/http/AbstractHttpCommandCodec.java

-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public AbstractHttpCommandCodec() {
7878
defineCommand(CLOSE, delete("/session/:sessionId/window"));
7979
defineCommand(SWITCH_TO_WINDOW, post("/session/:sessionId/window"));
8080

81-
defineCommand(GET_WINDOW_POSITION, get("/session/:sessionId/window/:windowHandle/position"));
8281
defineCommand(FULLSCREEN_CURRENT_WINDOW, post("/session/:sessionId/window/fullscreen"));
8382

8483
defineCommand(GET_CURRENT_URL, get("/session/:sessionId/url"));
@@ -92,7 +91,6 @@ public AbstractHttpCommandCodec() {
9291
defineCommand(UPLOAD_FILE, post("/session/:sessionId/file"));
9392
defineCommand(SCREENSHOT, get("/session/:sessionId/screenshot"));
9493
defineCommand(ELEMENT_SCREENSHOT, get("/session/:sessionId/screenshot/:id"));
95-
defineCommand(GET_PAGE_SOURCE, get("/session/:sessionId/source"));
9694
defineCommand(GET_TITLE, get("/session/:sessionId/title"));
9795

9896
defineCommand(FIND_ELEMENT, post("/session/:sessionId/element"));

java/client/src/org/openqa/selenium/remote/http/JsonHttpCommandCodec.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT;
2424
import static org.openqa.selenium.remote.DriverCommand.GET_ALERT_TEXT;
2525
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_WINDOW_HANDLE;
26+
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_WINDOW_POSITION;
2627
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_WINDOW_SIZE;
28+
import static org.openqa.selenium.remote.DriverCommand.GET_PAGE_SOURCE;
2729
import static org.openqa.selenium.remote.DriverCommand.GET_WINDOW_HANDLES;
2830
import static org.openqa.selenium.remote.DriverCommand.MAXIMIZE_CURRENT_WINDOW;
2931
import static org.openqa.selenium.remote.DriverCommand.SET_ALERT_VALUE;
@@ -45,20 +47,24 @@
4547
public class JsonHttpCommandCodec extends AbstractHttpCommandCodec {
4648

4749
public JsonHttpCommandCodec() {
48-
defineCommand(GET_WINDOW_HANDLES, get("/session/:sessionId/window_handles"));
50+
51+
defineCommand(EXECUTE_SCRIPT, post("/session/:sessionId/execute"));
52+
defineCommand(EXECUTE_ASYNC_SCRIPT, post("/session/:sessionId/execute_async"));
53+
54+
defineCommand(GET_PAGE_SOURCE, get("/session/:sessionId/source"));
55+
4956
defineCommand(MAXIMIZE_CURRENT_WINDOW, post("/session/:sessionId/window/:windowHandle/maximize"));
57+
defineCommand(GET_CURRENT_WINDOW_POSITION, get("/session/:sessionId/window/:windowHandle/position"));
5058
defineCommand(SET_CURRENT_WINDOW_POSITION, post("/session/:sessionId/window/:windowHandle/position"));
5159
defineCommand(GET_CURRENT_WINDOW_SIZE, get("/session/:sessionId/window/:windowHandle/size"));
5260
defineCommand(SET_CURRENT_WINDOW_SIZE, post("/session/:sessionId/window/:windowHandle/size"));
5361
defineCommand(GET_CURRENT_WINDOW_HANDLE, get("/session/:sessionId/window_handle"));
62+
defineCommand(GET_WINDOW_HANDLES, get("/session/:sessionId/window_handles"));
5463

5564
defineCommand(ACCEPT_ALERT, post("/session/:sessionId/accept_alert"));
5665
defineCommand(DISMISS_ALERT, post("/session/:sessionId/dismiss_alert"));
5766
defineCommand(GET_ALERT_TEXT, get("/session/:sessionId/alert_text"));
5867
defineCommand(SET_ALERT_VALUE, post("/session/:sessionId/alert_text"));
59-
60-
defineCommand(EXECUTE_SCRIPT, post("/session/:sessionId/execute"));
61-
defineCommand(EXECUTE_ASYNC_SCRIPT, post("/session/:sessionId/execute_async"));
6268
}
6369

6470
@Override
@@ -74,6 +80,11 @@ public JsonHttpCommandCodec() {
7480
.put("handle", "current")
7581
.build();
7682

83+
case DriverCommand.SWITCH_TO_WINDOW:
84+
return ImmutableMap.<String, Object>builder()
85+
.put("name", parameters.get("handle"))
86+
.build();
87+
7788
default:
7889
return parameters;
7990
}

java/client/src/org/openqa/selenium/remote/http/W3CHttpCommandCodec.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT;
2424
import static org.openqa.selenium.remote.DriverCommand.GET_ALERT_TEXT;
2525
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_WINDOW_HANDLE;
26+
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_WINDOW_POSITION;
2627
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_WINDOW_SIZE;
28+
import static org.openqa.selenium.remote.DriverCommand.GET_PAGE_SOURCE;
2729
import static org.openqa.selenium.remote.DriverCommand.GET_WINDOW_HANDLES;
2830
import static org.openqa.selenium.remote.DriverCommand.MAXIMIZE_CURRENT_WINDOW;
2931
import static org.openqa.selenium.remote.DriverCommand.SET_ALERT_VALUE;
@@ -49,20 +51,23 @@ public class W3CHttpCommandCodec extends AbstractHttpCommandCodec {
4951

5052
public W3CHttpCommandCodec() {
5153

52-
defineCommand(GET_WINDOW_HANDLES, get("/session/:sessionId/window/handles"));
54+
defineCommand(EXECUTE_SCRIPT, post("/session/:sessionId/execute/sync"));
55+
defineCommand(EXECUTE_ASYNC_SCRIPT, post("/session/:sessionId/execute/async"));
56+
57+
defineCommand(GET_PAGE_SOURCE, post("/session/:sessionId/execute/sync"));
58+
5359
defineCommand(MAXIMIZE_CURRENT_WINDOW, post("/session/:sessionId/window/maximize"));
60+
defineCommand(GET_CURRENT_WINDOW_POSITION, get("/session/:sessionId/execute/sync"));
5461
defineCommand(SET_CURRENT_WINDOW_POSITION, post("/session/:sessionId/execute/sync"));
5562
defineCommand(GET_CURRENT_WINDOW_SIZE, get("/session/:sessionId/window/size"));
5663
defineCommand(SET_CURRENT_WINDOW_SIZE, post("/session/:sessionId/window/size"));
5764
defineCommand(GET_CURRENT_WINDOW_HANDLE, get("/session/:sessionId/window"));
65+
defineCommand(GET_WINDOW_HANDLES, get("/session/:sessionId/window/handles"));
5866

5967
defineCommand(ACCEPT_ALERT, post("/session/:sessionId/alert/accept"));
6068
defineCommand(DISMISS_ALERT, post("/session/:sessionId/alert/dismiss"));
6169
defineCommand(GET_ALERT_TEXT, get("/session/:sessionId/alert/text"));
6270
defineCommand(SET_ALERT_VALUE, post("/session/:sessionId/alert/text"));
63-
64-
defineCommand(EXECUTE_SCRIPT, post("/session/:sessionId/execute/sync"));
65-
defineCommand(EXECUTE_ASYNC_SCRIPT, post("/session/:sessionId/execute/async"));
6671
}
6772

6873
@Override
@@ -114,6 +119,15 @@ public W3CHttpCommandCodec() {
114119
return toReturn;
115120

116121

122+
case GET_PAGE_SOURCE:
123+
return toScript(
124+
"var source = document.documentElement.outerHTML; \n" +
125+
"if (!source) { source = new XMLSerializer().serializeToString(document); }\n" +
126+
"return source;");
127+
128+
case DriverCommand.GET_CURRENT_WINDOW_POSITION:
129+
return toScript("return {x: window.screenX, y: window.screenY}");
130+
117131
case DriverCommand.SET_CURRENT_WINDOW_POSITION:
118132
return toScript(
119133
"window.screenX = arguments[0]; window.screenY = arguments[1]",

java/server/src/org/openqa/selenium/remote/server/JsonHttpCommandHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ private void setUpMappings() {
266266

267267
addNewMapping(GET_CURRENT_WINDOW_SIZE, GetWindowSize.class);
268268
addNewMapping(SET_CURRENT_WINDOW_SIZE, SetWindowSize.class);
269-
addNewMapping(GET_WINDOW_POSITION, GetWindowPosition.class);
269+
addNewMapping(GET_CURRENT_WINDOW_POSITION, GetWindowPosition.class);
270270
addNewMapping(SET_CURRENT_WINDOW_POSITION, SetWindowPosition.class);
271271
addNewMapping(MAXIMIZE_CURRENT_WINDOW, MaximizeWindow.class);
272272
addNewMapping(FULLSCREEN_CURRENT_WINDOW, FullscreenWindow.class);

0 commit comments

Comments
 (0)