diff --git a/py/selenium/webdriver/chromium/options.py b/py/selenium/webdriver/chromium/options.py index f5f4193df9054..fa9b23d49cb23 100644 --- a/py/selenium/webdriver/chromium/options.py +++ b/py/selenium/webdriver/chromium/options.py @@ -150,6 +150,17 @@ def headless(self, value): else: self._arguments = list(set(self._arguments) - args) + @property + def page_load_strategy(self): + return self._caps["pageLoadStrategy"] + + @page_load_strategy.setter + def page_load_strategy(self, strategy): + if strategy in ["normal", "eager", "none"]: + self.set_capability("pageLoadStrategy", strategy) + else: + raise ValueError("Strategy can only be one of the following: normal, eager, none") + def to_capabilities(self): """ Creates a capabilities with all the options that have been set diff --git a/py/selenium/webdriver/common/options.py b/py/selenium/webdriver/common/options.py index 06f74b546fb74..aab3f0803cf02 100644 --- a/py/selenium/webdriver/common/options.py +++ b/py/selenium/webdriver/common/options.py @@ -26,6 +26,7 @@ class BaseOptions(object): def __init__(self): self._caps = self.default_capabilities + self.set_capability("pageLoadStrategy", "normal") @property def capabilities(self): diff --git a/py/selenium/webdriver/firefox/options.py b/py/selenium/webdriver/firefox/options.py index 913dcfe1abf59..410a3390e7c8e 100644 --- a/py/selenium/webdriver/firefox/options.py +++ b/py/selenium/webdriver/firefox/options.py @@ -137,6 +137,17 @@ def headless(self, value): elif '-headless' in self._arguments: self._arguments.remove('-headless') + @property + def page_load_strategy(self): + return self._caps["pageLoadStrategy"] + + @page_load_strategy.setter + def page_load_strategy(self, strategy): + if strategy in ["normal", "eager", "none"]: + self.set_capability("pageLoadStrategy", strategy) + else: + raise ValueError("Strategy can only be one of the following: normal, eager, none") + def to_capabilities(self): """Marshals the Firefox options to a `moz:firefoxOptions` object. diff --git a/py/selenium/webdriver/opera/options.py b/py/selenium/webdriver/opera/options.py index 4fc29c172d665..5bc10b44c448f 100644 --- a/py/selenium/webdriver/opera/options.py +++ b/py/selenium/webdriver/opera/options.py @@ -79,6 +79,17 @@ def android_command_line_file(self, value): """ self._android_command_line_file = value + @property + def page_load_strategy(self): + return self._caps["pageLoadStrategy"] + + @page_load_strategy.setter + def page_load_strategy(self, strategy): + if strategy in ["normal", "eager", "none"]: + self.set_capability("pageLoadStrategy", strategy) + else: + raise ValueError("Strategy can only be one of the following: normal, eager, none") + def to_capabilities(self): """ Creates a capabilities with all the options that have been set and diff --git a/py/selenium/webdriver/webkitgtk/options.py b/py/selenium/webdriver/webkitgtk/options.py index ad84c468336ae..cbf5a620c9352 100644 --- a/py/selenium/webdriver/webkitgtk/options.py +++ b/py/selenium/webdriver/webkitgtk/options.py @@ -61,6 +61,17 @@ def overlay_scrollbars_enabled(self, value): """ self._overlay_scrollbars_enabled = value + @property + def page_load_strategy(self): + return self._caps["pageLoadStrategy"] + + @page_load_strategy.setter + def page_load_strategy(self, strategy): + if strategy in ["normal", "eager", "none"]: + self.set_capability("pageLoadStrategy", strategy) + else: + raise ValueError("Strategy can only be one of the following: normal, eager, none") + def to_capabilities(self): """ Creates a capabilities with all the options that have been set and diff --git a/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py b/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py index ff7e14ebeb84e..ba3a1d2b07ed3 100644 --- a/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py +++ b/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py @@ -147,7 +147,9 @@ def test_creates_capabilities(options): def test_starts_with_default_capabilities(options): from selenium.webdriver import DesiredCapabilities - assert options._caps == DesiredCapabilities.CHROME + caps = DesiredCapabilities.CHROME.copy() + caps.update({"pageLoadStrategy": "normal"}) + assert options._caps == caps def test_is_a_baseoptions(options): diff --git a/py/test/unit/selenium/webdriver/edge/edge_options_tests.py b/py/test/unit/selenium/webdriver/edge/edge_options_tests.py index 1fa50291d9cf9..38f121b6ceff3 100644 --- a/py/test/unit/selenium/webdriver/edge/edge_options_tests.py +++ b/py/test/unit/selenium/webdriver/edge/edge_options_tests.py @@ -48,7 +48,9 @@ def test_creates_capabilities(options): def test_starts_with_default_capabilities(options): from selenium.webdriver import DesiredCapabilities - assert options._caps == DesiredCapabilities.EDGE + caps = DesiredCapabilities.EDGE.copy() + caps.update({"pageLoadStrategy": "normal"}) + assert options._caps == caps def test_is_a_baseoptions(options): diff --git a/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py b/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py index 93d53d33a44eb..718638a42bac4 100644 --- a/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py +++ b/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py @@ -154,9 +154,32 @@ def test_creates_capabilities(options): def test_starts_with_default_capabilities(options): from selenium.webdriver import DesiredCapabilities - assert options._caps == DesiredCapabilities.FIREFOX + caps = DesiredCapabilities.FIREFOX.copy() + caps.update({"pageLoadStrategy": "normal"}) + assert options._caps == caps def test_is_a_baseoptions(options): from selenium.webdriver.common.options import BaseOptions assert isinstance(options, BaseOptions) + + +def test_raises_exception_with_invalid_page_load_strategy(options): + with pytest.raises(ValueError): + options.page_load_strategy = 'never' + + +def test_set_page_load_strategy(options): + options.page_load_strategy = 'normal' + assert options._caps["pageLoadStrategy"] == 'normal' + + +def test_get_page_load_strategy(options): + options._page_load_strategy = 'normal' + assert options._caps["pageLoadStrategy"] == 'normal' + + +def test_creates_capabilities(options): + options.page_load_strategy = 'eager' + caps = options.to_capabilities() + assert caps['pageLoadStrategy'] == 'eager' diff --git a/py/test/unit/selenium/webdriver/opera/opera_options_tests.py b/py/test/unit/selenium/webdriver/opera/opera_options_tests.py index 523b860001af3..dd9afe7c47c33 100644 --- a/py/test/unit/selenium/webdriver/opera/opera_options_tests.py +++ b/py/test/unit/selenium/webdriver/opera/opera_options_tests.py @@ -79,7 +79,9 @@ def test_creates_capabilities(options): def test_starts_with_default_capabilities(options): from selenium.webdriver import DesiredCapabilities - assert options._caps == DesiredCapabilities.OPERA + caps = DesiredCapabilities.OPERA.copy() + caps.update({"pageLoadStrategy": "normal"}) + assert options._caps == caps def test_is_a_baseoptions(options): diff --git a/py/test/unit/selenium/webdriver/webkitgtk/webkitgtk_options_tests.py b/py/test/unit/selenium/webdriver/webkitgtk/webkitgtk_options_tests.py index 508bd90f7aaa6..63aee42ba5f1c 100644 --- a/py/test/unit/selenium/webdriver/webkitgtk/webkitgtk_options_tests.py +++ b/py/test/unit/selenium/webdriver/webkitgtk/webkitgtk_options_tests.py @@ -59,7 +59,9 @@ def test_creates_capabilities(options): def test_starts_with_default_capabilities(options): from selenium.webdriver import DesiredCapabilities - assert options._caps == DesiredCapabilities.WEBKITGTK + caps = DesiredCapabilities.WEBKITGTK.copy() + caps.update({"pageLoadStrategy": "normal"}) + assert options._caps == caps def test_is_a_baseoptions(options):