From 56b8f579d7bd63fe845ec074c2d73f29cbee81f2 Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Mon, 19 Aug 2024 20:30:51 -0500 Subject: [PATCH 1/2] Implement fill-active-human (#629) --- CHANGELOG.adoc | 1 + src/etaoin/api.clj | 10 +++++++++- test/etaoin/api_test.clj | 14 +++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index ff7b78d..eca8667 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -22,6 +22,7 @@ A release with an intentional breaking changes is marked with: * Changes ** {issue}559[#559]: Create `query-from` and `query-all-from` as replacements for `child` and `children`. Rewrite logic such that `q` parameter allows for vector syntax similar to `query` and `query-all`. Deprecate `child` and `children`. ({person}dgr[@dgr]) ** {issue}559[#559]: Make `get-active-element` a public API. This was previously private. ({person}dgr[@dgr]) +** {issue}629[#629]: Added `fill-active-human` as a convenience function that fills the currently active input using `fill-human-el`. ({person}dgr[@dgr]) * Docs ** {issue}559[#559]: Deprecate use of `:active` with `query` and other APIs that use `query` under the hood. ({person}dgr[@dgr]) diff --git a/src/etaoin/api.clj b/src/etaoin/api.clj index 581deff..32f974f 100644 --- a/src/etaoin/api.clj +++ b/src/etaoin/api.clj @@ -56,7 +56,7 @@ **Inputs/Forms** - [[fill]] [[fill-active]] [[fill-el]] [[fill-multi]] - - [[fill-human]] [[fill-human-el]] [[fill-human-multi]] + - [[fill-human]] [[fill-active-human]] [[fill-human-el]] [[fill-human-multi]] - [[select]] [[selected?]] [[selected-el?]] - [[upload-file]] [[remote-file]] - [[disabled?]] [[enabled?]] @@ -2787,6 +2787,14 @@ ([driver q text opts] (fill-human-el driver (query driver q) text opts))) +(defn fill-active-human + "Fills the currently active element with `text` as if it were a real + human using `opts`. This is a simple convience function wrapped + around `get-active-element` and `fill-human-el`." + ([driver text] (fill-active-human driver text {})) + ([driver text opts] + (fill-human-el driver (get-active-element driver) text opts))) + (defn fill-human-multi "Have `driver` fill multiple elements as if it were a real human being via `q-text` using `opts`. diff --git a/test/etaoin/api_test.clj b/test/etaoin/api_test.clj index 719a6f7..2cfef51 100644 --- a/test/etaoin/api_test.clj +++ b/test/etaoin/api_test.clj @@ -187,7 +187,19 @@ (e/when-safari (e/wait 3)) (-> e/get-url (str/ends-with? "?login=1test2+A&password=&message=") - is)))) + is))) + (testing "fill active human" + (doto *driver* + (e/click :simple-input) + (e/fill-active-human "MyLogin2") + (e/click :simple-password) + (e/fill-active-human "MyPassword2") + (e/click :simple-textarea) + (e/fill-active "Some text 2") + (e/click :simple-submit) + (e/when-safari (e/wait 3))) + (is (str/ends-with? (e/get-url *driver*) + "?login=MyLogin2&password=MyPassword2&message=Some+text+2")))) (deftest test-unicode-bmp-input (let [data {:simple-input "ĩṋṗṵţ" From d22d7768768af0236136fce09e01a5f2e9d5e9d2 Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Mon, 19 Aug 2024 20:55:10 -0500 Subject: [PATCH 2/2] Update textarea field fill to use fill-active-human --- test/etaoin/api_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/etaoin/api_test.clj b/test/etaoin/api_test.clj index 2cfef51..fcfa439 100644 --- a/test/etaoin/api_test.clj +++ b/test/etaoin/api_test.clj @@ -195,7 +195,7 @@ (e/click :simple-password) (e/fill-active-human "MyPassword2") (e/click :simple-textarea) - (e/fill-active "Some text 2") + (e/fill-active-human "Some text 2") (e/click :simple-submit) (e/when-safari (e/wait 3))) (is (str/ends-with? (e/get-url *driver*)