From 5e9ac64ea2d3971b27c7e6f26fb40b8662de6507 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 15:59:49 +0200 Subject: [PATCH 01/41] Add safari driver --- splinter/driver/webdriver/remote.py | 8 ++++++++ splinter/driver/webdriver/setup.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/splinter/driver/webdriver/remote.py b/splinter/driver/webdriver/remote.py index a0971a763..82015dd8f 100644 --- a/splinter/driver/webdriver/remote.py +++ b/splinter/driver/webdriver/remote.py @@ -13,6 +13,7 @@ from splinter.driver.webdriver.setup import _setup_chrome from splinter.driver.webdriver.setup import _setup_edge from splinter.driver.webdriver.setup import _setup_firefox +from splinter.driver.webdriver.setup import _setup_safari # MonkeyPatch RemoteConnection remote_connection.RemoteConnection._request = patch_request # type: ignore @@ -64,5 +65,12 @@ def __init__( options = options or Options() driver = _setup_firefox(Remote, self.config, options, **kwargs) + elif browser_name == "SAFARI": + from selenium.webdriver.safari.options import Options + + options = options or Options() + driver = _setup_safari(Remote, self.config, options, **kwargs) + else: + raise ValueError(f"Unsupporeted browser {browser_name}") super().__init__(driver, wait_time) diff --git a/splinter/driver/webdriver/setup.py b/splinter/driver/webdriver/setup.py index aa720ffa2..e6b0ad00d 100644 --- a/splinter/driver/webdriver/setup.py +++ b/splinter/driver/webdriver/setup.py @@ -93,3 +93,15 @@ def _setup_firefox(driver_class, config=None, options=None, service=None, **kwar rv.fullscreen_window() return rv + + +def _setup_safari(driver_class, config=None, options=None, service=None, **kwargs): + """ + Returns: selenium.webdriver.Safari || selenium.webdriver.Remote + """ + if driver_class == Remote: + rv = driver_class(options=options, **kwargs) + else: + rv = driver_class(options=options, service=service, **kwargs) + + return rv From 248412a7a639327ac6abcc75114b081056e619d1 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:18 +0200 Subject: [PATCH 02/41] Add test for Safari remote --- tests/test_webdriver_remote.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index 12f835dfa..81a27337c 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -57,3 +57,22 @@ def test_support_with_statement(self): def test_should_be_able_to_change_user_agent(self): "Remote should not support custom user agent" pass + + +class RemoteBrowserSafariTest(WebDriverTests, unittest.TestCase): + @pytest.fixture(autouse=True, scope="class") + def setup_browser(self, request): + request.cls.browser = Browser("remote", browser="safari") + request.addfinalizer(request.cls.browser.quit) + + def setUp(self): + self.browser.visit(EXAMPLE_APP) + + def test_support_with_statement(self): + "Remote should support with statement" + with Browser("remote"): + pass + + def test_should_be_able_to_change_user_agent(self): + "Remote should not support custom user agent" + pass From 8066ed1de7f461f15eb24a247a90e6115e92e6df Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:20 +0200 Subject: [PATCH 03/41] Add MacOS CI --- .github/workflows/macos.yml | 56 ++++++++++++++++++++++++++++++++++ tests/test_webdriver_remote.py | 1 + tox.ini | 7 +++++ 3 files changed, 64 insertions(+) create mode 100644 .github/workflows/macos.yml diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 000000000..b894fcab4 --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,56 @@ +name: CI-MacOS + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + selenium: + runs-on: macos-latest + + strategy: + matrix: + include: + - PY_VER: py38 + python-version: 3.8 + - PY_VER: py39 + python-version: 3.9 + - PY_VER: py310 + python-version: "3.10" + - PY_VER: py311 + python-version: 3.11 + - PY_VER: py312 + python-version: "3.12" + + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v4 + with: + python-version: ${{matrix.python-version}} + + - name: Install test dependencies + run: pip install tox + + - name: Download Selenium Server + run: | + wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.1.jar -O selenium-server.jar + + - name: Enable Safari Webdriver + run: safaridriver --enable + + - name: Setup node + run: java -jar selenium-server-4.16.1.jar node -I "safari" & + + - name: Setup hub + run: java -jar selenium-server-4.16.1.jar hub & + + - name: Run tests for windows-only drivers + run: | + tox -e tests_macos_selenium -- -m macos -n 1 tests/test_webdriver_remote.py; diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index 81a27337c..95f6def64 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -59,6 +59,7 @@ def test_should_be_able_to_change_user_agent(self): pass +@pytest.mark.macos class RemoteBrowserSafariTest(WebDriverTests, unittest.TestCase): @pytest.fixture(autouse=True, scope="class") def setup_browser(self, request): diff --git a/tox.ini b/tox.ini index 73668aeee..8e3335d22 100644 --- a/tox.ini +++ b/tox.ini @@ -21,3 +21,10 @@ passenv = EDGEWEBDRIVER commands= pytest --ignore-flaky -v {posargs} + +[testenv:tests_macos_selenium] +extras = selenium +deps = + -rrequirements/test.txt +commands= + pytest --ignore-flaky -v {posargs} From 8e9951d207c41f153892e051657481ca7a4aecad Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:21 +0200 Subject: [PATCH 04/41] Add more params for safari --- .github/workflows/macos.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index b894fcab4..e9aa72f7b 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -43,7 +43,10 @@ jobs: wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.1.jar -O selenium-server.jar - name: Enable Safari Webdriver - run: safaridriver --enable + run: | + defaults write com.apple.Safari IncludeDevelopMenu YES + defaults write com.apple.Safari AllowRemoteAutomation 1 + sudo safaridriver --enable - name: Setup node run: java -jar selenium-server-4.16.1.jar node -I "safari" & From 62c02ad70a3d942f00756cf012eacab430eac3fe Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:21 +0200 Subject: [PATCH 05/41] Change order of hub and node --- .github/workflows/macos.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index e9aa72f7b..0af2663e4 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -48,12 +48,12 @@ jobs: defaults write com.apple.Safari AllowRemoteAutomation 1 sudo safaridriver --enable - - name: Setup node - run: java -jar selenium-server-4.16.1.jar node -I "safari" & - - name: Setup hub run: java -jar selenium-server-4.16.1.jar hub & - - name: Run tests for windows-only drivers + - name: Setup node + run: java -jar selenium-server-4.16.1.jar node -I "safari" & + + - name: Run tests for macos run: | tox -e tests_macos_selenium -- -m macos -n 1 tests/test_webdriver_remote.py; From 95336136f61a22c68599d897bbb54fd09f467b2a Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:22 +0200 Subject: [PATCH 06/41] Add wait for selenium hub up for macos --- .github/workflows/macos.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 0af2663e4..985fb62d1 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -56,4 +56,6 @@ jobs: - name: Run tests for macos run: | + timeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-server.log && exit 2) + tox -e tests_macos_selenium -- -m macos -n 1 tests/test_webdriver_remote.py; From fb8ff1214f885b5af93345cf7bd006de200d1eff Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:23 +0200 Subject: [PATCH 07/41] Add logs for hub and node --- .github/workflows/macos.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 985fb62d1..a5e56868a 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -49,13 +49,13 @@ jobs: sudo safaridriver --enable - name: Setup hub - run: java -jar selenium-server-4.16.1.jar hub & + run: java -jar selenium-server-4.16.1.jar hub > selenium-hub.log 2>&1 & - name: Setup node - run: java -jar selenium-server-4.16.1.jar node -I "safari" & + run: java -jar selenium-server-4.16.1.jar node -I "safari" > selenium-node.log 2>&1 & - name: Run tests for macos run: | - timeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-server.log && exit 2) + timeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-hub.log selenium-node.log && exit 2) tox -e tests_macos_selenium -- -m macos -n 1 tests/test_webdriver_remote.py; From 0c2ba23014cf6e9b1ced21ebf26ebd37150a1940 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:24 +0200 Subject: [PATCH 08/41] Fix selenium filename --- .github/workflows/macos.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index a5e56868a..ecf1dda0e 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -38,21 +38,21 @@ jobs: - name: Install test dependencies run: pip install tox - - name: Download Selenium Server - run: | - wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.1.jar -O selenium-server.jar - - name: Enable Safari Webdriver run: | defaults write com.apple.Safari IncludeDevelopMenu YES defaults write com.apple.Safari AllowRemoteAutomation 1 sudo safaridriver --enable + - name: Download Selenium Server + run: | + wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.1.jar -O selenium-server.jar + - name: Setup hub - run: java -jar selenium-server-4.16.1.jar hub > selenium-hub.log 2>&1 & + run: java -jar selenium-server.jar hub > selenium-hub.log 2>&1 & - name: Setup node - run: java -jar selenium-server-4.16.1.jar node -I "safari" > selenium-node.log 2>&1 & + run: java -jar selenium-server.jar node -I "safari" > selenium-node.log 2>&1 & - name: Run tests for macos run: | From 7efb3c4aec772dcecf3b54876e6d87b17ef72523 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:25 +0200 Subject: [PATCH 09/41] Add timeout util for mac --- .github/workflows/macos.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index ecf1dda0e..0b0d20e05 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -54,8 +54,11 @@ jobs: - name: Setup node run: java -jar selenium-server.jar node -I "safari" > selenium-node.log 2>&1 & + - name: Install timeout util + run: brew install coreutils + - name: Run tests for macos run: | - timeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-hub.log selenium-node.log && exit 2) + gtimeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-hub.log selenium-node.log && exit 2) tox -e tests_macos_selenium -- -m macos -n 1 tests/test_webdriver_remote.py; From 8cd953924db9bab242820ae6ca3eff71e21c586e Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:26 +0200 Subject: [PATCH 10/41] Install java for macos --- .github/workflows/macos.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 0b0d20e05..8785c6563 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -44,6 +44,9 @@ jobs: defaults write com.apple.Safari AllowRemoteAutomation 1 sudo safaridriver --enable + - name: Install timeout util and java + run: brew install coreutils java + - name: Download Selenium Server run: | wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.1.jar -O selenium-server.jar @@ -54,8 +57,6 @@ jobs: - name: Setup node run: java -jar selenium-server.jar node -I "safari" > selenium-node.log 2>&1 & - - name: Install timeout util - run: brew install coreutils - name: Run tests for macos run: | From 7c81575f0ecbd14e07dfb23b4c66a4d4541d6365 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:27 +0200 Subject: [PATCH 11/41] Debug java version --- .github/workflows/macos.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 8785c6563..9dfb7487e 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -45,7 +45,9 @@ jobs: sudo safaridriver --enable - name: Install timeout util and java - run: brew install coreutils java + run: | + brew install coreutils java + java --version - name: Download Selenium Server run: | From e3558d9e0f9108c1d4f470f99c2de75b4cf05073 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:28 +0200 Subject: [PATCH 12/41] Check java version other way --- .github/workflows/macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 9dfb7487e..b5837dfea 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -47,7 +47,7 @@ jobs: - name: Install timeout util and java run: | brew install coreutils java - java --version + java -version - name: Download Selenium Server run: | From 0943c82589aca677e73a48727f9a51baa0a4a5bc Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:30 +0200 Subject: [PATCH 13/41] Other way of java installation --- .github/workflows/macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index b5837dfea..c4cf764a5 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -46,7 +46,7 @@ jobs: - name: Install timeout util and java run: | - brew install coreutils java + brew install coreutils openjdk java -version - name: Download Selenium Server From 5c0885d42c2e47e802084e24e573c79ebdf1f030 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:30 +0200 Subject: [PATCH 14/41] Try to reinstall java --- .github/workflows/macos.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index c4cf764a5..94471b273 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -46,7 +46,9 @@ jobs: - name: Install timeout util and java run: | - brew install coreutils openjdk + brew update && brew upgrade + brew install coreutils + brew reinstall java openjdk java -version - name: Download Selenium Server From 259b3f44f273984b898c2d556797d631f7f4518d Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:31 +0200 Subject: [PATCH 15/41] Try to install java11 --- .github/workflows/macos.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 94471b273..b112b39b4 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -46,10 +46,11 @@ jobs: - name: Install timeout util and java run: | - brew update && brew upgrade brew install coreutils - brew reinstall java openjdk + brew search java + brew install java11 java -version + ls -la /opt/homebrew/Cellar/ - name: Download Selenium Server run: | From 1997be9792ca68f47092a0b8d383d20723bab80f Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:32 +0200 Subject: [PATCH 16/41] Try to run with java 11 --- .github/workflows/macos.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index b112b39b4..d0775c282 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -47,20 +47,17 @@ jobs: - name: Install timeout util and java run: | brew install coreutils - brew search java brew install java11 - java -version - ls -la /opt/homebrew/Cellar/ - name: Download Selenium Server run: | wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.1.jar -O selenium-server.jar - name: Setup hub - run: java -jar selenium-server.jar hub > selenium-hub.log 2>&1 & + run: /usr/local/opt/openjdk@11/bin/java -jar selenium-server.jar hub > selenium-hub.log 2>&1 & - name: Setup node - run: java -jar selenium-server.jar node -I "safari" > selenium-node.log 2>&1 & + run: /usr/local/opt/openjdk@11/bin/java -jar selenium-server.jar node -I "safari" > selenium-node.log 2>&1 & - name: Run tests for macos From 7162484ebb51d4465a399a94b7b9500465e4e604 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:33 +0200 Subject: [PATCH 17/41] Rewrite all tests requested for new browser for safari --- .github/workflows/macos.yml | 9 ++-- tests/test_webdriver_remote.py | 97 ++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 6 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index d0775c282..b060432bd 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -53,15 +53,12 @@ jobs: run: | wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.16.0/selenium-server-4.16.1.jar -O selenium-server.jar - - name: Setup hub - run: /usr/local/opt/openjdk@11/bin/java -jar selenium-server.jar hub > selenium-hub.log 2>&1 & - - - name: Setup node - run: /usr/local/opt/openjdk@11/bin/java -jar selenium-server.jar node -I "safari" > selenium-node.log 2>&1 & + - name: Setup standalone + run: /usr/local/opt/openjdk@11/bin/java -jar selenium-server.jar standalone -I 'safari' > selenium-standalone.log 2>&1 & - name: Run tests for macos run: | - gtimeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-hub.log selenium-node.log && exit 2) + gtimeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-standalone.log && exit 2) tox -e tests_macos_selenium -- -m macos -n 1 tests/test_webdriver_remote.py; diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index 95f6def64..a88867965 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -77,3 +77,100 @@ def test_support_with_statement(self): def test_should_be_able_to_change_user_agent(self): "Remote should not support custom user agent" pass + + # Safari doesn't support multisessions. + # So next test must be rewrited without getting new browser + def test_can_forward_on_history(self): + next_url = f"{EXAMPLE_APP}iframe" + + self.browser.visit(EXAMPLE_APP) + self.browser.visit(next_url) + self.browser.back() + + self.browser.forward() + assert next_url == self.browser.url + + def test_create_and_access_a_cookie(self): + """Should be able to create and access a cookie""" + self.browser.visit(self.EXAMPLE_APP) + + self.browser.cookies.add({"sha": "zam"}) + + assert "zam" == self.browser.cookies["sha"] + + def test_create_many_cookies_at_once_as_dict(self): + """Should be able to create many cookies at once as dict""" + self.browser.visit(self.EXAMPLE_APP) + + cookies = {"sha": "zam", "foo": "bar"} + self.browser.cookies.add(cookies) + + assert "zam" == self.browser.cookies["sha"] + assert "bar" == self.browser.cookies["foo"] + + def test_create_some_cookies_and_delete_them_all(self): + """Should be able to delete all cookies""" + self.browser.visit(self.EXAMPLE_APP) + + self.browser.cookies.add({"whatever": "and ever"}) + self.browser.cookies.add({"anothercookie": "im bored"}) + self.browser.cookies.delete_all() + + assert {} == self.browser.cookies + + def test_create_and_delete_a_cookie(self): + """Should be able to create and destroy a cookie""" + self.browser.visit(self.EXAMPLE_APP) + + self.browser.cookies.delete_all() + self.browser.cookies.add({"cookie": "with milk"}) + self.browser.cookies.delete("cookie") + + assert {} == self.browser.cookies + + def test_create_and_delete_many_cookies(self): + """Should be able to create and destroy many cookies""" + self.browser.visit(self.EXAMPLE_APP) + + self.browser.cookies.delete_all() + self.browser.cookies.add({"acookie": "cooked"}) + self.browser.cookies.add({"anothercookie": "uncooked"}) + self.browser.cookies.add({"notacookie": "halfcooked"}) + self.browser.cookies.delete("acookie", "notacookie") + + assert "uncooked" == self.browser.cookies["anothercookie"] + + def test_try_to_destroy_an_absent_cookie_and_nothing_happens(self): + self.browser.visit(self.EXAMPLE_APP) + + self.browser.cookies.delete_all() + self.browser.cookies.add({"foo": "bar"}) + self.browser.cookies.delete("mwahahahaha") + + {"foo": "bar"} == self.browser.cookies + + def test_create_and_get_all_cookies(self): + """Should be able to create some cookies and retrieve them all""" + + self.browser.visit(self.EXAMPLE_APP) + + self.browser.cookies.delete_all() + self.browser.cookies.add({"taco": "shrimp"}) + self.browser.cookies.add({"lavar": "burton"}) + + assert 2 == len(self.browser.cookies.all()) + + self.browser.cookies.delete_all() + + assert {} == self.browser.cookies.all() + + def test_create_and_use_contains(self): + """Should be able to create many cookies at once as dict""" + + self.browser.visit(self.EXAMPLE_APP) + + cookies = {"sha": "zam"} + self.browser.cookies.add(cookies) + + assert "sha" in self.browser.cookies + assert "foo" not in self.browser.cookies From cb1f6596c9b7fd36f766e35aed7da7cacbaa23de Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:35 +0200 Subject: [PATCH 18/41] Patch multisession tests instead of rewriting --- tests/test_webdriver_remote.py | 101 ++++++++------------------------- 1 file changed, 25 insertions(+), 76 deletions(-) diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index a88867965..25819e6c9 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -3,6 +3,7 @@ # license that can be found in the LICENSE file. import unittest from urllib.request import urlopen +from unittest.mock import patch import pytest @@ -78,99 +79,47 @@ def test_should_be_able_to_change_user_agent(self): "Remote should not support custom user agent" pass + # ------- BEGIN OF MULTISESSION TESTS ------- # Safari doesn't support multisessions. - # So next test must be rewrited without getting new browser - def test_can_forward_on_history(self): - next_url = f"{EXAMPLE_APP}iframe" - - self.browser.visit(EXAMPLE_APP) - self.browser.visit(next_url) - self.browser.back() + # So next tests mock quit of browser. + def get_new_browser(self): + return self.browser - self.browser.forward() - assert next_url == self.browser.url + def test_can_forward_on_history(self): + with patch("splinter.driver.webdriver.remote.WebDriver.quit"): + super().test_can_forward_on_history() def test_create_and_access_a_cookie(self): - """Should be able to create and access a cookie""" - self.browser.visit(self.EXAMPLE_APP) - - self.browser.cookies.add({"sha": "zam"}) - - assert "zam" == self.browser.cookies["sha"] + with patch("splinter.driver.webdriver.remote.WebDriver.quit"): + super().test_create_and_access_a_cookie() def test_create_many_cookies_at_once_as_dict(self): - """Should be able to create many cookies at once as dict""" - self.browser.visit(self.EXAMPLE_APP) - - cookies = {"sha": "zam", "foo": "bar"} - self.browser.cookies.add(cookies) - - assert "zam" == self.browser.cookies["sha"] - assert "bar" == self.browser.cookies["foo"] + with patch("splinter.driver.webdriver.remote.WebDriver.quit"): + super().test_create_many_cookies_at_once_as_dict() def test_create_some_cookies_and_delete_them_all(self): - """Should be able to delete all cookies""" - self.browser.visit(self.EXAMPLE_APP) - - self.browser.cookies.add({"whatever": "and ever"}) - self.browser.cookies.add({"anothercookie": "im bored"}) - self.browser.cookies.delete_all() - - assert {} == self.browser.cookies + with patch("splinter.driver.webdriver.remote.WebDriver.quit"): + super().test_create_some_cookies_and_delete_them_all() def test_create_and_delete_a_cookie(self): - """Should be able to create and destroy a cookie""" - self.browser.visit(self.EXAMPLE_APP) - - self.browser.cookies.delete_all() - self.browser.cookies.add({"cookie": "with milk"}) - self.browser.cookies.delete("cookie") - - assert {} == self.browser.cookies + with patch("splinter.driver.webdriver.remote.WebDriver.quit"): + super().test_create_and_delete_a_cookie() def test_create_and_delete_many_cookies(self): - """Should be able to create and destroy many cookies""" - self.browser.visit(self.EXAMPLE_APP) - - self.browser.cookies.delete_all() - self.browser.cookies.add({"acookie": "cooked"}) - self.browser.cookies.add({"anothercookie": "uncooked"}) - self.browser.cookies.add({"notacookie": "halfcooked"}) - self.browser.cookies.delete("acookie", "notacookie") - - assert "uncooked" == self.browser.cookies["anothercookie"] + with patch("splinter.driver.webdriver.remote.WebDriver.quit"): + super().test_create_and_delete_many_cookies() def test_try_to_destroy_an_absent_cookie_and_nothing_happens(self): - self.browser.visit(self.EXAMPLE_APP) - - self.browser.cookies.delete_all() - self.browser.cookies.add({"foo": "bar"}) - self.browser.cookies.delete("mwahahahaha") - - {"foo": "bar"} == self.browser.cookies + with patch("splinter.driver.webdriver.remote.WebDriver.quit"): + super().test_try_to_destroy_an_absent_cookie_and_nothing_happens() def test_create_and_get_all_cookies(self): - """Should be able to create some cookies and retrieve them all""" - - self.browser.visit(self.EXAMPLE_APP) - - self.browser.cookies.delete_all() - self.browser.cookies.add({"taco": "shrimp"}) - self.browser.cookies.add({"lavar": "burton"}) - - assert 2 == len(self.browser.cookies.all()) - - self.browser.cookies.delete_all() - - assert {} == self.browser.cookies.all() + with patch("splinter.driver.webdriver.remote.WebDriver.quit"): + super().test_create_and_get_all_cookies() def test_create_and_use_contains(self): - """Should be able to create many cookies at once as dict""" - - self.browser.visit(self.EXAMPLE_APP) + with patch("splinter.driver.webdriver.remote.WebDriver.quit"): + super().test_create_and_use_contains() - cookies = {"sha": "zam"} - self.browser.cookies.add(cookies) + # ------- END OF MULTISESSION TESTS ------- - assert "sha" in self.browser.cookies - assert "foo" not in self.browser.cookies From f02af6c1fbaca709e5e3024066bc427bb3882e07 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:36 +0200 Subject: [PATCH 19/41] Add return to main page for test --- tests/click_elements.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/click_elements.py b/tests/click_elements.py index 7365c6e05..69fadd759 100644 --- a/tests/click_elements.py +++ b/tests/click_elements.py @@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. +from .fake_webapp import EXAMPLE_APP class ClickElementsTest: def test_click_links(self): @@ -15,3 +16,4 @@ def test_click_element_by_css_selector(self): def test_click_input_by_css_selector(self): self.browser.find_by_css('input[name="send"]').click() self.assertIn("My name is: Master Splinter", self.browser.html) + self.browser.visit(EXAMPLE_APP) From 283e733a22cead21be2f41c954996cc2711c3be9 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:37 +0200 Subject: [PATCH 20/41] Check async element present on the page --- tests/is_element_present.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/is_element_present.py b/tests/is_element_present.py index f352095ec..15a8032f9 100644 --- a/tests/is_element_present.py +++ b/tests/is_element_present.py @@ -51,7 +51,7 @@ def test_is_element_present_by_xpath_returns_false_if_element_is_not_present(sel def test_is_element_not_present_by_xpath_returns_false_if_element_is_present(self): """should is_element_not_present_by_xpath returns False if element is present""" self.browser.find_by_css(".add-async-element").click() - self.browser.find_by_xpath("//h4") + assert len(self.browser.find_by_xpath("//h4")) > 0 assert not self.browser.is_element_not_present_by_xpath("//h4") def test_is_element_not_present_by_xpath_using_a_custom_wait_time(self): From f15c31c9b540a7a6f61166bad135a8081e868c4f Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:38 +0200 Subject: [PATCH 21/41] Move with statement test to setup for Safari --- tests/test_webdriver_remote.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index 25819e6c9..5eb1a0fcd 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -64,6 +64,11 @@ def test_should_be_able_to_change_user_agent(self): class RemoteBrowserSafariTest(WebDriverTests, unittest.TestCase): @pytest.fixture(autouse=True, scope="class") def setup_browser(self, request): + # test with statement. It can't be used as simple test + # because safari doesn't support multisessions + with Browser("remote", browser="safari"): + pass + request.cls.browser = Browser("remote", browser="safari") request.addfinalizer(request.cls.browser.quit) @@ -71,9 +76,10 @@ def setUp(self): self.browser.visit(EXAMPLE_APP) def test_support_with_statement(self): - "Remote should support with statement" - with Browser("remote"): - pass + """ + Remote should support with statement + See setup browser + """ def test_should_be_able_to_change_user_agent(self): "Remote should not support custom user agent" From 33dfefe5f955501318268ff387becf5de671c914 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:40 +0200 Subject: [PATCH 22/41] Add particular browser selector for remote browsers --- tests/test_webdriver_remote.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index 5eb1a0fcd..3fa27cef5 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -33,7 +33,7 @@ def setUp(self): def test_support_with_statement(self): "Remote should support with statement" - with Browser("remote"): + with Browser("remote", browser="firefox"): pass def test_should_be_able_to_change_user_agent(self): @@ -52,7 +52,7 @@ def setUp(self): def test_support_with_statement(self): "Remote should support with statement" - with Browser("remote"): + with Browser("remote", browser="chrome"): pass def test_should_be_able_to_change_user_agent(self): From e7ac7a4e62f5e0953b5bbd42c5e03af27099a26a Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:41 +0200 Subject: [PATCH 23/41] Mark click test with xfail for Safari --- tests/test_webdriver_remote.py | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index 3fa27cef5..11ad7a935 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -129,3 +129,79 @@ def test_create_and_use_contains(self): # ------- END OF MULTISESSION TESTS ------- + def test_can_fill_more_than_one_field_in_form(self): + "should provide a away to change field value" + self.browser.fill("query", "my name") + self.assertFalse(self.browser.find_by_id("gender-m").checked) + self.assertFalse(self.browser.find_option_by_value("rj").selected) + self.assertFalse(self.browser.find_by_name("some-check").checked) + self.assertTrue(self.browser.find_by_name("checked-checkbox").checked) + # Select of dropdown doesn't work for Safari 17 (remote). Safari as OS user works well + # for some reason select doesn't work for Safari + self.browser.fill_form( + { + "query": "another new query", + "description": "Just another description value in the textarea", + "gender": "M", + #"uf": "rj", + "some-check": True, + "checked-checkbox": False, + }, + ) + query_value = self.browser.find_by_name("query").value + self.assertEqual("another new query", query_value) + desc_value = self.browser.find_by_name("description").value + self.assertEqual("Just another description value in the textarea", desc_value) + self.assertTrue(self.browser.find_by_id("gender-m").checked) + #self.assertTrue(self.browser.find_option_by_value("rj").selected) + self.assertTrue(self.browser.find_by_name("some-check").checked) + self.assertFalse(self.browser.find_by_name("checked-checkbox").checked) + + # ------- BEGIN OF CLICK PROBLEM TESTS ------- + #https://stackoverflow.com/questions/77388720/automation-testing-with-selenium-click-doesnt-works-on-new-safari-17-ios-sonoma + @pytest.mark.xfail + def test_clicking_submit_button_doesnt_post_button_value_if_empty(self): + super().test_clicking_submit_button_doesnt_post_button_value_if_empty() + + @pytest.mark.xfail + def test_clicking_submit_button_doesnt_post_button_value_if_name_not_present(self): + super().test_clicking_submit_button_doesnt_post_button_value_if_name_not_present() + + @pytest.mark.xfail + def test_clicking_submit_button_posts_button_value_if_value_present(self): + super().test_clicking_submit_button_posts_button_value_if_value_present() + + @pytest.mark.xfail + def test_clicking_submit_button_posts_empty_value_if_value_not_present(self): + super().test_clicking_submit_button_posts_empty_value_if_value_not_present() + + @pytest.mark.xfail + def test_clicking_submit_input_doesnt_post_input_value_if_empty(self): + super().test_clicking_submit_input_doesnt_post_input_value_if_empty() + + @pytest.mark.xfail + def test_clicking_submit_input_doesnt_post_input_value_if_name_not_present(self): + super().test_clicking_submit_input_doesnt_post_input_value_if_name_not_present() + + @pytest.mark.xfail + def test_clicking_submit_input_posts_empty_value_if_value_not_present(self): + super().test_clicking_submit_input_posts_empty_value_if_value_not_present() + + @pytest.mark.xfail + def test_clicking_submit_input_posts_input_value_if_value_present(self): + super().test_clicking_submit_input_posts_input_value_if_value_present() + + @pytest.mark.xfail + def test_submiting_a_form_and_verifying_page_content(self): + super().test_submiting_a_form_and_verifying_page_content() + + # ------- END OF CLICK PROBLEM TESTS ------- + # ------- START OF TYPE PROBLEM TESTS ------- + @pytest.mark.xfail + def test_simple_type(self): + super().test_simple_type() + + @pytest.mark.xfail + def test_simple_type_on_element(self): + super().test_simple_type_on_element() + # ------- END OF TYPE PROBLEM TESTS ------- From ddcc252fc7c25710f9e493e4ecd9c648b10b55a7 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:42 +0200 Subject: [PATCH 24/41] Skip one more test --- tests/click_elements.py | 1 + tests/test_webdriver_remote.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/tests/click_elements.py b/tests/click_elements.py index 69fadd759..4aa4be587 100644 --- a/tests/click_elements.py +++ b/tests/click_elements.py @@ -12,6 +12,7 @@ def test_click_links(self): def test_click_element_by_css_selector(self): self.browser.find_by_css('a[href="http://localhost:5000/foo"]').click() self.assertIn("BAR!", self.browser.html) + self.browser.visit(EXAMPLE_APP) def test_click_input_by_css_selector(self): self.browser.find_by_css('input[name="send"]').click() diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index 11ad7a935..f8c027a4b 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -159,6 +159,11 @@ def test_can_fill_more_than_one_field_in_form(self): # ------- BEGIN OF CLICK PROBLEM TESTS ------- #https://stackoverflow.com/questions/77388720/automation-testing-with-selenium-click-doesnt-works-on-new-safari-17-ios-sonoma + + @pytest.mark.xfail + def test_click_input_by_css_selector(self): + super().test_click_input_by_css_selector() + @pytest.mark.xfail def test_clicking_submit_button_doesnt_post_button_value_if_empty(self): super().test_clicking_submit_button_doesnt_post_button_value_if_empty() From 890acb22cfd9f2913b92cfa016e51db742a783f9 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:43 +0200 Subject: [PATCH 25/41] Add return to main page --- tests/click_elements.py | 1 + tests/form_elements.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/click_elements.py b/tests/click_elements.py index 4aa4be587..6482a1042 100644 --- a/tests/click_elements.py +++ b/tests/click_elements.py @@ -8,6 +8,7 @@ class ClickElementsTest: def test_click_links(self): self.browser.links.find_by_text("FOO").click() self.assertIn("BAR!", self.browser.html) + self.browser.visit(EXAMPLE_APP) def test_click_element_by_css_selector(self): self.browser.find_by_css('a[href="http://localhost:5000/foo"]').click() diff --git a/tests/form_elements.py b/tests/form_elements.py index 6df3630bb..c0357e771 100644 --- a/tests/form_elements.py +++ b/tests/form_elements.py @@ -108,6 +108,7 @@ def test_submiting_a_form_and_verifying_page_content(self): self.browser.fill("query", "my name") self.browser.find_by_name("send").click() self.assertIn("My name is: Master Splinter", self.browser.html) + self.browser.visit(EXAMPLE_APP) def test_can_choose_a_radio_button(self): "should provide a way to choose a radio button" From 271edd77652975c22ab55156d8ef3c2158416f01 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:44 +0200 Subject: [PATCH 26/41] xfail one more click --- tests/test_webdriver_remote.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index f8c027a4b..f1ff9210c 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -159,6 +159,9 @@ def test_can_fill_more_than_one_field_in_form(self): # ------- BEGIN OF CLICK PROBLEM TESTS ------- #https://stackoverflow.com/questions/77388720/automation-testing-with-selenium-click-doesnt-works-on-new-safari-17-ios-sonoma + @pytest.mark.xfail + def test_click_element_by_css_selector(self): + super().test_click_element_by_css_selector() @pytest.mark.xfail def test_click_input_by_css_selector(self): From b9277680f489e31780c5fe4a7d29495b46efa091 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:44 +0200 Subject: [PATCH 27/41] Add missed import --- tests/form_elements.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/form_elements.py b/tests/form_elements.py index c0357e771..da342b0e3 100644 --- a/tests/form_elements.py +++ b/tests/form_elements.py @@ -8,6 +8,7 @@ import pytest from splinter.exceptions import ElementDoesNotExist +from .fake_webapp import EXAMPLE_APP def skip_if_zope(f): From 460d14d25a4f7780343349a37eda008b2d886473 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:45 +0200 Subject: [PATCH 28/41] Fix formatting --- tests/click_elements.py | 2 +- tests/form_elements.py | 2 +- tests/test_webdriver_remote.py | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/click_elements.py b/tests/click_elements.py index 6482a1042..41f265cdd 100644 --- a/tests/click_elements.py +++ b/tests/click_elements.py @@ -1,9 +1,9 @@ # Copyright 2012 splinter authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. - from .fake_webapp import EXAMPLE_APP + class ClickElementsTest: def test_click_links(self): self.browser.links.find_by_text("FOO").click() diff --git a/tests/form_elements.py b/tests/form_elements.py index da342b0e3..b7986c960 100644 --- a/tests/form_elements.py +++ b/tests/form_elements.py @@ -7,8 +7,8 @@ import pytest -from splinter.exceptions import ElementDoesNotExist from .fake_webapp import EXAMPLE_APP +from splinter.exceptions import ElementDoesNotExist def skip_if_zope(f): diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index f1ff9210c..775df9207 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -2,8 +2,8 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. import unittest -from urllib.request import urlopen from unittest.mock import patch +from urllib.request import urlopen import pytest @@ -143,7 +143,7 @@ def test_can_fill_more_than_one_field_in_form(self): "query": "another new query", "description": "Just another description value in the textarea", "gender": "M", - #"uf": "rj", + # "uf": "rj", "some-check": True, "checked-checkbox": False, }, @@ -153,12 +153,12 @@ def test_can_fill_more_than_one_field_in_form(self): desc_value = self.browser.find_by_name("description").value self.assertEqual("Just another description value in the textarea", desc_value) self.assertTrue(self.browser.find_by_id("gender-m").checked) - #self.assertTrue(self.browser.find_option_by_value("rj").selected) + # self.assertTrue(self.browser.find_option_by_value("rj").selected) self.assertTrue(self.browser.find_by_name("some-check").checked) self.assertFalse(self.browser.find_by_name("checked-checkbox").checked) # ------- BEGIN OF CLICK PROBLEM TESTS ------- - #https://stackoverflow.com/questions/77388720/automation-testing-with-selenium-click-doesnt-works-on-new-safari-17-ios-sonoma + # https://stackoverflow.com/questions/77388720/automation-testing-with-selenium-click-doesnt-works-on-new-safari-17-ios-sonoma @pytest.mark.xfail def test_click_element_by_css_selector(self): super().test_click_element_by_css_selector() @@ -212,4 +212,5 @@ def test_simple_type(self): @pytest.mark.xfail def test_simple_type_on_element(self): super().test_simple_type_on_element() + # ------- END OF TYPE PROBLEM TESTS ------- From 4102746689fd6003de0cefc5ee2c0c9bb5eca224 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:46 +0200 Subject: [PATCH 29/41] Add macos filter for tox --- .github/workflows/macos.yml | 2 +- tox.ini | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index b060432bd..26a810219 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -61,4 +61,4 @@ jobs: run: | gtimeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-standalone.log && exit 2) - tox -e tests_macos_selenium -- -m macos -n 1 tests/test_webdriver_remote.py; + tox -e tests_macos_selenium -- -n 1 tests/test_webdriver_remote.py; diff --git a/tox.ini b/tox.ini index 8e3335d22..6d168fe66 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ extras = selenium deps = -rrequirements/test.txt commands= - pytest --ignore-flaky -v {posargs} + pytest --ignore-flaky -m "not macos" -v {posargs} [testenv:tests_windows_selenium] @@ -27,4 +27,4 @@ extras = selenium deps = -rrequirements/test.txt commands= - pytest --ignore-flaky -v {posargs} + pytest --ignore-flaky -m macos -v {posargs} From a6d5091675fa9c95e7fa98c1f20a87471e48ccb8 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:47 +0200 Subject: [PATCH 30/41] Add pytest markers --- pytest.ini | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..1c51692a0 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +markers = + macos: tests can be runned only on MacOS (Safari) From d6c8607d4ce0ea6a6e99f644c2bb553a53d1f06b Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:48 +0200 Subject: [PATCH 31/41] Set parallel to 1 for macos to avoid new tab problem --- .github/workflows/macos.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 26a810219..35b5c701e 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -14,6 +14,7 @@ jobs: runs-on: macos-latest strategy: + max-parallel: 1 matrix: include: - PY_VER: py38 From d267b21acd04fa03a2c6f0ab6a6ece10776f58a1 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:49 +0200 Subject: [PATCH 32/41] Try to limit parallel jobs --- .github/workflows/macos.yml | 1 + .github/workflows/main.yml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 35b5c701e..275503b23 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -14,6 +14,7 @@ jobs: runs-on: macos-latest strategy: + # Safari has some problem with tabs max-parallel: 1 matrix: include: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0e3741107..fc631e819 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,6 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: + max-parallel: 3 matrix: include: - PY_VER: py38 @@ -55,6 +56,7 @@ jobs: runs-on: ubuntu-latest strategy: + max-parallel: 3 matrix: include: - PY_VER: py38 @@ -97,6 +99,7 @@ jobs: runs-on: ubuntu-latest strategy: + max-parallel: 3 matrix: include: - PY_VER: py38 From 5ae8aad941aa53a20baa2d296c550135a7dd57cf Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:50 +0200 Subject: [PATCH 33/41] Make explicit visit of main page for tab test --- tests/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/base.py b/tests/base.py index 17be49de7..2511f43dc 100644 --- a/tests/base.py +++ b/tests/base.py @@ -140,6 +140,7 @@ def test_status_code(self): def test_can_open_page_in_new_tab(self): """should be able to visit url in a new tab""" + self.browser.visit(EXAMPLE_APP) self.browser.windows.current.new_tab(EXAMPLE_APP) self.browser.windows[1].is_current = True self.assertEqual(EXAMPLE_APP, self.browser.url) From 4c7d84aa6d9d8b6cdd2f3ca64a4a596965f68d8c Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 21 Dec 2023 16:00:53 +0200 Subject: [PATCH 34/41] Add test click to xfail --- tests/test_webdriver_remote.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index 775df9207..31b5372cc 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -203,6 +203,10 @@ def test_clicking_submit_input_posts_input_value_if_value_present(self): def test_submiting_a_form_and_verifying_page_content(self): super().test_submiting_a_form_and_verifying_page_content() + @pytest.mark.xfail + def test_click_links(self): + super().test_click_links() + # ------- END OF CLICK PROBLEM TESTS ------- # ------- START OF TYPE PROBLEM TESTS ------- @pytest.mark.xfail From 465cea3f543b6a5c3bedba3e1d22b1be200c3ee9 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 28 Dec 2023 14:15:57 +0200 Subject: [PATCH 35/41] Try to rerun failed tests --- .github/workflows/macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 275503b23..6ef3f0dde 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -63,4 +63,4 @@ jobs: run: | gtimeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-standalone.log && exit 2) - tox -e tests_macos_selenium -- -n 1 tests/test_webdriver_remote.py; + tox -e tests_macos_selenium -- -n 1 tests || tox -e tests_macos_selenium -- -n 1 --lf From 16c1a941c2c8ff82462679df754c9deb6511d0cd Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 28 Dec 2023 15:13:05 +0200 Subject: [PATCH 36/41] Try to rerun less failed tests --- .github/workflows/macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 6ef3f0dde..0628758ba 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -63,4 +63,4 @@ jobs: run: | gtimeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-standalone.log && exit 2) - tox -e tests_macos_selenium -- -n 1 tests || tox -e tests_macos_selenium -- -n 1 --lf + tox -e tests_macos_selenium -- -n 1 tests || tox -e tests_macos_selenium -- -n 1 --last-failed --last-failed-no-failures none From d786f49d53c2ba51a87ee1bdee7dc8f7fec33576 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 28 Dec 2023 15:39:38 +0200 Subject: [PATCH 37/41] Clear cache before test run --- .github/workflows/macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 0628758ba..9d2d670ba 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -63,4 +63,4 @@ jobs: run: | gtimeout 60 bash -c 'while ! wget -O /dev/null -T 1 http://localhost:4444/readyz; do echo waiting for selenium server; sleep 1; done' || (cat selenium-standalone.log && exit 2) - tox -e tests_macos_selenium -- -n 1 tests || tox -e tests_macos_selenium -- -n 1 --last-failed --last-failed-no-failures none + tox -e tests_macos_selenium -- --cache-clear -n 1 tests || tox -e tests_macos_selenium -- -n 1 --last-failed --last-failed-no-failures none From e74197457733eab2674191bcf1efb24b15e64fd2 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Thu, 28 Dec 2023 15:47:49 +0200 Subject: [PATCH 38/41] Run google search only if called directly --- samples/test_google_search.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/test_google_search.py b/samples/test_google_search.py index e35367c57..46d4fa7f4 100755 --- a/samples/test_google_search.py +++ b/samples/test_google_search.py @@ -32,4 +32,5 @@ def test_filling_splinter_in_the_search_box_returns_splinter_website(self): self.assertTrue(self.browser.is_text_present("https://splinter.readthedocs.io")) -unittest.main() +if __name__ == "__main__": + unittest.main() From ea8e35185a6bd88bcbccf47435249369bb294b16 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Fri, 29 Dec 2023 12:53:13 +0200 Subject: [PATCH 39/41] Remove visit of main page in start of tests --- tests/base.py | 1 - tests/click_elements.py | 4 ---- tests/form_elements.py | 2 -- 3 files changed, 7 deletions(-) diff --git a/tests/base.py b/tests/base.py index 2511f43dc..17be49de7 100644 --- a/tests/base.py +++ b/tests/base.py @@ -140,7 +140,6 @@ def test_status_code(self): def test_can_open_page_in_new_tab(self): """should be able to visit url in a new tab""" - self.browser.visit(EXAMPLE_APP) self.browser.windows.current.new_tab(EXAMPLE_APP) self.browser.windows[1].is_current = True self.assertEqual(EXAMPLE_APP, self.browser.url) diff --git a/tests/click_elements.py b/tests/click_elements.py index 41f265cdd..7365c6e05 100644 --- a/tests/click_elements.py +++ b/tests/click_elements.py @@ -1,21 +1,17 @@ # Copyright 2012 splinter authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -from .fake_webapp import EXAMPLE_APP class ClickElementsTest: def test_click_links(self): self.browser.links.find_by_text("FOO").click() self.assertIn("BAR!", self.browser.html) - self.browser.visit(EXAMPLE_APP) def test_click_element_by_css_selector(self): self.browser.find_by_css('a[href="http://localhost:5000/foo"]').click() self.assertIn("BAR!", self.browser.html) - self.browser.visit(EXAMPLE_APP) def test_click_input_by_css_selector(self): self.browser.find_by_css('input[name="send"]').click() self.assertIn("My name is: Master Splinter", self.browser.html) - self.browser.visit(EXAMPLE_APP) diff --git a/tests/form_elements.py b/tests/form_elements.py index b7986c960..6df3630bb 100644 --- a/tests/form_elements.py +++ b/tests/form_elements.py @@ -7,7 +7,6 @@ import pytest -from .fake_webapp import EXAMPLE_APP from splinter.exceptions import ElementDoesNotExist @@ -109,7 +108,6 @@ def test_submiting_a_form_and_verifying_page_content(self): self.browser.fill("query", "my name") self.browser.find_by_name("send").click() self.assertIn("My name is: Master Splinter", self.browser.html) - self.browser.visit(EXAMPLE_APP) def test_can_choose_a_radio_button(self): "should provide a way to choose a radio button" From 6e077e5f165dda0c708fd58dd37789dd0c077bc6 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Fri, 29 Dec 2023 12:54:03 +0200 Subject: [PATCH 40/41] Add reason of skipping for user agent --- tests/test_webdriver_remote.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index 31b5372cc..b2640c1cc 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -36,8 +36,8 @@ def test_support_with_statement(self): with Browser("remote", browser="firefox"): pass + @pytest.mark.skip(reason="Remote should not support custom user agent") def test_should_be_able_to_change_user_agent(self): - "Remote should not support custom user agent" pass @@ -55,8 +55,8 @@ def test_support_with_statement(self): with Browser("remote", browser="chrome"): pass + @pytest.mark.skip(reason="Remote should not support custom user agent") def test_should_be_able_to_change_user_agent(self): - "Remote should not support custom user agent" pass @@ -81,8 +81,8 @@ def test_support_with_statement(self): See setup browser """ + @pytest.mark.skip(reason="Remote should not support custom user agent") def test_should_be_able_to_change_user_agent(self): - "Remote should not support custom user agent" pass # ------- BEGIN OF MULTISESSION TESTS ------- From 345bdf66f1185b58af89d771184eab857dbc45d2 Mon Sep 17 00:00:00 2001 From: Andmedoctopus Date: Fri, 29 Dec 2023 13:01:13 +0200 Subject: [PATCH 41/41] Remove all matrix limits --- .github/workflows/macos.yml | 2 -- .github/workflows/main.yml | 3 --- 2 files changed, 5 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 9d2d670ba..34fe4d044 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -14,8 +14,6 @@ jobs: runs-on: macos-latest strategy: - # Safari has some problem with tabs - max-parallel: 1 matrix: include: - PY_VER: py38 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fc631e819..0e3741107 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,6 @@ jobs: runs-on: ubuntu-latest strategy: - max-parallel: 3 matrix: include: - PY_VER: py38 @@ -56,7 +55,6 @@ jobs: runs-on: ubuntu-latest strategy: - max-parallel: 3 matrix: include: - PY_VER: py38 @@ -99,7 +97,6 @@ jobs: runs-on: ubuntu-latest strategy: - max-parallel: 3 matrix: include: - PY_VER: py38