WebDriver
qa_pytest_webdriver
__all__ = ['By', 'Locator', 'SearchContext', 'SeleniumConfiguration', 'SeleniumSteps', 'SeleniumTests']
module-attribute
By
Factory for Selenium locators, matching Selenium's By API.
Provides static methods to create Locator objects for each Selenium locator strategy.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
class_name(value)
staticmethod
Creates a locator for elements with the given class name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The class name. |
required |
Returns: Locator: The locator object.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
142 143 144 145 146 147 148 149 150 151 152 |
|
css_selector(value)
staticmethod
Creates a locator for elements matching the given CSS selector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The CSS selector. |
required |
Returns: Locator: The locator object.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
154 155 156 157 158 159 160 161 162 163 164 |
|
id(value)
staticmethod
Creates a locator for elements with the given id attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The id value. |
required |
Returns: Locator: The locator object.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
70 71 72 73 74 75 76 77 78 79 80 |
|
link_text(value)
staticmethod
Creates a locator for elements with the given link text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The link text. |
required |
Returns: Locator: The locator object.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
94 95 96 97 98 99 100 101 102 103 104 |
|
name(value)
staticmethod
Creates a locator for elements with the given name attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The name value. |
required |
Returns: Locator: The locator object.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
118 119 120 121 122 123 124 125 126 127 128 |
|
partial_link_text(value)
staticmethod
Creates a locator for elements with the given partial link text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The partial link text. |
required |
Returns: Locator: The locator object.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
106 107 108 109 110 111 112 113 114 115 116 |
|
tag_name(value)
staticmethod
Creates a locator for elements with the given tag name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The tag name. |
required |
Returns: Locator: The locator object.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
130 131 132 133 134 135 136 137 138 139 140 |
|
xpath(value)
staticmethod
Creates a locator for elements matching the given XPath expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The XPath expression. |
required |
Returns: Locator: The locator object.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
82 83 84 85 86 87 88 89 90 91 92 |
|
Locator
dataclass
Represents a Selenium locator as a (by, value) pair.
Attributes:
Name | Type | Description |
---|---|---|
by |
str
|
The Selenium locator strategy (e.g., By.ID, By.XPATH). |
value |
str
|
The locator value. |
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
by
instance-attribute
value
instance-attribute
__init__(by, value)
as_tuple()
Returns the locator as a tuple (by, value), suitable for Selenium APIs.
Returns:
Type | Description |
---|---|
Tuple[str, str]
|
Tuple[str, str]: The locator as a tuple. |
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
53 54 55 56 57 58 59 60 |
|
SearchContext
Bases: Protocol
Protocol for Selenium search contexts (e.g., WebDriver, WebElement).
Provides methods to find single or multiple elements using Selenium's locator strategy.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
28 29 30 31 32 33 34 35 36 37 38 |
|
find_element(by, value)
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
35 |
|
find_elements(by, value)
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
37 38 |
|
SeleniumConfiguration
Bases: BaseConfiguration
SeleniumConfiguration extends BaseConfiguration to provide Selenium-specific configuration options.
This class exposes properties for retrieving the UI URL and initializing the Selenium WebDriver Service, leveraging configuration values and dynamic driver management.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_configuration.py
13 14 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 |
|
landing_page
cached
property
Returns the UI URL from the configuration parser.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The URL string specified under the "selenium/base" in the configuration. |
Raises:
Type | Description |
---|---|
KeyError
|
If the "selenium" section or "base" key is not present in the configuration parser. |
service
cached
property
Creates and returns a Selenium WebDriver Service instance using the ChromeDriverManager.
Returns:
Name | Type | Description |
---|---|---|
Service |
Service
|
An instance of Selenium's Service class, initialized with the path to the ChromeDriver executable |
Service
|
installed by ChromeDriverManager. |
Note
This method currently supports only ChromeDriver, but may be extended to support different services based on configuration in the future.
SeleniumSteps
Bases: GenericSteps[TConfiguration]
BDD-style step definitions for Selenium-based UI operations.
Type Parameters
TConfiguration: The configuration type, must be a SeleniumConfiguration.
Attributes:
Name | Type | Description |
---|---|---|
_web_driver |
WebDriver
|
The Selenium WebDriver instance used for browser automation. |
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
clicking(element)
clicking(element: Locator) -> Self
clicking(element: ElementSupplier) -> Self
Clicks the element specified by a locator or supplier, with retry logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element
|
LocatorOrSupplier
|
Locator or callable returning a WebElement. |
required |
Returns: Self: The current step instance for chaining.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
205 206 207 208 209 210 211 212 213 214 215 |
|
clicking_once(element_supplier)
Clicks the element supplied by the given callable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_supplier
|
ElementSupplier
|
Callable returning a WebElement. |
required |
Returns: Self: The current step instance for chaining.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
the_element(locator, by_rule, context=None)
Asserts that the element found by the locator matches the given matcher.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locator
|
Locator
|
The locator to find the element. |
required |
by_rule
|
Matcher[WebElement]
|
Matcher for the element. |
required |
context
|
Optional[SearchContext]
|
Optional search context. |
None
|
Returns: Self: The current step instance for chaining.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
the_elements(locator, by_rule, context=None)
Asserts that the elements found by the locator match the given matcher.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locator
|
Locator
|
The locator to find the elements. |
required |
by_rule
|
Matcher[Iterator[WebElement]]
|
Matcher for the elements iterator. |
required |
context
|
Optional[SearchContext]
|
Optional search context. |
None
|
Returns: Self: The current step instance for chaining.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
typing(element, text)
typing(element: Locator, text: str) -> Self
typing(element: ElementSupplier, text: str) -> Self
Types the given text into the element specified by a locator or supplier, with retry logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element
|
LocatorOrSupplier
|
Locator or callable returning a WebElement. |
required |
text
|
str
|
The text to type. |
required |
Returns: Self: The current step instance for chaining.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
240 241 242 243 244 245 246 247 248 249 250 251 |
|
typing_once(element_supplier, text)
Types the given text into the element supplied by the callable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_supplier
|
ElementSupplier
|
Callable returning a WebElement. |
required |
text
|
str
|
The text to type. |
required |
Returns: Self: The current step instance for chaining.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_steps.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
SeleniumTests
Bases: 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:
Name | Type | Description |
---|---|---|
_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 SeleniumConfiguration.
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 |
|
web_driver
property
Returns the web driver instance.
Returns:
Name | Type | Description |
---|---|---|
WebDriver |
WebDriver
|
The web driver instance. |
setup_method()
Initializes the Selenium WebDriver before each test method.
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 |
|
teardown_method()
Quits the Selenium WebDriver after each test method.
Source code in qa-pytest-webdriver/src/qa_pytest_webdriver/selenium_tests.py
57 58 59 60 61 62 63 64 65 |
|