Bases: AbstractTestsBase[SeleniumTests[TSteps], SeleniumTests[TConfiguration]]
Base class for Selenium-based UI test cases.
This class manages the lifecycle of a Selenium WebDriver for each test method.
It is generic over the types of steps and configuration used.
Attributes:
| Name |
Type |
Description |
_web_driver |
WebDriver
|
The Selenium WebDriver instance (not thread safe).
|
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_tests.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 | class SeleniumTests[
TSteps: SeleniumSteps[Any],
TConfiguration: UiConfiguration
](AbstractTestsBase[TSteps, TConfiguration]):
"""
Base class for Selenium-based UI test cases.
This class manages the lifecycle of a Selenium WebDriver for each test method.
It is generic over the types of steps and configuration used.
Attributes:
_web_driver (WebDriver): The Selenium WebDriver instance (not thread safe).
Type Parameters:
TSteps: The type of the steps class, typically derived from SeleniumSteps.
TConfiguration: The type of the configuration class, typically derived from UiConfiguration.
"""
_web_driver: WebDriver # not thread safe
@property
def ui_context(self) -> UiContext[UiElement]:
'''
Returns the web driver instance.
Returns:
UiContext[UiElement]: The web driver instance.
'''
return SeleniumUiContext(self._web_driver)
@override
def setup_method(self):
'''
Initializes a local Chrome WebDriver before each test method.
If you need to customize or use other driver, override this method in your test class.
'''
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
super().setup_method()
options = Options()
options.add_argument("--start-maximized")
options.add_argument("--disable-gpu")
self._web_driver = Chrome(
options,
Service(ChromeDriverManager().install()))
@override
def teardown_method(self):
'''
Quits the Selenium WebDriver after each test method.
'''
try:
self._web_driver.quit()
finally:
super().teardown_method()
|
ui_context
property
Returns the web driver instance.
Returns:
setup_method()
Initializes a local Chrome WebDriver before each test method.
If you need to customize or use other driver, override this method in your test class.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_tests.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 | @override
def setup_method(self):
'''
Initializes a local Chrome WebDriver before each test method.
If you need to customize or use other driver, override this method in your test class.
'''
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
super().setup_method()
options = Options()
options.add_argument("--start-maximized")
options.add_argument("--disable-gpu")
self._web_driver = Chrome(
options,
Service(ChromeDriverManager().install()))
|
teardown_method()
Quits the Selenium WebDriver after each test method.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_tests.py
65
66
67
68
69
70
71
72
73 | @override
def teardown_method(self):
'''
Quits the Selenium WebDriver after each test method.
'''
try:
self._web_driver.quit()
finally:
super().teardown_method()
|