Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[py] add safari service tests #14700

Merged
merged 9 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,4 @@ jobs:
browser: safari
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
run: bazel test --local_test_jobs 1 --flaky_test_attempts 3 //py:test-safari
1 change: 1 addition & 0 deletions py/test/selenium/webdriver/common/alerts_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions py/test/selenium/webdriver/common/api_example_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions py/test/selenium/webdriver/common/interactions_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions py/test/selenium/webdriver/common/position_and_size_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
11 changes: 8 additions & 3 deletions py/test/selenium/webdriver/common/selenium_manager_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion py/test/selenium/webdriver/common/upload_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import os
import textwrap

import pytest

Expand All @@ -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")

Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions py/test/selenium/webdriver/common/w3c_interaction_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions py/test/selenium/webdriver/common/webdriverwait_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions py/test/selenium/webdriver/safari/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
59 changes: 59 additions & 0 deletions py/test/selenium/webdriver/safari/safari_service_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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"
Loading