A collection of expected conditions against the current browser.
Expectations
.contain_title(title: str) - The substring for the title to contain
.contain_url(url: str) - The substring for the URL to contain
.have_title(title: str) - The case-sensitive title to match
.have_url(url: str) - The case-sensitive url to match
.not_find(css: str) - The CSS selector
.not_findx(xpath: str) - The XPATH selector
.not_contain(text: str) - The text to contain
Syntax
# Use the default wait_time
py.should().<expectation>
---or---
# Customize the wait_time for this expectation
py.should(timeout: int).<expectation>
---or---
# Ignore exceptions that you expect to "get in the way"
py.should(ignored_exceptions: list).<expectation>
---or---
# Customize both fully
py.should(timeout: int, ignored_exceptions: list).<expectation>
def test_title_matches_within_5_seconds(py):
py.visit("https://qap.dev")
# Override global timeout for only this action
assert py.should(timeout=5).have_title("QA at the Point")
Ignore exceptions
def test_title_matches(py):
py.visit("https://qap.dev")
# These exceptions will not stop the "wait until"
exceptions = [WebDriverException, NoSuchElementException]
assert py.should(ignored_exceptions=exceptions).have_title("QA at the Point")
Yields
Pylenium - If the assertion passes, then the current instance of Pylenium is returned, else an AssertionError is raised if the condition is not met within the specified timeout.