pytest_dash package¶
Submodules¶
pytest_dash.application_runners module¶
pytest_dash.behavior_parser module¶
Custom lark parser and transformer for dash behavior tests.
-
class
pytest_dash.behavior_parser.
BehaviorTransformer
(driver, variables=None)[source]¶ Bases:
lark.visitors.Transformer
,object
Transform and execute behavior commands.
-
__init__
(driver, variables=None)[source]¶ Parameters: driver (selenium.webdriver.remote.webdriver.WebDriver) – Selenium driver to find elements in the tree
-
element_id
(*args, **kwargs)[source]¶ Find an element by id when found in the tree.
Example: #dropdown
Kind: value Parameters: element_id – Text after #
-
element_prop
(*args, **kwargs)[source]¶ Property value of an element
Example: #element.prop
Kind: value
-
element_selector
(*args, **kwargs)[source]¶ Find an element by selector when found in the tree.
Example: {#radio-items > label:nth-child(9) > input[type="radio"]}
Kind: value Parameters: selector – Text contained between { & }
-
elements_xpath
(*args, **kwargs)[source]¶ Find all elements by xpath
Example: *[//div/span]
Kind: value
-
escape_string
(*args, **kwargs)[source]¶ Escaped string handler, remove the
"
from the token.Kind: value
-
prop_compare
(*args, **kwargs)[source]¶ Wait for a property to equal a value.
Example: #output.id should be "my-element"
Kind: comparison
-
send_value
(*args, **kwargs)[source]¶ Send key inputs to the element
Example: enter "Hello" in #input
Kind: command
-
style_compare
(*args, **kwargs)[source]¶ Compare a style value of an of element.
Example: style “color” of #style should be “rgba(0, 0, 255, 1)”
Kind: comparison
Parameters: - style – Name of the style property
- element – Element to find
- _ – eq
- value – Value to compare to the element style attribute.
Returns:
-
-
class
pytest_dash.behavior_parser.
BehaviorTransformerMeta
[source]¶ Bases:
type
Dynamically create a parser transformer with user defined behaviors
-
pytest_dash.behavior_parser.
parser_factory
(driver, variables=None, behaviors=None)[source]¶ Create a Lark parser with a BehaviorTransformer with the provided selenium driver to find the elements.
A new behavior transformer class is created and behaviors are assigned a transformer function from the supplied behaviors in the pytest_add_behaviors hook.
Parameters: - driver – Selenium driver to use when parsing elements.
- variables – Variables to use in the parser transformer.
- behaviors – Custom behaviors, come from plugin.behaviors.
Returns:
pytest_dash.behaviors module¶
pytest_dash.errors module¶
Pytest-dash errors.
-
exception
pytest_dash.errors.
DashAppLoadingError
[source]¶ Bases:
pytest_dash.errors.PytestDashError
The dash app failed to load
-
exception
pytest_dash.errors.
InvalidDriverError
[source]¶ Bases:
pytest_dash.errors.PytestDashError
An invalid selenium driver was specified.
-
exception
pytest_dash.errors.
MissingBehaviorError
[source]¶ Bases:
pytest_dash.errors.PytestDashError
A behavior was missing from the
-
exception
pytest_dash.errors.
NoAppFoundError
[source]¶ Bases:
pytest_dash.errors.PytestDashError
No app was found in the file.
-
exception
pytest_dash.errors.
PytestDashError
[source]¶ Bases:
exceptions.Exception
Base error for pytest-dash.
-
exception
pytest_dash.errors.
ServerCloseError
[source]¶ Bases:
pytest_dash.errors.PytestDashError
Pytest-dash had trouble closing a server.
pytest_dash.new_hooks module¶
Custom hooks for pytest dash
-
pytest_dash.new_hooks.
pytest_add_behaviors
(add_behavior)[source]¶ Use this hook to add custom behavior parsing.
Example conftest.py
def pytest_add_behavior(add_behavior): @add_behavior('Text to parse') def custom_parse_action(params): pass
Parameters: add_behavior – Decorator for a behavior handler function. Returns:
-
pytest_dash.new_hooks.
pytest_setup_selenium
(driver_name)[source]¶ Called before the driver is created, return a dictionary to use as kwargs for the driver init.
Parameters: driver_name (str) – The name of the driver specified by either cli argument or in pytest.ini. Returns: The dictionary of kwargs to give to the driver constructor.
pytest_dash.plugin module¶
pytest_dash.wait_for module¶
Utils methods for pytest-dash such wait_for wrappers
-
pytest_dash.wait_for.
wait_for_element_by_css_selector
(driver, selector, timeout=10.0)[source]¶ Wait until a single element is found and return it. This variant use the css selector api: https://www.w3schools.com/jsref/met_document_queryselector.asp
Parameters: - driver (selenium.webdriver.remote.webdriver.WebDriver) – Selenium driver
- selector (str) – CSS selector to find.
- timeout (float) – Maximum time to find the element.
Returns:
-
pytest_dash.wait_for.
wait_for_element_by_id
(driver, _id, timeout=10)[source]¶ Wait until a single element is found and return it. This variant find by id.
Parameters: - driver (selenium.webdriver.remote.webdriver.WebDriver) – Selenium driver
- _id – The id of the element to find.
- timeout (float) – Maximum time to find the element.
Returns:
-
pytest_dash.wait_for.
wait_for_element_by_xpath
(driver, xpath, timeout=10)[source]¶ Wait until a single element is found and return it. This variant use xpath to find the element. https://www.w3schools.com/xml/xml_xpath.asp
Parameters: - driver (selenium.webdriver.remote.webdriver.WebDriver) – Selenium driver
- xpath (str) – Xpath query string.
- timeout (float) – Maximum time to find the element.
Returns:
-
pytest_dash.wait_for.
wait_for_elements_by_css_selector
(driver, selector, timeout=10.0)[source]¶ Wait until all elements are found by the selector before the timeout.
Parameters: - driver (selenium.webdriver.remote.webdriver.WebDriver) – Selenium driver
- selector (str) – Search for elements
- timeout (float) – Maximum wait time
Returns: Found elements
-
pytest_dash.wait_for.
wait_for_elements_by_xpath
(driver, xpath, timeout=10)[source]¶ Wait until all are found before the timeout. This variant use xpath to find the elements. https://www.w3schools.com/xml/xml_xpath.asp
Parameters: - driver (selenium.webdriver.remote.webdriver.WebDriver) – Selenium driver
- xpath (str) – Xpath query string.
- timeout (float) – Maximum time to find the element.
Returns:
-
pytest_dash.wait_for.
wait_for_property_to_equal
(driver, selector, prop_name, prop_value, timeout=10)[source]¶ Wait for an element property to equal a value.
Parameters: - driver (selenium.webdriver.remote.webdriver.WebDriver) – Selenium driver
- selector (str) – Selector of the element to assert it’s property.
- prop_name (str) – The name of property.
- prop_value – The value to assert.
- timeout (float) – Maximum time.
Returns:
-
pytest_dash.wait_for.
wait_for_style_to_equal
(driver, selector, style_attribute, style_assertion, timeout=10)[source]¶ Wait for an element style attribute to equal.
Parameters: - driver (selenium.webdriver.remote.webdriver.WebDriver) – Selenium driver
- selector (str) – Selector of the element to assert it’s style property.
- style_attribute (str) – The name of the CSS attribute to assert.
- style_assertion (str) – The value to equal of CSS attribute.
- timeout (float) – Maximum time.
Returns:
-
pytest_dash.wait_for.
wait_for_text_to_equal
(driver, selector, text, timeout=10)[source]¶ Wait an element text found by css selector is equal to text.
Parameters: - driver (selenium.webdriver.remote.webdriver.WebDriver) – Selenium driver
- selector (str) – Selector of the element to assert it’s text property.
- text (str) – Text to equal.
- timeout (float) – Maximum time for the text to equal.
Returns: