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 page load strategy enum #13258

Merged
merged 3 commits into from
Dec 8, 2023
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
19 changes: 18 additions & 1 deletion py/selenium/webdriver/common/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,28 @@
import typing
from abc import ABCMeta
from abc import abstractmethod
from enum import Enum

from selenium.common.exceptions import InvalidArgumentException
from selenium.webdriver.common.proxy import Proxy


class PageLoadStrategy(str, Enum):
"""Enum of possible page load strategies.

Selenium support following strategies:
* normal (default) - waits for all resources to download
* eager - DOM access is ready, but other resources like images may still be loading
* none - does not block `WebDriver` at all

Docs: https://www.selenium.dev/documentation/webdriver/drivers/options/#pageloadstrategy.
"""

normal = "normal"
eager = "eager"
none = "none"


class _BaseOptionsDescriptor:
def __init__(self, name):
self.name = name
Expand Down Expand Up @@ -348,7 +365,7 @@ def __init__(self) -> None:
super().__init__()
self._caps = self.default_capabilities
self._proxy = None
self.set_capability("pageLoadStrategy", "normal")
self.set_capability("pageLoadStrategy", PageLoadStrategy.normal)
self.mobile_options = None

@property
Expand Down
3 changes: 2 additions & 1 deletion py/test/selenium/webdriver/marionette/mn_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.options import PageLoadStrategy
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.options import Log
Expand Down Expand Up @@ -98,7 +99,7 @@ def test_arguments(self):
def test_to_capabilities(self):
opts = Options()
firefox_caps = DesiredCapabilities.FIREFOX.copy()
firefox_caps.update({"pageLoadStrategy": "normal"})
firefox_caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
assert opts.to_capabilities() == firefox_caps

profile = FirefoxProfile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pytest

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.options import PageLoadStrategy


@pytest.fixture
Expand Down Expand Up @@ -132,7 +133,7 @@ def test_starts_with_default_capabilities(options):
from selenium.webdriver import DesiredCapabilities

caps = DesiredCapabilities.CHROME.copy()
caps.update({"pageLoadStrategy": "normal"})
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
assert options._caps == caps


Expand Down
15 changes: 8 additions & 7 deletions py/test/unit/selenium/webdriver/edge/edge_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import pytest

from selenium.webdriver.common.options import PageLoadStrategy
from selenium.webdriver.edge.options import Options


Expand All @@ -31,27 +32,27 @@ def test_raises_exception_with_invalid_page_load_strategy(options):


def test_set_page_load_strategy(options):
options.page_load_strategy = "normal"
options.page_load_strategy = PageLoadStrategy.normal
caps = options.to_capabilities()
assert caps["pageLoadStrategy"] == "normal"
assert caps["pageLoadStrategy"] == PageLoadStrategy.normal


def test_get_page_load_strategy(options):
options._caps["pageLoadStrategy"] = "normal"
assert options.page_load_strategy == "normal"
options._caps["pageLoadStrategy"] = PageLoadStrategy.normal
assert options.page_load_strategy == PageLoadStrategy.normal


def test_creates_capabilities(options):
options.page_load_strategy = "eager"
options.page_load_strategy = PageLoadStrategy.eager
caps = options.to_capabilities()
assert caps["pageLoadStrategy"] == "eager"
assert caps["pageLoadStrategy"] == PageLoadStrategy.eager


def test_starts_with_default_capabilities(options):
from selenium.webdriver import DesiredCapabilities

caps = DesiredCapabilities.EDGE.copy()
caps.update({"pageLoadStrategy": "normal"})
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
assert options._caps == caps


Expand Down
15 changes: 8 additions & 7 deletions py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pytest

from selenium.common.exceptions import InvalidArgumentException
from selenium.webdriver.common.options import PageLoadStrategy
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
Expand Down Expand Up @@ -150,7 +151,7 @@ def test_starts_with_default_capabilities(options):
from selenium.webdriver import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX.copy()
caps.update({"pageLoadStrategy": "normal"})
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
assert options._caps == caps


Expand All @@ -166,19 +167,19 @@ def test_raises_exception_with_invalid_page_load_strategy(options):


def test_set_page_load_strategy(options):
options.page_load_strategy = "normal"
assert options._caps["pageLoadStrategy"] == "normal"
options.page_load_strategy = PageLoadStrategy.normal
assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal


def test_get_page_load_strategy(options):
options._page_load_strategy = "normal"
assert options._caps["pageLoadStrategy"] == "normal"
options._page_load_strategy = PageLoadStrategy.normal
assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal


def test_creates_capabilities_with_page_load_strategy(options):
options.page_load_strategy = "eager"
options.page_load_strategy = PageLoadStrategy.eager
caps = options.to_capabilities()
assert caps["pageLoadStrategy"] == "eager"
assert caps["pageLoadStrategy"] == PageLoadStrategy.eager


def test_enables_firefox_mobile(options):
Expand Down
3 changes: 2 additions & 1 deletion py/test/unit/selenium/webdriver/ie/test_ie_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import pytest

from selenium.webdriver.common.options import PageLoadStrategy
from selenium.webdriver.ie.options import ElementScrollBehavior
from selenium.webdriver.ie.options import Options

Expand Down Expand Up @@ -193,7 +194,7 @@ def test_starts_with_default_capabilities(opts):
from selenium.webdriver import DesiredCapabilities

caps = DesiredCapabilities.INTERNETEXPLORER.copy()
caps.update({"pageLoadStrategy": "normal"})
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
assert opts._caps == caps


Expand Down
5 changes: 3 additions & 2 deletions py/test/unit/selenium/webdriver/remote/new_session_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.common.options import ArgOptions
from selenium.webdriver.common.options import PageLoadStrategy
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
from selenium.webdriver.remote import webdriver
Expand Down Expand Up @@ -77,7 +78,7 @@ def test_always_match_if_2_of_the_same_options():
"capabilities": {
"alwaysMatch": {
"browserName": "chrome",
"pageLoadStrategy": "normal",
"pageLoadStrategy": PageLoadStrategy.normal,
},
"firstMatch": [
{"goog:chromeOptions": {"args": ["foo"], "extensions": []}},
Expand All @@ -95,7 +96,7 @@ def test_first_match_when_2_different_option_types():

expected = {
"capabilities": {
"alwaysMatch": {"pageLoadStrategy": "normal"},
"alwaysMatch": {"pageLoadStrategy": PageLoadStrategy.normal},
"firstMatch": [
{"browserName": "chrome", "goog:chromeOptions": {"extensions": [], "args": []}},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import pytest

from selenium.webdriver.common.options import PageLoadStrategy
from selenium.webdriver.safari.options import Options


Expand All @@ -29,7 +30,7 @@ def test_starts_with_default_capabilities(options):
from selenium.webdriver import DesiredCapabilities

caps = DesiredCapabilities.SAFARI.copy()
caps.update({"pageLoadStrategy": "normal"})
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
assert options._caps == caps


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import pytest

from selenium.webdriver.common.options import PageLoadStrategy
from selenium.webdriver.webkitgtk.options import Options


Expand Down Expand Up @@ -61,7 +62,7 @@ def test_starts_with_default_capabilities(options):
from selenium.webdriver import DesiredCapabilities

caps = DesiredCapabilities.WEBKITGTK.copy()
caps.update({"pageLoadStrategy": "normal"})
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
assert options._caps == caps


Expand Down
Loading