Skip to content
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
5 changes: 0 additions & 5 deletions .skipped-tests
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
-//javascript/selenium-webdriver:test-chrome-service-test.js-chrome
-//javascript/selenium-webdriver:test-firefox-options-test.js-firefox
-//javascript/selenium-webdriver:test-lib-capabilities-test.js-chrome
-//py:test-chrome-test/selenium/webdriver/chrome/chrome_launcher_tests.py
-//py:test-chrome-test/selenium/webdriver/chrome/chrome_service_tests.py
-//py:test-chrome-test/selenium/webdriver/chrome/proxy_tests.py
-//py:test-edge-test/selenium/webdriver/edge/edge_launcher_tests.py
-//py:test-edge-test/selenium/webdriver/edge/edge_service_tests.py
-//rb/spec/integration/selenium/webdriver/chrome:service-chrome
-//rb/spec/integration/selenium/webdriver/chrome:service-chrome-bidi
-//rb/spec/integration/selenium/webdriver/chrome:service-chrome-remote
Expand Down
33 changes: 14 additions & 19 deletions py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,10 @@ def get_options(driver_class, config):
browser_args = config.option.args
headless = config.option.headless
bidi = config.option.bidi
options = None

options = getattr(webdriver, f"{driver_class}Options")()

if browser_path or browser_args:
if not options:
options = getattr(webdriver, f"{driver_class}Options")()
if driver_class == "WebKitGTK":
options.overlay_scrollbars_enabled = False
if browser_path is not None:
Expand All @@ -227,16 +226,12 @@ def get_options(driver_class, config):
options.add_argument(arg)

if headless:
if not options:
options = getattr(webdriver, f"{driver_class}Options")()
if driver_class == "Chrome" or driver_class == "Edge":
options.add_argument("--headless=new")
if driver_class == "Firefox":
options.add_argument("-headless")

if bidi:
if not options:
options = getattr(webdriver, f"{driver_class}Options")()
options.web_socket_url = True
options.unhandled_prompt_behavior = "ignore"

Expand Down Expand Up @@ -336,30 +331,30 @@ def driver_executable(request):
return request.config.option.executable


@pytest.fixture(scope="function")
def clean_service(request):
try:
driver_class = get_driver_class(request.config.option.drivers[0])
except (AttributeError, TypeError):
raise Exception("This test requires a --driver to be specified")

yield get_service(driver_class, request.config.option.executable)


@pytest.fixture(scope="function")
def clean_driver(request):
try:
driver_class = get_driver_class(request.config.option.drivers[0])
except (AttributeError, TypeError):
raise Exception("This test requires a --driver to be specified")

driver_reference = getattr(webdriver, driver_class)
yield driver_reference

if request.node.get_closest_marker("no_driver_after_test"):
driver_reference = None


@pytest.fixture(scope="function")
def clean_service(request):
driver_class = get_driver_class(request.config.option.drivers[0])
yield get_service(driver_class, request.config.option.executable)


@pytest.fixture(scope="function")
def clean_options(request):
driver_class = get_driver_class(request.config.option.drivers[0])
yield get_options(driver_class, request.config)


@pytest.fixture
def firefox_options(request):
try:
Expand Down
12 changes: 6 additions & 6 deletions py/test/selenium/webdriver/chrome/chrome_launcher_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@


@pytest.mark.no_driver_after_test
def test_launch_and_close_browser(clean_driver, clean_service):
driver = clean_driver(service=clean_service)
def test_launch_and_close_browser(clean_driver, clean_options, clean_service):
driver = clean_driver(options=clean_options, service=clean_service)
driver.quit()


@pytest.mark.no_driver_after_test
def test_we_can_launch_multiple_chrome_instances(clean_driver, clean_service):
driver1 = clean_driver(service=clean_service)
driver2 = clean_driver(service=clean_service)
driver3 = clean_driver(service=clean_service)
def test_we_can_launch_multiple_chrome_instances(clean_driver, clean_options, clean_service):
driver1 = clean_driver(options=clean_options, service=clean_service)
driver2 = clean_driver(options=clean_options, service=clean_service)
driver3 = clean_driver(options=clean_options, service=clean_service)
driver1.quit()
driver2.quit()
driver3.quit()
28 changes: 13 additions & 15 deletions py/test/selenium/webdriver/chrome/chrome_service_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import pytest

from selenium.common.exceptions import SessionNotCreatedException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service


