Skip to content

Commit

Permalink
add select fn (#241)
Browse files Browse the repository at this point in the history
* add select fn
  • Loading branch information
Uunnamed authored Jul 22, 2020
1 parent 2d26401 commit c72a784
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions resources/html/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ <h3>Input section</h3>
<label>Password</label>
<input id="simple-password"
name="password" type="password"><br>
<select id="simple-country">
<option value="rf">Russia</option>
<option value="usa">United States</option>
<option value="uk">United Kingdom</option>
<option value="fr">France</option>
</select>
<label>Message</label>
<textarea id="simple-textarea"
name="message"></textarea><br>
Expand Down
14 changes: 14 additions & 0 deletions src/etaoin/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,20 @@
[driver q text]
(fill-human-el driver (query driver q) text))

(defn select
"Select element in select-box by visible text on click.
Arguments:
- `driver`: a driver instance,
- `q`: a query term, see `query` function for more info,
- `text`: a string to input."
[driver q text]
(let [el (query driver q {:tag :option :fn/has-text text})]
(click-el driver el)))

(defn clear-el
"Clears an element by its identifier."
[driver el]
Expand Down
8 changes: 8 additions & 0 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
(-> (invisible? {:id :div-hidden}) is)
(-> (invisible? {:id :dunno-foo-bar}) is)))

(deftest test-select
(testing "test `select` on select-box"
(let [default-val (get-element-value *driver* :simple-country)
_ (select *driver* :simple-country "France")
selected-val (get-element-value *driver* :simple-country)]
(is (= "rf" default-val))
(is (= "fr" selected-val)))))

(deftest test-input
(testing "fill multiple imputs"
(doto *driver*
Expand Down

0 comments on commit c72a784

Please sign in to comment.