Skip to content

Commit

Permalink
[py] Add in support for page loading strategies for Options
Browse files Browse the repository at this point in the history
This allows for the page load strategy to be set.

See https://w3c.github.io/webdriver/#dfn-page-loading-strategy
  • Loading branch information
AutomatedTester committed Feb 28, 2020
1 parent a849bb7 commit f878211
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 5 deletions.
11 changes: 11 additions & 0 deletions py/selenium/webdriver/chromium/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions py/selenium/webdriver/common/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BaseOptions(object):

def __init__(self):
self._caps = self.default_capabilities
self.set_capability("pageLoadStrategy", "normal")

@property
def capabilities(self):
Expand Down
11 changes: 11 additions & 0 deletions py/selenium/webdriver/firefox/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions py/selenium/webdriver/opera/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions py/selenium/webdriver/webkitgtk/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion py/test/unit/selenium/webdriver/edge/edge_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 24 additions & 1 deletion py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 3 additions & 1 deletion py/test/unit/selenium/webdriver/opera/opera_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f878211

Please sign in to comment.