Skip to content

Commit 578e375

Browse files
authored
Rollback our work on displayed? api function (#487)
We have learned that displayed-ness is more complex than we had originally imagined. It requires more research and maybe more hammock time. Effectively rolls back PR #445 for issue #444.
1 parent 964ea76 commit 578e375

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

CHANGELOG.adoc

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ That said, for Etaoin users who have adopted and prefer the api2 versions, they
112112
This will allow for easier testing of unreleased versions of Etaoin via git deps.
113113
It also unconvered that our minimum Clojure version was 1.10, instead of the advertised v1.9.
114114
Fixed.
115-
* https://github.com/clj-commons/etaoin/issues/444[#444]: Visibility checks fixed for firefox and chrome (thanks https://github.com/daveyarwood[@daveyarwood]!)
116115
* https://github.com/clj-commons/etaoin/issues/455[#455]: Automatically create specified parent dirs for screenshots
117116
* https://github.com/clj-commons/etaoin/issues/469[#469]: Include WebDriver process liveness in http client exception
118117
* https://github.com/clj-commons/etaoin/issues/446[#446]: Bump Etaoin dependencies to current releases

env/test/resources/html/test.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ <h3>Select section</h3>
5050
<option value="rf">Russia</option>
5151
<option value="usa">United States</option>
5252
<option value="uk">United Kingdom</option>
53-
<option id="option-visible" value="fr">France</option>
54-
<option id="option-hidden" style="display: none" value="nowhere">Nowhere</option>
53+
<option value="fr">France</option>
5554
</select>
5655
<label for="cars">Choose a car:</label>
5756
<select name="cars" id="cars" multiple>

src/etaoin/api.clj

+18-12
Original file line numberDiff line numberDiff line change
@@ -2289,28 +2289,34 @@
22892289
:arglists '([driver q & more])}
22902290
absent? (complement exists?))
22912291

2292-
;; TODO: I think we might have broken this! @lread
2293-
(defn- effectively-displayed?
2294-
[driver el]
2295-
{:pre [(some? el)]}
2296-
(and (not= "none" (get-element-css-el driver el :display))
2297-
(not= "hidden" (get-element-css-el driver el :visibility))))
2298-
22992292
(defmulti displayed-el?
2300-
"Return true if `driver` finds `el` is effectively displayed/visible.
2293+
"Return true if `driver` finds `el` is displayed/visible.
23012294
23022295
See [[query]] for details on `q`.
23032296
2304-
Rather than checking the browser native `displayed` implementation, which
2305-
isn't 100% reliable, we are taking a pragmatic approach by checking the
2306-
`display` and `visibility` CSS properties."
2297+
Note: Safari webdriver has not implemented `displayed`, for it
2298+
we currently default to some naive CSS display/visibilty checks."
23072299
{:arglists '([driver el])}
23082300
dispatch-driver)
23092301

23102302
(defmethod displayed-el? :default
23112303
[driver el]
23122304
{:pre [(some? el)]}
2313-
(effectively-displayed? driver el))
2305+
(:value (execute {:driver driver
2306+
:method :get
2307+
:path [:session (:session driver) :element el :displayed]})))
2308+
2309+
(defmethod displayed-el? :safari
2310+
[driver el]
2311+
{:pre [(some? el)]}
2312+
(cond
2313+
(= (get-element-css-el driver el :display)
2314+
"none")
2315+
false
2316+
(= (get-element-css-el driver el :visibility)
2317+
"hidden")
2318+
false
2319+
:else true))
23142320

23152321
(defn displayed?
23162322
"Return true if element found by `driver` with query `q` is effectively displayed."

test/etaoin/api_test.clj

-2
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@
7676
(deftest test-visible
7777
(doto *driver*
7878
(-> (e/visible? {:id :button-visible}) is)
79-
(-> (e/visible? {:id :option-visible}) is)
8079
(-> (e/invisible? {:id :button-hidden}) is)
8180
(-> (e/invisible? {:id :div-hidden}) is)
82-
(-> (e/invisible? {:id :option-hidden}) is)
8381
(-> (e/invisible? {:id :dunno-foo-bar}) is)))
8482

8583
(deftest test-select

0 commit comments

Comments
 (0)