Skip to content

Commit dadde61

Browse files
committed
Simulating window.getPosition and setPosition operations
1 parent e2b3b6b commit dadde61

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -859,9 +859,14 @@ public void setSize(Dimension targetSize) {
859859
}
860860

861861
public void setPosition(Point targetPosition) {
862-
execute(DriverCommand.SET_WINDOW_POSITION,
863-
ImmutableMap
864-
.of("windowHandle", "current", "x", targetPosition.x, "y", targetPosition.y));
862+
if (getW3CStandardComplianceLevel() == 0) {
863+
execute(DriverCommand.SET_WINDOW_POSITION,
864+
ImmutableMap
865+
.of("windowHandle", "current", "x", targetPosition.x, "y", targetPosition.y));
866+
} else {
867+
executeScript("window.screenX = arguments[0]; window.screenY = arguments[1]",
868+
targetPosition.x, targetPosition.y);
869+
}
865870
}
866871

867872
@SuppressWarnings({"unchecked"})
@@ -879,10 +884,16 @@ public Dimension getSize() {
879884
}
880885

881886
@SuppressWarnings({"unchecked"})
887+
Map<String, Object> rawPoint;
882888
public Point getPosition() {
883-
Response response = execute(DriverCommand.GET_WINDOW_POSITION,
884-
ImmutableMap.of("windowHandle", "current"));
885-
Map<String, Object> rawPoint = (Map<String, Object>) response.getValue();
889+
if (getW3CStandardComplianceLevel() == 0) {
890+
Response response = execute(DriverCommand.GET_WINDOW_POSITION,
891+
ImmutableMap.of("windowHandle", "current"));
892+
rawPoint = (Map<String, Object>) response.getValue();
893+
} else {
894+
rawPoint = (Map<String, Object>) executeScript(
895+
"return {x: window.screenX, y: window.screenY}");
896+
}
886897

887898
int x = ((Number) rawPoint.get("x")).intValue();
888899
int y = ((Number) rawPoint.get("y")).intValue();

java/client/test/org/openqa/selenium/WindowTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import static org.junit.Assume.assumeFalse;
2525
import static org.openqa.selenium.Platform.ANDROID;
2626
import static org.openqa.selenium.Platform.LINUX;
27-
import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE;
2827
import static org.openqa.selenium.testing.Ignore.Driver.PHANTOMJS;
2928
import static org.openqa.selenium.testing.Ignore.Driver.SAFARI;
3029

@@ -96,7 +95,6 @@ public void testSetsTheSizeOfTheCurrentWindowFromIframe() {
9695
}
9796

9897
@Test
99-
@Ignore(MARIONETTE)
10098
public void testGetsThePositionOfTheCurrentWindow() {
10199
// Window position is undefined on ANDROID (and most mobile platforms
102100
// though others aren't defined in org.openqa.selenium.Platform).
@@ -108,7 +106,7 @@ public void testGetsThePositionOfTheCurrentWindow() {
108106
}
109107

110108
@Test
111-
@Ignore(value = {SAFARI, PHANTOMJS, MARIONETTE},
109+
@Ignore(value = {SAFARI, PHANTOMJS},
112110
reason = "Safari: getPosition after setPosition doesn't match up exactly, " +
113111
"as expected - probably due to nuances in Mac OSX window manager.")
114112
public void testSetsThePositionOfTheCurrentWindow() throws InterruptedException {

0 commit comments

Comments
 (0)