Skip to content

Commit 68b9260

Browse files
authored
[py] Add page load strategy enum (#13258)
Fixes #13236
1 parent 6620bce commit 68b9260

File tree

9 files changed

+47
-22
lines changed

9 files changed

+47
-22
lines changed

py/selenium/webdriver/common/options.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,28 @@
1717
import typing
1818
from abc import ABCMeta
1919
from abc import abstractmethod
20+
from enum import Enum
2021

2122
from selenium.common.exceptions import InvalidArgumentException
2223
from selenium.webdriver.common.proxy import Proxy
2324

2425

26+
class PageLoadStrategy(str, Enum):
27+
"""Enum of possible page load strategies.
28+
29+
Selenium support following strategies:
30+
* normal (default) - waits for all resources to download
31+
* eager - DOM access is ready, but other resources like images may still be loading
32+
* none - does not block `WebDriver` at all
33+
34+
Docs: https://www.selenium.dev/documentation/webdriver/drivers/options/#pageloadstrategy.
35+
"""
36+
37+
normal = "normal"
38+
eager = "eager"
39+
none = "none"
40+
41+
2542
class _BaseOptionsDescriptor:
2643
def __init__(self, name):
2744
self.name = name
@@ -348,7 +365,7 @@ def __init__(self) -> None:
348365
super().__init__()
349366
self._caps = self.default_capabilities
350367
self._proxy = None
351-
self.set_capability("pageLoadStrategy", "normal")
368+
self.set_capability("pageLoadStrategy", PageLoadStrategy.normal)
352369
self.mobile_options = None
353370

354371
@property

py/test/selenium/webdriver/marionette/mn_options_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from selenium.webdriver.common.by import By
2121
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
22+
from selenium.webdriver.common.options import PageLoadStrategy
2223
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
2324
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
2425
from selenium.webdriver.firefox.options import Log
@@ -98,7 +99,7 @@ def test_arguments(self):
9899
def test_to_capabilities(self):
99100
opts = Options()
100101
firefox_caps = DesiredCapabilities.FIREFOX.copy()
101-
firefox_caps.update({"pageLoadStrategy": "normal"})
102+
firefox_caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
102103
assert opts.to_capabilities() == firefox_caps
103104

104105
profile = FirefoxProfile()

py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import pytest
2121

2222
from selenium.webdriver.chrome.options import Options
23+
from selenium.webdriver.common.options import PageLoadStrategy
2324

2425

2526
@pytest.fixture
@@ -132,7 +133,7 @@ def test_starts_with_default_capabilities(options):
132133
from selenium.webdriver import DesiredCapabilities
133134

134135
caps = DesiredCapabilities.CHROME.copy()
135-
caps.update({"pageLoadStrategy": "normal"})
136+
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
136137
assert options._caps == caps
137138

138139

py/test/unit/selenium/webdriver/edge/edge_options_tests.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import pytest
1919

20+
from selenium.webdriver.common.options import PageLoadStrategy
2021
from selenium.webdriver.edge.options import Options
2122

2223

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

3233

3334
def test_set_page_load_strategy(options):
34-
options.page_load_strategy = "normal"
35+
options.page_load_strategy = PageLoadStrategy.normal
3536
caps = options.to_capabilities()
36-
assert caps["pageLoadStrategy"] == "normal"
37+
assert caps["pageLoadStrategy"] == PageLoadStrategy.normal
3738

3839

3940
def test_get_page_load_strategy(options):
40-
options._caps["pageLoadStrategy"] = "normal"
41-
assert options.page_load_strategy == "normal"
41+
options._caps["pageLoadStrategy"] = PageLoadStrategy.normal
42+
assert options.page_load_strategy == PageLoadStrategy.normal
4243

4344

4445
def test_creates_capabilities(options):
45-
options.page_load_strategy = "eager"
46+
options.page_load_strategy = PageLoadStrategy.eager
4647
caps = options.to_capabilities()
47-
assert caps["pageLoadStrategy"] == "eager"
48+
assert caps["pageLoadStrategy"] == PageLoadStrategy.eager
4849

4950

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

5354
caps = DesiredCapabilities.EDGE.copy()
54-
caps.update({"pageLoadStrategy": "normal"})
55+
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
5556
assert options._caps == caps
5657

5758

py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import pytest
1919

2020
from selenium.common.exceptions import InvalidArgumentException
21+
from selenium.webdriver.common.options import PageLoadStrategy
2122
from selenium.webdriver.common.proxy import Proxy
2223
from selenium.webdriver.common.proxy import ProxyType
2324
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
@@ -150,7 +151,7 @@ def test_starts_with_default_capabilities(options):
150151
from selenium.webdriver import DesiredCapabilities
151152

152153
caps = DesiredCapabilities.FIREFOX.copy()
153-
caps.update({"pageLoadStrategy": "normal"})
154+
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
154155
assert options._caps == caps
155156

156157

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

167168

168169
def test_set_page_load_strategy(options):
169-
options.page_load_strategy = "normal"
170-
assert options._caps["pageLoadStrategy"] == "normal"
170+
options.page_load_strategy = PageLoadStrategy.normal
171+
assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal
171172

172173

173174
def test_get_page_load_strategy(options):
174-
options._page_load_strategy = "normal"
175-
assert options._caps["pageLoadStrategy"] == "normal"
175+
options._page_load_strategy = PageLoadStrategy.normal
176+
assert options._caps["pageLoadStrategy"] == PageLoadStrategy.normal
176177

177178

178179
def test_creates_capabilities_with_page_load_strategy(options):
179-
options.page_load_strategy = "eager"
180+
options.page_load_strategy = PageLoadStrategy.eager
180181
caps = options.to_capabilities()
181-
assert caps["pageLoadStrategy"] == "eager"
182+
assert caps["pageLoadStrategy"] == PageLoadStrategy.eager
182183

183184

184185
def test_enables_firefox_mobile(options):

py/test/unit/selenium/webdriver/ie/test_ie_options.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import pytest
2020

21+
from selenium.webdriver.common.options import PageLoadStrategy
2122
from selenium.webdriver.ie.options import ElementScrollBehavior
2223
from selenium.webdriver.ie.options import Options
2324

@@ -193,7 +194,7 @@ def test_starts_with_default_capabilities(opts):
193194
from selenium.webdriver import DesiredCapabilities
194195

195196
caps = DesiredCapabilities.INTERNETEXPLORER.copy()
196-
caps.update({"pageLoadStrategy": "normal"})
197+
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
197198
assert opts._caps == caps
198199

199200

py/test/unit/selenium/webdriver/remote/new_session_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from selenium.webdriver.chrome.options import Options as ChromeOptions
2424
from selenium.webdriver.common.options import ArgOptions
25+
from selenium.webdriver.common.options import PageLoadStrategy
2526
from selenium.webdriver.common.proxy import Proxy
2627
from selenium.webdriver.common.proxy import ProxyType
2728
from selenium.webdriver.remote import webdriver
@@ -77,7 +78,7 @@ def test_always_match_if_2_of_the_same_options():
7778
"capabilities": {
7879
"alwaysMatch": {
7980
"browserName": "chrome",
80-
"pageLoadStrategy": "normal",
81+
"pageLoadStrategy": PageLoadStrategy.normal,
8182
},
8283
"firstMatch": [
8384
{"goog:chromeOptions": {"args": ["foo"], "extensions": []}},
@@ -95,7 +96,7 @@ def test_first_match_when_2_different_option_types():
9596

9697
expected = {
9798
"capabilities": {
98-
"alwaysMatch": {"pageLoadStrategy": "normal"},
99+
"alwaysMatch": {"pageLoadStrategy": PageLoadStrategy.normal},
99100
"firstMatch": [
100101
{"browserName": "chrome", "goog:chromeOptions": {"extensions": [], "args": []}},
101102
{

py/test/unit/selenium/webdriver/safari/safari_options_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import pytest
1919

20+
from selenium.webdriver.common.options import PageLoadStrategy
2021
from selenium.webdriver.safari.options import Options
2122

2223

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

3132
caps = DesiredCapabilities.SAFARI.copy()
32-
caps.update({"pageLoadStrategy": "normal"})
33+
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
3334
assert options._caps == caps
3435

3536

py/test/unit/selenium/webdriver/webkitgtk/webkitgtk_options_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import pytest
1919

20+
from selenium.webdriver.common.options import PageLoadStrategy
2021
from selenium.webdriver.webkitgtk.options import Options
2122

2223

@@ -61,7 +62,7 @@ def test_starts_with_default_capabilities(options):
6162
from selenium.webdriver import DesiredCapabilities
6263

6364
caps = DesiredCapabilities.WEBKITGTK.copy()
64-
caps.update({"pageLoadStrategy": "normal"})
65+
caps.update({"pageLoadStrategy": PageLoadStrategy.normal})
6566
assert options._caps == caps
6667

6768

0 commit comments

Comments
 (0)