From 99525af178c0e50c4d85aa259fb9192b3b2bc31b Mon Sep 17 00:00:00 2001 From: delta456 Date: Fri, 1 Nov 2024 17:19:27 +0530 Subject: [PATCH 1/5] [py]: add safari service tests --- py/test/selenium/webdriver/safari/__init__.py | 16 ++++++ .../webdriver/safari/safari_service_tests.py | 54 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 py/test/selenium/webdriver/safari/__init__.py create mode 100644 py/test/selenium/webdriver/safari/safari_service_tests.py diff --git a/py/test/selenium/webdriver/safari/__init__.py b/py/test/selenium/webdriver/safari/__init__.py new file mode 100644 index 0000000000000..a5b1e6f85a09e --- /dev/null +++ b/py/test/selenium/webdriver/safari/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Software Freedom Conservancy (SFC) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The SFC licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/py/test/selenium/webdriver/safari/safari_service_tests.py b/py/test/selenium/webdriver/safari/safari_service_tests.py new file mode 100644 index 0000000000000..02c76a91bece0 --- /dev/null +++ b/py/test/selenium/webdriver/safari/safari_service_tests.py @@ -0,0 +1,54 @@ +# Licensed to the Software Freedom Conservancy (SFC) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The SFC licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import os +import pytest + +from selenium.webdriver.safari.service import Service + +@pytest.fixture +def service(): + return Service() + +@pytest.mark.usefixtures("service") +class TestSafariDriverService: + service_path = "/path/to/safaridriver" + + @pytest.fixture(autouse=True) + def setup_and_teardown(self): + os.environ["SE_SAFARIDRIVER"] = self.service_path + yield + os.environ.pop("SE_SAFARIDRIVER", None) + + def test_uses_path_from_env_variable(self, service): + assert "safaridriver" in service.path + + def test_updates_path_after_setting_env_variable(self, service): + new_path = "/foo/bar" + os.environ["SE_SAFARIDRIVER"] = new_path + service.executable_path = self.service_path # Simulating the update + + assert "safaridriver" in service.executable_path + +def test_enable_logging(): + enable_logging = True + service = Service(enable_logging=enable_logging) + assert '--diagnose' in service.service_args + +def test_service_url(): + service = Service(port=1313) + assert service.service_url == "http://localhost:1313" From b35f289ac1efa64b4f7e70c10eb9467a8c06092e Mon Sep 17 00:00:00 2001 From: delta456 Date: Fri, 1 Nov 2024 22:14:19 +0530 Subject: [PATCH 2/5] fmt --- py/test/selenium/webdriver/safari/safari_service_tests.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/py/test/selenium/webdriver/safari/safari_service_tests.py b/py/test/selenium/webdriver/safari/safari_service_tests.py index 02c76a91bece0..494cbe6be6143 100644 --- a/py/test/selenium/webdriver/safari/safari_service_tests.py +++ b/py/test/selenium/webdriver/safari/safari_service_tests.py @@ -16,14 +16,17 @@ # under the License. import os + import pytest from selenium.webdriver.safari.service import Service + @pytest.fixture def service(): return Service() + @pytest.mark.usefixtures("service") class TestSafariDriverService: service_path = "/path/to/safaridriver" @@ -44,10 +47,12 @@ def test_updates_path_after_setting_env_variable(self, service): assert "safaridriver" in service.executable_path + def test_enable_logging(): enable_logging = True service = Service(enable_logging=enable_logging) - assert '--diagnose' in service.service_args + assert "--diagnose" in service.service_args + def test_service_url(): service = Service(port=1313) From d583b187cae9e5256c8be68fc23547bcc5df7bc0 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Sun, 3 Nov 2024 20:10:51 +0700 Subject: [PATCH 3/5] [py] Enable all test-safari Signed-off-by: Viet Nguyen Duc --- .github/workflows/ci-python.yml | 2 +- py/test/selenium/webdriver/common/alerts_tests.py | 1 + .../selenium/webdriver/common/api_example_tests.py | 1 + .../common/executing_async_javascript_tests.py | 1 + .../selenium/webdriver/common/interactions_tests.py | 4 ++++ .../common/interactions_with_device_tests.py | 4 ++++ .../webdriver/common/position_and_size_tests.py | 2 ++ .../webdriver/common/selenium_manager_tests.py | 11 ++++++++--- .../webdriver/common/w3c_interaction_tests.py | 2 ++ .../selenium/webdriver/common/webdriverwait_tests.py | 2 ++ .../webdriver/common/window_switching_tests.py | 1 + 11 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml index cebe68597d063..39e199aba52d8 100644 --- a/.github/workflows/ci-python.yml +++ b/.github/workflows/ci-python.yml @@ -97,4 +97,4 @@ jobs: os: macos cache-key: py-safari run: | - bazel test --local_test_jobs 1 --flaky_test_attempts 3 //py:test-safari-test/selenium/webdriver/safari/launcher_tests.py + bazel test --local_test_jobs 1 --flaky_test_attempts 3 //py:test-safari diff --git a/py/test/selenium/webdriver/common/alerts_tests.py b/py/test/selenium/webdriver/common/alerts_tests.py index ea37e0e3d5371..9479df88fadf5 100644 --- a/py/test/selenium/webdriver/common/alerts_tests.py +++ b/py/test/selenium/webdriver/common/alerts_tests.py @@ -294,6 +294,7 @@ def test_alert_should_not_allow_additional_commands_if_dismissed(driver, pages): @pytest.mark.xfail_remote(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1279211") @pytest.mark.xfail_chrome @pytest.mark.xfail_edge +@pytest.mark.xfail_safari def test_unexpected_alert_present_exception_contains_alert_text(driver, pages): pages.load("alerts.html") driver.find_element(by=By.ID, value="alert").click() diff --git a/py/test/selenium/webdriver/common/api_example_tests.py b/py/test/selenium/webdriver/common/api_example_tests.py index 7b8a4cedee3d8..40b3d2b7a2f01 100644 --- a/py/test/selenium/webdriver/common/api_example_tests.py +++ b/py/test/selenium/webdriver/common/api_example_tests.py @@ -240,6 +240,7 @@ def test_is_element_displayed(driver, pages): @pytest.mark.xfail_chrome +@pytest.mark.xfail_safari def test_move_window_position(driver, pages): pages.load("blank.html") loc = driver.get_window_position() diff --git a/py/test/selenium/webdriver/common/executing_async_javascript_tests.py b/py/test/selenium/webdriver/common/executing_async_javascript_tests.py index 9ca2477e70b1f..16d7beefa6dc3 100644 --- a/py/test/selenium/webdriver/common/executing_async_javascript_tests.py +++ b/py/test/selenium/webdriver/common/executing_async_javascript_tests.py @@ -152,6 +152,7 @@ def test_should_catch_errors_when_executing_initial_script(driver, pages): driver.execute_async_script("throw Error('you should catch this!');") +@pytest.mark.xfail_safari def test_should_be_able_to_execute_asynchronous_scripts(driver, pages): pages.load("ajaxy_page.html") diff --git a/py/test/selenium/webdriver/common/interactions_tests.py b/py/test/selenium/webdriver/common/interactions_tests.py index 8c2ad03fc8d6f..7ffe0e9dc4e0b 100644 --- a/py/test/selenium/webdriver/common/interactions_tests.py +++ b/py/test/selenium/webdriver/common/interactions_tests.py @@ -253,6 +253,7 @@ def test_can_pause(driver, pages): @pytest.mark.xfail_firefox @pytest.mark.xfail_remote +@pytest.mark.xfail_safari def test_can_scroll_to_element(driver, pages): pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html") iframe = driver.find_element(By.TAG_NAME, "iframe") @@ -266,6 +267,7 @@ def test_can_scroll_to_element(driver, pages): @pytest.mark.xfail_firefox @pytest.mark.xfail_remote +@pytest.mark.xfail_safari def test_can_scroll_from_element_by_amount(driver, pages): pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html") iframe = driver.find_element(By.TAG_NAME, "iframe") @@ -280,6 +282,7 @@ def test_can_scroll_from_element_by_amount(driver, pages): @pytest.mark.xfail_firefox @pytest.mark.xfail_remote +@pytest.mark.xfail_safari def test_can_scroll_from_element_with_offset_by_amount(driver, pages): pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html") footer = driver.find_element(By.TAG_NAME, "footer") @@ -314,6 +317,7 @@ def test_can_scroll_from_viewport_by_amount(driver, pages): assert _in_viewport(driver, footer) +@pytest.mark.xfail_safari def test_can_scroll_from_viewport_with_offset_by_amount(driver, pages): pages.load("scrolling_tests/frame_with_nested_scrolling_frame.html") scroll_origin = ScrollOrigin.from_viewport(10, 10) diff --git a/py/test/selenium/webdriver/common/interactions_with_device_tests.py b/py/test/selenium/webdriver/common/interactions_with_device_tests.py index 926b93c641e44..f82f3967a0776 100644 --- a/py/test/selenium/webdriver/common/interactions_with_device_tests.py +++ b/py/test/selenium/webdriver/common/interactions_with_device_tests.py @@ -247,6 +247,7 @@ def test_can_pause_with_pointer(driver, pages): @pytest.mark.xfail_firefox @pytest.mark.xfail_remote +@pytest.mark.xfail_safari def test_can_scroll_to_element_with_wheel(driver, pages): pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html") iframe = driver.find_element(By.TAG_NAME, "iframe") @@ -262,6 +263,7 @@ def test_can_scroll_to_element_with_wheel(driver, pages): @pytest.mark.xfail_firefox @pytest.mark.xfail_remote +@pytest.mark.xfail_safari def test_can_scroll_from_element_by_amount_with_wheel(driver, pages): pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html") iframe = driver.find_element(By.TAG_NAME, "iframe") @@ -278,6 +280,7 @@ def test_can_scroll_from_element_by_amount_with_wheel(driver, pages): @pytest.mark.xfail_firefox @pytest.mark.xfail_remote +@pytest.mark.xfail_safari def test_can_scroll_from_element_with_offset_by_amount_with_wheel(driver, pages): pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html") footer = driver.find_element(By.TAG_NAME, "footer") @@ -320,6 +323,7 @@ def test_can_scroll_from_viewport_by_amount_with_wheel(driver, pages): @pytest.mark.xfail_firefox +@pytest.mark.xfail_safari def test_can_scroll_from_viewport_with_offset_by_amount_with_wheel(driver, pages): pages.load("scrolling_tests/frame_with_nested_scrolling_frame.html") scroll_origin = ScrollOrigin.from_viewport(10, 10) diff --git a/py/test/selenium/webdriver/common/position_and_size_tests.py b/py/test/selenium/webdriver/common/position_and_size_tests.py index a438c0f5e0c88..081c51358a517 100644 --- a/py/test/selenium/webdriver/common/position_and_size_tests.py +++ b/py/test/selenium/webdriver/common/position_and_size_tests.py @@ -53,6 +53,7 @@ def test_should_get_coordinates_of_an_invisible_element(driver, pages): _check_location(element.location, x=0, y=0) +@pytest.mark.xfail_safari def test_should_scroll_page_and_get_coordinates_of_an_element_that_is_out_of_view_port(driver, pages): pages.load("coordinates_tests/page_with_element_out_of_view.html") element = driver.find_element(By.ID, "box") @@ -89,6 +90,7 @@ def test_should_get_coordinates_of_an_element_in_anested_frame(driver, pages): _check_location(element.location, x=10, y=10) +@pytest.mark.xfail_safari def test_should_get_coordinates_of_an_element_with_fixed_position(driver, pages): pages.load("coordinates_tests/page_with_fixed_element.html") element = driver.find_element(By.ID, "fixed") diff --git a/py/test/selenium/webdriver/common/selenium_manager_tests.py b/py/test/selenium/webdriver/common/selenium_manager_tests.py index 8692644cee0c4..67239bf87a67d 100644 --- a/py/test/selenium/webdriver/common/selenium_manager_tests.py +++ b/py/test/selenium/webdriver/common/selenium_manager_tests.py @@ -15,6 +15,7 @@ # specific language governing permissions and limitations # under the License. import json +import platform import sys from pathlib import Path from unittest import mock @@ -59,10 +60,14 @@ def test_uses_windows(monkeypatch): def test_uses_linux(monkeypatch): monkeypatch.setattr(sys, "platform", "linux") - binary = SeleniumManager()._get_binary() - project_root = Path(selenium.__file__).parent.parent - assert binary == project_root.joinpath("selenium/webdriver/common/linux/selenium-manager") + if platform.machine() == "arm64": + with pytest.raises(WebDriverException, match="Unsupported platform/architecture combination: linux/arm64"): + SeleniumManager()._get_binary() + else: + binary = SeleniumManager()._get_binary() + project_root = Path(selenium.__file__).parent.parent + assert binary == project_root.joinpath("selenium/webdriver/common/linux/selenium-manager") def test_uses_mac(monkeypatch): diff --git a/py/test/selenium/webdriver/common/w3c_interaction_tests.py b/py/test/selenium/webdriver/common/w3c_interaction_tests.py index d0a00ac26a2d4..5376265ede3bb 100644 --- a/py/test/selenium/webdriver/common/w3c_interaction_tests.py +++ b/py/test/selenium/webdriver/common/w3c_interaction_tests.py @@ -176,6 +176,7 @@ def test_dragging_element_with_mouse_fires_events(driver, pages): @pytest.mark.xfail_firefox @pytest.mark.xfail_remote +@pytest.mark.xfail_safari def test_pen_pointer_properties(driver, pages): pages.load("pointerActionsPage.html") @@ -223,6 +224,7 @@ def test_pen_pointer_properties(driver, pages): @pytest.mark.xfail_firefox @pytest.mark.xfail_remote +@pytest.mark.xfail_safari def test_touch_pointer_properties(driver, pages): pages.load("pointerActionsPage.html") pointerArea = driver.find_element(By.CSS_SELECTOR, "#pointerArea") diff --git a/py/test/selenium/webdriver/common/webdriverwait_tests.py b/py/test/selenium/webdriver/common/webdriverwait_tests.py index 14019d185e8b0..318f20c81d392 100644 --- a/py/test/selenium/webdriver/common/webdriverwait_tests.py +++ b/py/test/selenium/webdriver/common/webdriverwait_tests.py @@ -35,6 +35,7 @@ def throw_sere(driver): @pytest.mark.xfail_chrome(reason="https://bugs.chromium.org/p/chromedriver/issues/detail?id=4743") @pytest.mark.xfail_edge(reason="https://bugs.chromium.org/p/chromedriver/issues/detail?id=4743") +@pytest.mark.xfail_safari def test_should_fail_with_invalid_selector_exception(driver, pages): pages.load("dynamic.html") with pytest.raises(InvalidSelectorException): @@ -283,6 +284,7 @@ def test_expected_condition_element_to_be_clickable(driver, pages): assert element.is_displayed() is False +@pytest.mark.xfail_safari def test_expected_condition_staleness_of(driver, pages): pages.load("dynamicallyModifiedPage.html") element = driver.find_element(By.ID, "element-to-remove") diff --git a/py/test/selenium/webdriver/common/window_switching_tests.py b/py/test/selenium/webdriver/common/window_switching_tests.py index 1e2359cd52b36..2883ab2c55f69 100644 --- a/py/test/selenium/webdriver/common/window_switching_tests.py +++ b/py/test/selenium/webdriver/common/window_switching_tests.py @@ -130,6 +130,7 @@ def test_should_throw_no_such_window_exception_on_any_element_operation_if_awind element.text +@pytest.mark.xfail_safari def test_clicking_on_abutton_that_closes_an_open_window_does_not_cause_the_browser_to_hang(driver, pages): pages.load("xhtmlTest.html") current = driver.current_window_handle From a813d3d35510ad1cfeb58da7566b743220c94727 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Sun, 3 Nov 2024 23:08:24 +0700 Subject: [PATCH 4/5] Update to run macos-15 Signed-off-by: Viet Nguyen Duc --- .github/workflows/bazel.yml | 2 +- .github/workflows/ci-python.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 428ac9ae6f87a..bd71d478682ae 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -70,7 +70,7 @@ on: jobs: bazel: name: ${{ inputs.name }} - runs-on: ${{ inputs.os == 'macos' && 'macos-13' || format('{0}-latest', inputs.os) }} + runs-on: ${{ inputs.os == 'macos' && 'macos-13' || inputs.os == 'macos-15' && 'macos-15' || format('{0}-latest', inputs.os) }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SEL_M2_USER: ${{ secrets.SEL_M2_USER }} diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml index 39e199aba52d8..f48bb93c3cd1e 100644 --- a/.github/workflows/ci-python.yml +++ b/.github/workflows/ci-python.yml @@ -94,7 +94,7 @@ jobs: with: name: Integration Tests (safari) browser: safari - os: macos + os: macos-15 cache-key: py-safari run: | bazel test --local_test_jobs 1 --flaky_test_attempts 3 //py:test-safari From 6dd408246b7681979b8dc7d4394614eb5291eed8 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Mon, 4 Nov 2024 04:39:34 +0700 Subject: [PATCH 5/5] Update tests Signed-off-by: Viet Nguyen Duc --- .github/workflows/bazel.yml | 2 +- .github/workflows/ci-python.yml | 5 ++--- .../webdriver/common/executing_async_javascript_tests.py | 1 - py/test/selenium/webdriver/common/upload_tests.py | 6 +++++- py/test/selenium/webdriver/common/webdriverwait_tests.py | 1 - 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index bd71d478682ae..428ac9ae6f87a 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -70,7 +70,7 @@ on: jobs: bazel: name: ${{ inputs.name }} - runs-on: ${{ inputs.os == 'macos' && 'macos-13' || inputs.os == 'macos-15' && 'macos-15' || format('{0}-latest', inputs.os) }} + runs-on: ${{ inputs.os == 'macos' && 'macos-13' || format('{0}-latest', inputs.os) }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SEL_M2_USER: ${{ secrets.SEL_M2_USER }} diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml index f48bb93c3cd1e..e826cab4a91f0 100644 --- a/.github/workflows/ci-python.yml +++ b/.github/workflows/ci-python.yml @@ -94,7 +94,6 @@ jobs: with: name: Integration Tests (safari) browser: safari - os: macos-15 + os: macos cache-key: py-safari - run: | - bazel test --local_test_jobs 1 --flaky_test_attempts 3 //py:test-safari + run: bazel test --local_test_jobs 1 --flaky_test_attempts 3 //py:test-safari diff --git a/py/test/selenium/webdriver/common/executing_async_javascript_tests.py b/py/test/selenium/webdriver/common/executing_async_javascript_tests.py index 16d7beefa6dc3..9ca2477e70b1f 100644 --- a/py/test/selenium/webdriver/common/executing_async_javascript_tests.py +++ b/py/test/selenium/webdriver/common/executing_async_javascript_tests.py @@ -152,7 +152,6 @@ def test_should_catch_errors_when_executing_initial_script(driver, pages): driver.execute_async_script("throw Error('you should catch this!');") -@pytest.mark.xfail_safari def test_should_be_able_to_execute_asynchronous_scripts(driver, pages): pages.load("ajaxy_page.html") diff --git a/py/test/selenium/webdriver/common/upload_tests.py b/py/test/selenium/webdriver/common/upload_tests.py index df2906eecce74..642085790e303 100644 --- a/py/test/selenium/webdriver/common/upload_tests.py +++ b/py/test/selenium/webdriver/common/upload_tests.py @@ -16,6 +16,7 @@ # under the License. import os +import textwrap import pytest @@ -30,11 +31,13 @@ def get_local_path(): current_dir = os.path.dirname(os.path.realpath(__file__)) def wrapped(filename): - return os.path.join(current_dir, filename) + full_path = os.path.join(current_dir, filename) + return textwrap.fill(full_path, width=512) return wrapped +@pytest.mark.xfail_safari def test_can_upload_file(driver, pages, get_local_path): pages.load("upload.html") @@ -45,6 +48,7 @@ def test_can_upload_file(driver, pages, get_local_path): WebDriverWait(driver, 10).until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, "body"), "test_file.txt")) +@pytest.mark.xfail_safari def test_can_upload_two_files(driver, pages, get_local_path): pages.load("upload.html") two_file_paths = get_local_path("test_file.txt") + "\n" + get_local_path("test_file2.txt") diff --git a/py/test/selenium/webdriver/common/webdriverwait_tests.py b/py/test/selenium/webdriver/common/webdriverwait_tests.py index 318f20c81d392..f332933e4241c 100644 --- a/py/test/selenium/webdriver/common/webdriverwait_tests.py +++ b/py/test/selenium/webdriver/common/webdriverwait_tests.py @@ -284,7 +284,6 @@ def test_expected_condition_element_to_be_clickable(driver, pages): assert element.is_displayed() is False -@pytest.mark.xfail_safari def test_expected_condition_staleness_of(driver, pages): pages.load("dynamicallyModifiedPage.html") element = driver.find_element(By.ID, "element-to-remove")