@pytest.mark.no_driver_after_test
def test_uses_chromedriver_logging(clean_driver, driver_executable) -> None:
def test_uses_chromedriver_logging(clean_driver, clean_options, driver_executable) -> None:
log_file = "chromedriver.log"
service_args = ["--append-log"]

Expand All @@ -47,10 +46,10 @@ def test_uses_chromedriver_logging(clean_driver, driver_executable) -> None:
driver1 = None
driver2 = None
try:
driver1 = clean_driver(service=service1)
driver1 = clean_driver(options=clean_options, service=service1)
with open(log_file) as fp:
lines = len(fp.readlines())
driver2 = clean_driver(service=service2)
driver2 = clean_driver(options=clean_options, service=service2)
with open(log_file) as fp:
assert len(fp.readlines()) >= 2 * lines
finally:
Expand All @@ -62,12 +61,12 @@ def test_uses_chromedriver_logging(clean_driver, driver_executable) -> None:


@pytest.mark.no_driver_after_test
def test_log_output_as_filename(clean_driver, driver_executable) -> None:
def test_log_output_as_filename(clean_driver, clean_options, driver_executable) -> None:
log_file = "chromedriver.log"
service = Service(log_output=log_file, executable_path=driver_executable)
try:
assert "--log-path=chromedriver.log" in service.service_args
driver = clean_driver(service=service)
driver = clean_driver(options=clean_options, service=service)
with open(log_file) as fp:
assert "Starting ChromeDriver" in fp.readline()
finally:
Expand All @@ -76,12 +75,12 @@ def test_log_output_as_filename(clean_driver, driver_executable) -> None:


@pytest.mark.no_driver_after_test
def test_log_output_as_file(clean_driver, driver_executable) -> None:
def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> None:
log_name = "chromedriver.log"
log_file = open(log_name, "w", encoding="utf-8")
service = Service(log_output=log_file, executable_path=driver_executable)
try:
driver = clean_driver(service=service)
driver = clean_driver(options=clean_options, service=service)
time.sleep(1)
with open(log_name) as fp:
assert "Starting ChromeDriver" in fp.readline()
Expand All @@ -92,9 +91,9 @@ def test_log_output_as_file(clean_driver, driver_executable) -> None:


@pytest.mark.no_driver_after_test
def test_log_output_as_stdout(clean_driver, capfd, driver_executable) -> None:
def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executable) -> None:
service = Service(log_output=subprocess.STDOUT, executable_path=driver_executable)
driver = clean_driver(service=service)
driver = clean_driver(options=clean_options, service=service)

out, err = capfd.readouterr()
assert "Starting ChromeDriver" in out
Expand All @@ -109,12 +108,11 @@ def test_log_output_null_default(driver, capfd) -> None:


@pytest.mark.no_driver_after_test
def test_driver_is_stopped_if_browser_cant_start(clean_driver) -> None:
options = Options()
options.add_argument("--user-data-dir=/no/such/location")
service = Service()
def test_driver_is_stopped_if_browser_cant_start(clean_driver, clean_options, driver_executable) -> None:
clean_options.add_argument("--user-data-dir=/no/such/location")
service = Service(executable_path=driver_executable)
with pytest.raises(SessionNotCreatedException):
clean_driver(options=options, service=service)
clean_driver(options=clean_options, service=service)
assert not service.is_connectable()
assert service.process.poll() is not None

Expand Down
10 changes: 3 additions & 7 deletions py/test/selenium/webdriver/chrome/proxy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@
import pytest
import urllib3

from selenium import webdriver


@pytest.mark.no_driver_after_test
def test_bad_proxy_doesnt_interfere(clean_driver, clean_service):
def test_bad_proxy_doesnt_interfere(clean_driver, clean_options, clean_service):
# Proxy environment variables should be ignored if
# ignore_local_proxy_environment_variables() is called.

options = webdriver.ChromeOptions()
options.ignore_local_proxy_environment_variables()
chrome_kwargs = {"options": options, "service": clean_service}
clean_options.ignore_local_proxy_environment_variables()
chrome_kwargs = {"options": clean_options, "service": clean_service}
with patch.dict("os.environ", {"http_proxy": "bad", "https_proxy": "bad"}):
driver = clean_driver(**chrome_kwargs)
assert hasattr(driver, "command_executor")
Expand Down
12 changes: 6 additions & 6 deletions py/test/selenium/webdriver/edge/edge_launcher_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@


@pytest.mark.no_driver_after_test
def test_launch_and_close_browser(clean_driver, clean_service):
driver = clean_driver(service=clean_service)
def test_launch_and_close_browser(clean_driver, clean_options, clean_service):
driver = clean_driver(options=clean_options, service=clean_service)
driver.quit()


