API Reference¶
API compatibility / stability¶
lemoncheesecake-selenium follows the well know Semantic Versioning for its public API. Since lemoncheesecake-selenium is still on 0.y.z major version, API breaking changes might occur; it is then advised to pin the version.
What is considered as “public” is everything documented on https://lemoncheesecake-selenium.readthedocs.io. Everything else is internal and is subject to changes at anytime.
Selector¶
- class lemoncheesecake_selenium.Selector(driver)¶
Factory of
Selectioninstances.- Parameters
- by_xpath(value)¶
Get a
Selectionusing element’s xpath- Parameters
value – a value related to
by- Returns
- by_link_text(value)¶
Get a
Selectionusing element’s link text- Parameters
value – a value related to
by- Returns
- by_partial_link_text(value)¶
Get a
Selectionusing element’s partial link text- Parameters
value – a value related to
by- Returns
- by_name(value)¶
Get a
Selectionusing element’s name- Parameters
value – a value related to
by- Returns
- by_tag_name(value)¶
Get a
Selectionusing element’s tag name- Parameters
value – a value related to
by- Returns
Selection¶
- class lemoncheesecake_selenium.Selection(driver, by, value)¶
- default_timeout = 10¶
The default timeout value to use if no
timeoutargument is passed to themust_be_waited_until()/must_be_waited_until_not()methods.
- screenshot_on_exceptions = False¶
Whether or not a screenshot will be automatically saved upon upon
WebDriverExceptionexceptions on methods such asSelection.set_text(),Selection.click(), etc…
- screenshot_on_failed_checks = False¶
Whether or not a screenshot will be automatically saved upon failed checks with
Selection.check_element(),Selection.require_element()andSelection.assert_element()methods.
- must_be_waited_until(expected_condition, *, timeout=None, extra_args=())¶
The method can be called to set an explicit wait (see https://selenium-python.readthedocs.io/waits.html#explicit-waits) on the underlying element so that it is considered available when the
expected_conditionis met.- Parameters
expected_condition (Callable) – a callable that will take a locator (a tuple of
(by, path)) as first argumenttimeout (Optional[int]) – wait timeout (will be
Selection.default_timeoutif no argument is passed)extra_args – extra arguments to be passed to the
expected_conditioncallable
- Returns
self, meaning this method can be chain called
- must_be_waited_until_not(expected_condition, *, timeout=None, extra_args=())¶
The method can be called to set an explicit wait (see https://selenium-python.readthedocs.io/waits.html#explicit-waits) on the underlying element so that it is considered available when the
expected_conditionis NOT met.- Parameters
expected_condition (Callable) – a callable that will take a locator (a tuple of
(by, path)) as first argumenttimeout (Optional[int]) – wait timeout (will be
Selection.default_timeoutif no argument is passed)extra_args – extra arguments to be passed to the
expected_conditioncallable
- Returns
self, meaning this method can be chain called
- property element: selenium.webdriver.remote.webelement.WebElement¶
- Returns
the underlying
WebElementwith the explicit wait taken into account (if any has been set)
- property elements: Sequence[selenium.webdriver.remote.webelement.WebElement]¶
- Returns
the underlying
WebElementlist with the explicit wait taken into account (if any has been set)
- click()¶
Click on the element.
- clear()¶
Clear the element.
- check_element(expected)¶
Check that the element matches
expectedusing thelemoncheesecake.matching.check_that()function.- Parameters
expected (lemoncheesecake.matching.matcher.Matcher) – a
Matcherinstance whosematchesmethod will be called with theWebElementthat has been found
- check_no_element()¶
Check that the element is not present using the
lemoncheesecake.matching.check_that()function.
- require_element(expected)¶
Check that the element matches
expectedusing thelemoncheesecake.matching.require_that()function.- Parameters
expected (lemoncheesecake.matching.matcher.Matcher) – a
Matcherinstance whosematchesmethod will be called with theWebElementthat has been found
- require_no_element()¶
Check that the element is not present using the
lemoncheesecake.matching.require_that()function.
- assert_element(expected)¶
Check that the element matches
expectedusing thelemoncheesecake.matching.assert_that()function.- Parameters
expected (lemoncheesecake.matching.matcher.Matcher) – a
Matcherinstance whosematchesmethod will be called with theWebElementthat has been found
- assert_no_element()¶
Check that the element is not present using the
lemoncheesecake.matching.assert_that()function.
- save_screenshot(description=None)¶
Take and save (as lemoncheesecake attachment) a screenshot of the underlying element.
- Parameters
description (Optional[str]) – description of the image attachment for that screenshot
- select_by_value(value)¶
Select option by its value considering the underlying element is a SELECT element.
- Parameters
value – the value to be selected
- select_by_index(index)¶
Select option by its index considering the underlying element is a SELECT element.
- Parameters
index – the index to be selected
- select_by_visible_text(text)¶
Select option by its text considering the underlying element is a SELECT element.
- Parameters
text – the text to be selected
- deselect_all()¶
Deselect all options considering the underlying element is a SELECT element.
- deselect_by_value(value)¶
Deselect option by its value considering the underlying element is a SELECT element.
- Parameters
value – the value to be deselected
- deselect_by_index(index)¶
Deselect option by its index considering the underlying element is a SELECT element.
- Parameters
index – the index to be deselected
- deselect_by_visible_text(text)¶
Deselect option by its text considering the underlying element is a SELECT element.
- Parameters
text – the text to be deselected
Matchers¶
- lemoncheesecake_selenium.is_in_page()¶
Test if
WebElementis present in page.NB: as the matcher is already called with a
WebElementinstance, the matcher will always be successful.- Returns
Matcherinstance
- lemoncheesecake_selenium.has_text(expected)¶
Test if
WebElementinstance has text.- Parameters
expected (Union[lemoncheesecake.matching.matcher.Matcher, str]) – expected text
- Returns
Matcherinstance
- lemoncheesecake_selenium.has_attribute(name, matcher=None)¶
Test if
WebElementelement has entity.- Parameters
name (str) – attribute name
matcher (Optional[Union[str, lemoncheesecake.matching.matcher.Matcher]]) – attribute matcher
- Returns
Matcherinstance
- lemoncheesecake_selenium.has_property(name, matcher=None)¶
- Parameters
matcher (Optional[Union[str, lemoncheesecake.matching.matcher.Matcher]]) –
- lemoncheesecake_selenium.is_displayed()¶
Test if
WebElementelement is displayed.- Returns
Matcherinstance
Utils¶
- lemoncheesecake_selenium.save_screenshot(driver, description=None)¶
Take and save screenshot as a lemoncheesecake report attachment.
- Parameters
driver (selenium.webdriver.remote.webdriver.WebDriver) –
WebDriverinstancedescription (Optional[str]) – an optional screenshot description
- lemoncheesecake_selenium.save_screenshot_on_exception(driver)¶
Context manager. Upon a
WebDriverExceptionexception, it saves a screenshot and re-raise the exception.- Parameters
driver (selenium.webdriver.remote.webdriver.WebDriver) –
WebDriverinstance