pytest plugin for Selenium
Project description
pytest-selenium-enhancer is a plugin for pytest that provides enhanced webdriver functionality by dynamically adding methods to: - remote.webdriver.Webdriver - remote.webdriver.WebElement
It provides a set of commands to enable testing of WebComponents and Visual Regression Testing
Requirements
Following prerequisites are needed in order to use pytest-selenium-enhancer:
numpy
opencv-python >= 4.2.0.32
pillow >= 7.0.0
Python >= 3.7.5
pytest >= 5.3.0
pytest-variables >= 1.9.0
requests
selenium >= 3.141.0
Installation
To install pytest-selenium-enhancer:
$ pip install pytest-selenium-enhancer
Features
The plugin provides a set of custom commands to use for browser testing with pytest
remote.Webdriver
shadow_find_element
Returns an element of a DOM subtree by given selector
Usage
browser.shadow_find_element(selector)
Parameters
Name
Type
Details
selector
(obj:CSS Selector)
CSS Selector as described here
Example
browser.shadow_find_element('custom-login-component')
shadow_cascade_find_element
Returns an element of a DOM subtree by given list of selectors
Usage
browser.shadow_cascade_find_element(selectors)
Parameters
Name
Type
Details
selectors
(obj:CSS Selector), n (obj:CSS Selector)
CSS Selectors as described here
Example
browser.shadow_cascade_find_element('custom-login-component', 'custom-login-form', 'custom-field')
shadow_find_elements
Returns a list of elements of a DOM subtree by given of selector
Usage
browser.shadow_find_elements(selector)
Parameters
Name
Type
Details
selectors
(obj:CSS Selector)
CSS Selectors as described here
Example
browser.shadow_cascade_find_element('custom-login-component')
get_full_page_screenshot_as_base64
- Gets full page screenshot of current page by automatically scroll the full width and height of the page
NOTE: Does not work for infinite scrolling pages
Usage
browser.get_full_page_screenshot_as_base64(elements_to_hide, device_offset)
Parameters
Name
Type
Details
selectors
(obj)
{‘top’: [sticky top elements that you want to hide after first horizontal scroll], ‘all’:[elements that you want to completely hide], ‘bottom’: [sticky bottom elements that you want to show only after first horizontal scroll]}
device_offset
(int)
iOS only. Used to define the height of the browser upper controls. Safari iOS browser controls are part of the screenshot taken by selenium so we want not to have them into a full page screenshot
Example
elements_to_hide = { "start": [self.get_header()._banner] if self.page_name is 'home_page' else None, "all": None, "end": [self.get_persistent_isi()._component_container] } browser.get_full_page_screenshot_as_base64(elements_to_hide, 284)
get_full_page_screenshot_as_png
- Gets full page screenshot of current page by automatically scroll the full width and height of the page
NOTE: Does not work for infinite scrolling pages
Usage
browser.get_full_page_screenshot_as_png(elements_to_hide, device_offset)
Parameters
Name
Type
Details
selectors
(obj)
{‘top’: [sticky top elements that you want to hide after first horizontal scroll], ‘all’:[elements that you want to completely hide], ‘bottom’: [sticky bottom elements that you want to show only after first horizontal scroll]}
device_offset
(int)
iOS only. Used to define the height of the browser upper controls. Safari iOS browser controls are part of the screenshot taken by selenium so we want not to have them into a full page screenshot
Example
elements_to_hide = { "start": [self.get_header()._banner] if self.page_name is 'home_page' else None, "all": None, "end": [self.get_persistent_isi()._component_container] } browser.get_full_page_screenshot_as_png(elements_to_hide, 284)
remote.WebElement
shadow_find_element
Returns a child element of a DOM subtree by given selector
Usage
element.shadow_find_element(selector)
Parameters
Name
Type
Details
selector
(obj:CSS Selector)
CSS Selector as described here
Example
custom_login_component = browser.find_element_by_tag_name('custom-login-component') custom_login_component.shadow_find_element('custom-login-component')
shadow_cascade_find_element
Returns a child element of a DOM subtree by given list of selectors
Usage
element.shadow_cascade_find_element(selectors)
Parameters
Name
Type
Details
selectors
(obj:CSS Selector), n (obj:CSS Selector)
CSS Selectors as described here
Example
custom_login_component = browser.find_element_by_tag_name('custom-login-component') custom_login_component.shadow_cascade_find_element('custom-login-component', 'custom-login-form', 'custom-field')
shadow_find_elements
Returns a list of children elements of a DOM subtree by given of selector
Usage
element.shadow_find_elements(selector)
Parameters
Name
Type
Details
selectors
(obj:CSS Selector)
CSS Selectors as described here
Example
custom_login_component = browser.find_element_by_tag_name('custom-login-component') custom_login_component.shadow_cascade_find_element('custom-login-component')
If you want to know more about WebComponents and ShadowRoot
NOTE: For the above examples, the following piece of HTML, as seen in Developer Tools, was considered:
<custom-login-component>
#shadowRoot (open)
<custom-login-form>
#shadowRoot (open)
<custom-field type="text">
#shadowRoot (open)
<input></input>
</custom-field>
<custom-field type="password">
#shadowRoot (open)
<input></input>
</custom-field>
<custom-button>Login
#shadowRoot (open)
<button></button>
</custom-button>
</custom-login-form>
</custom-login-component>
Contributing
We welcome contributions.
To learn more, see Contributing
E2E testing is brought to you by BrowserStack.
Resources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for pytest-selenium-enhancer-1.4.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | da783c5979db5ea67bd6c86de19f2e55b84561be0f3273b0bf6bcaedf5b9b335 |
|
MD5 | 48a1023917a3bac354f7194418e2a640 |
|
BLAKE2b-256 | 22ad379afad138747d84157e7af8e32090608ef1f603118a8490bfce074d2a51 |