@pytest.mark.no_driver_after_test
def test_we_can_launch_multiple_edge_instances(clean_driver, clean_service):
driver1 = clean_driver(service=clean_service)
driver2 = clean_driver(service=clean_service)
driver3 = clean_driver(service=clean_service)
def test_we_can_launch_multiple_edge_instances(clean_driver, clean_options, clean_service):
driver1 = clean_driver(options=clean_options, service=clean_service)
driver2 = clean_driver(options=clean_options, service=clean_service)
driver3 = clean_driver(options=clean_options, service=clean_service)
driver1.quit()
driver2.quit()
driver3.quit()
28 changes: 13 additions & 15 deletions py/test/selenium/webdriver/edge/edge_service_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import pytest

from selenium.common.exceptions import SessionNotCreatedException
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service


@pytest.mark.no_driver_after_test
def test_uses_edgedriver_logging(clean_driver, driver_executable) -> None:
def test_uses_edgedriver_logging(clean_driver, clean_options, driver_executable) -> None:
log_file = "msedgedriver.log"
service_args = ["--append-log"]

Expand All @@ -47,10 +46,10 @@ def test_uses_edgedriver_logging(clean_driver, driver_executable) -> None:
driver1 = None
driver2 = None
try:
driver1 = clean_driver(service=service1)
driver1 = clean_driver(options=clean_options, service=service1)
with open(log_file) as fp:
lines = len(fp.readlines())
driver2 = clean_driver(service=service2)
driver2 = clean_driver(options=clean_options, service=service2)
with open(log_file) as fp:
assert len(fp.readlines()) >= 2 * lines
finally:
Expand All @@ -62,12 +61,12 @@ def test_uses_edgedriver_logging(clean_driver, driver_executable) -> None:


@pytest.mark.no_driver_after_test
def test_log_output_as_filename(clean_driver, driver_executable) -> None:
def test_log_output_as_filename(clean_driver, clean_options, driver_executable) -> None:
log_file = "msedgedriver.log"
service = Service(log_output=log_file, executable_path=driver_executable)
try:
assert "--log-path=msedgedriver.log" in service.service_args
driver = clean_driver(service=service)
driver = clean_driver(options=clean_options, service=service)
with open(log_file) as fp:
assert "Starting Microsoft Edge WebDriver" in fp.readline()
finally:
Expand All @@ -76,12 +75,12 @@ def test_log_output_as_filename(clean_driver, driver_executable) -> None:


@pytest.mark.no_driver_after_test
def test_log_output_as_file(clean_driver, driver_executable) -> None:
def test_log_output_as_file(clean_driver, clean_options, driver_executable) -> None:
log_name = "msedgedriver.log"
log_file = open(log_name, "w", encoding="utf-8")
service = Service(log_output=log_file, executable_path=driver_executable)
try:
driver = clean_driver(service=service)
driver = clean_driver(options=clean_options, service=service)
time.sleep(1)
with open(log_name) as fp:
assert "Starting Microsoft Edge WebDriver" in fp.readline()
Expand All @@ -92,9 +91,9 @@ def test_log_output_as_file(clean_driver, driver_executable) -> None:


@pytest.mark.no_driver_after_test
def test_log_output_as_stdout(clean_driver, capfd, driver_executable) -> None:
def test_log_output_as_stdout(clean_driver, clean_options, capfd, driver_executable) -> None:
service = Service(log_output=subprocess.STDOUT, executable_path=driver_executable)
driver = clean_driver(service=service)
driver = clean_driver(options=clean_options, service=service)

out, err = capfd.readouterr()
assert "Starting Microsoft Edge WebDriver" in out
Expand All @@ -109,12 +108,11 @@ def test_log_output_null_default(driver, capfd) -> None:


@pytest.mark.no_driver_after_test
def test_driver_is_stopped_if_browser_cant_start(clean_driver) -> None:
options = Options()
options.add_argument("--user-data-dir=/no/such/location")
service = Service()
def test_driver_is_stopped_if_browser_cant_start(clean_driver, clean_options, clean_service, driver_executable) -> None:
clean_options.add_argument("--user-data-dir=/no/such/location")
service = Service(executable_path=driver_executable)
with pytest.raises(SessionNotCreatedException):
clean_driver(options=options, service=service)
clean_driver(options=clean_options, service=service)
assert not service.is_connectable()
assert service.process.poll() is not None

Expand Down
Loading