Skip to content

Commit b7c316f

Browse files
committed
Use an atom for isDisplayed when driving a W3C remote end.
Because the spec doesn't include this as a valid end point.
1 parent d729f32 commit b7c316f

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

java/client/src/org/openqa/selenium/remote/BUCK

+7
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ java_library(name = 'remote-lib',
117117
]),
118118
resources = [
119119
':get-attribute',
120+
':is-displayed',
120121
],
121122
deps = [
122123
':api',
@@ -134,3 +135,9 @@ export_file(
134135
src = '//javascript/webdriver/atoms:getAttribute',
135136
out = 'getAttribute.js',
136137
)
138+
139+
export_file(
140+
name = 'is-displayed',
141+
src = '//javascript/atoms/fragments:is-displayed',
142+
out = 'isDisplayed.js',
143+
)

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

-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
import static org.openqa.selenium.remote.DriverCommand.IME_IS_ACTIVATED;
8282
import static org.openqa.selenium.remote.DriverCommand.IMPLICITLY_WAIT;
8383
import static org.openqa.selenium.remote.DriverCommand.IS_BROWSER_ONLINE;
84-
import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_DISPLAYED;
8584
import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_ENABLED;
8685
import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_SELECTED;
8786
import static org.openqa.selenium.remote.DriverCommand.MOUSE_DOWN;
@@ -197,7 +196,6 @@ public AbstractHttpCommandCodec() {
197196
defineCommand(
198197
GET_ELEMENT_VALUE_OF_CSS_PROPERTY,
199198
get("/session/:sessionId/element/:id/css/:propertyName"));
200-
defineCommand(IS_ELEMENT_DISPLAYED, get("/session/:sessionId/element/:id/displayed"));
201199
defineCommand(FIND_CHILD_ELEMENT, post("/session/:sessionId/element/:id/element"));
202200
defineCommand(FIND_CHILD_ELEMENTS, post("/session/:sessionId/element/:id/elements"));
203201
defineCommand(IS_ELEMENT_ENABLED, get("/session/:sessionId/element/:id/enabled"));

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

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW;
3030
import static org.openqa.selenium.remote.DriverCommand.GET_PAGE_SOURCE;
3131
import static org.openqa.selenium.remote.DriverCommand.GET_WINDOW_HANDLES;
32+
import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_DISPLAYED;
3233
import static org.openqa.selenium.remote.DriverCommand.MAXIMIZE_CURRENT_WINDOW;
3334
import static org.openqa.selenium.remote.DriverCommand.SET_ALERT_VALUE;
3435
import static org.openqa.selenium.remote.DriverCommand.SET_CURRENT_WINDOW_POSITION;
@@ -52,6 +53,7 @@ public class JsonHttpCommandCodec extends AbstractHttpCommandCodec {
5253
public JsonHttpCommandCodec() {
5354
defineCommand(GET_ELEMENT_ATTRIBUTE, get("/session/:sessionId/element/:id/attribute/:name"));
5455
defineCommand(GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW, get("/session/:sessionId/element/:id/location_in_view"));
56+
defineCommand(IS_ELEMENT_DISPLAYED, get("/session/:sessionId/element/:id/displayed"));
5557
defineCommand(SUBMIT_ELEMENT, post("/session/:sessionId/element/:id/submit"));
5658

5759
defineCommand(EXECUTE_SCRIPT, post("/session/:sessionId/execute"));

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

+24-12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW;
3434
import static org.openqa.selenium.remote.DriverCommand.GET_PAGE_SOURCE;
3535
import static org.openqa.selenium.remote.DriverCommand.GET_WINDOW_HANDLES;
36+
import static org.openqa.selenium.remote.DriverCommand.IS_ELEMENT_DISPLAYED;
3637
import static org.openqa.selenium.remote.DriverCommand.MAXIMIZE_CURRENT_WINDOW;
3738
import static org.openqa.selenium.remote.DriverCommand.SET_ALERT_VALUE;
3839
import static org.openqa.selenium.remote.DriverCommand.SET_CURRENT_WINDOW_POSITION;
@@ -63,6 +64,7 @@ public class W3CHttpCommandCodec extends AbstractHttpCommandCodec {
6364
public W3CHttpCommandCodec() {
6465
alias(GET_ELEMENT_ATTRIBUTE, EXECUTE_SCRIPT);
6566
alias(GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW, EXECUTE_SCRIPT);
67+
alias(IS_ELEMENT_DISPLAYED, EXECUTE_SCRIPT);
6668
alias(SUBMIT_ELEMENT, EXECUTE_SCRIPT);
6769

6870
defineCommand(EXECUTE_SCRIPT, post("/session/:sessionId/execute/sync"));
@@ -134,18 +136,10 @@ public W3CHttpCommandCodec() {
134136

135137
case GET_ELEMENT_ATTRIBUTE:
136138
// Read the atom, wrap it, execute it.
137-
try {
138-
String scriptName = "/org/openqa/selenium/remote/getAttribute.js";
139-
URL url = getClass().getResource(scriptName);
140-
141-
String rawFunction = Resources.toString(url, Charsets.UTF_8);
142-
String script = String.format(
143-
"return (%s).apply(null, arguments);",
144-
rawFunction);
145-
return toScript(script, asElement(parameters.get("id")), parameters.get("name"));
146-
} catch (IOException | NullPointerException e) {
147-
throw new WebDriverException(e);
148-
}
139+
return executeAtom(
140+
"getAttribute.js",
141+
asElement(parameters.get("id")),
142+
parameters.get("name"));
149143

150144
case GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW:
151145
return toScript(
@@ -161,6 +155,9 @@ public W3CHttpCommandCodec() {
161155
case GET_CURRENT_WINDOW_POSITION:
162156
return toScript("return {x: window.screenX, y: window.screenY}");
163157

158+
case IS_ELEMENT_DISPLAYED:
159+
return executeAtom("isDisplayed.js", asElement(parameters.get("id")));
160+
164161
case SET_CURRENT_WINDOW_POSITION:
165162
return toScript(
166163
"window.screenX = arguments[0]; window.screenY = arguments[1]",
@@ -184,6 +181,21 @@ public W3CHttpCommandCodec() {
184181
}
185182
}
186183

184+
private Map<String, ?> executeAtom(String atomFileName, Object... args) {
185+
try {
186+
String scriptName = "/org/openqa/selenium/remote/" + atomFileName;
187+
URL url = getClass().getResource(scriptName);
188+
189+
String rawFunction = Resources.toString(url, Charsets.UTF_8);
190+
String script = String.format(
191+
"return (%s).apply(null, arguments);",
192+
rawFunction);
193+
return toScript(script, args);
194+
} catch (IOException | NullPointerException e) {
195+
throw new WebDriverException(e);
196+
}
197+
}
198+
187199
private Map<String, ?> toScript(String script, Object... args) {
188200
// Escape the quote marks
189201
script = script.replaceAll("\"", "\\\"");

javascript/atoms/fragments/BUCK

+10
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ js_fragment(name = 'execute_script',
1717
],
1818
)
1919

20+
js_fragment(name = 'is-displayed',
21+
function = 'bot.dom.isShown',
22+
module = 'bot.dom',
23+
deps = [
24+
'//javascript/atoms:dom',
25+
],
26+
visibility = [
27+
'//java/client/src/org/openqa/selenium/remote:is-displayed',
28+
],
29+
)

0 commit comments

Comments
 (0)