You've already forked SeleniumHQ.selenium.py
[py] Add page load strategy enum (#13258)
Fixes #13236 NOKEYCHECK=True GitOrigin-RevId: 68b92607f4629e6406f6611b56a7e08fb9cfdba5
This commit is contained in:

committed by
Copybara-Service

parent
4a53df342c
commit
08dd4cf456
selenium/webdriver/common
test
selenium
webdriver
marionette
unit
selenium
webdriver
chrome
edge
firefox
ie
remote
safari
webkitgtk
@ -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
|
||||
@ -348,7 +365,7 @@ class BaseOptions(metaclass=ABCMeta):
|
||||
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
|
||||
|
@ -19,6 +19,7 @@ import pytest
|
||||
|
||||
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
|
||||
@ -98,7 +99,7 @@ class TestUnit:
|
||||
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()
|
||||
|
@ -20,6 +20,7 @@ from os import path
|
||||
import pytest
|
||||
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
from selenium.webdriver.common.options import PageLoadStrategy
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -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
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from selenium.webdriver.common.options import PageLoadStrategy
|
||||
from selenium.webdriver.edge.options import Options
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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):
|
||||
|
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@ import pytest
|
||||
|
||||
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
|
||||
@ -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": []}},
|
||||
@ -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": []}},
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from selenium.webdriver.common.options import PageLoadStrategy
|
||||
from selenium.webdriver.safari.options import Options
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from selenium.webdriver.common.options import PageLoadStrategy
|
||||
from selenium.webdriver.webkitgtk.options import Options
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user