Skip to content

Commit

Permalink
Rollback our work on displayed? api function
Browse files Browse the repository at this point in the history
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 clj-commons#445 for issue clj-commons#444.
  • Loading branch information
lread committed Aug 1, 2022
1 parent 964ea76 commit 033739e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ That said, for Etaoin users who have adopted and prefer the api2 versions, they
This will allow for easier testing of unreleased versions of Etaoin via git deps.
It also unconvered that our minimum Clojure version was 1.10, instead of the advertised v1.9.
Fixed.
* https://github.com/clj-commons/etaoin/issues/444[#444]: Visibility checks fixed for firefox and chrome (thanks https://github.com/daveyarwood[@daveyarwood]!)
* https://github.com/clj-commons/etaoin/issues/455[#455]: Automatically create specified parent dirs for screenshots
* https://github.com/clj-commons/etaoin/issues/469[#469]: Include WebDriver process liveness in http client exception
* https://github.com/clj-commons/etaoin/issues/446[#446]: Bump Etaoin dependencies to current releases
Expand Down
3 changes: 1 addition & 2 deletions env/test/resources/html/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ <h3>Select section</h3>
<option value="rf">Russia</option>
<option value="usa">United States</option>
<option value="uk">United Kingdom</option>
<option id="option-visible" value="fr">France</option>
<option id="option-hidden" style="display: none" value="nowhere">Nowhere</option>
<option value="fr">France</option>
</select>
<label for="cars">Choose a car:</label>
<select name="cars" id="cars" multiple>
Expand Down
30 changes: 18 additions & 12 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2289,28 +2289,34 @@
:arglists '([driver q & more])}
absent? (complement exists?))

;; TODO: I think we might have broken this! @lread
(defn- effectively-displayed?
[driver el]
{:pre [(some? el)]}
(and (not= "none" (get-element-css-el driver el :display))
(not= "hidden" (get-element-css-el driver el :visibility))))

(defmulti displayed-el?
"Return true if `driver` finds `el` is effectively displayed/visible.
"Return true if `driver` finds `el` is displayed/visible.
See [[query]] for details on `q`.
Rather than checking the browser native `displayed` implementation, which
isn't 100% reliable, we are taking a pragmatic approach by checking the
`display` and `visibility` CSS properties."
Note: Safari webdriver has not implemented `displayed`, for it
we currently default to some naive CSS display/visibilty checks."
{:arglists '([driver el])}
dispatch-driver)

(defmethod displayed-el? :default
[driver el]
{:pre [(some? el)]}
(effectively-displayed? driver el))
(:value (execute {:driver driver
:method :get
:path [:session (:session driver) :element el :displayed]})))

(defmethod displayed-el? :safari
[driver el]
{:pre [(some? el)]}
(cond
(= (get-element-css-el driver el :display)
"none")
false
(= (get-element-css-el driver el :visibility)
"hidden")
false
:else true))

(defn displayed?
"Return true if element found by `driver` with query `q` is effectively displayed."
Expand Down
2 changes: 0 additions & 2 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@
(deftest test-visible
(doto *driver*
(-> (e/visible? {:id :button-visible}) is)
(-> (e/visible? {:id :option-visible}) is)
(-> (e/invisible? {:id :button-hidden}) is)
(-> (e/invisible? {:id :div-hidden}) is)
(-> (e/invisible? {:id :option-hidden}) is)
(-> (e/invisible? {:id :dunno-foo-bar}) is)))

(deftest test-select
Expand Down

0 comments on commit 033739e

Please sign in to comment.