Pylenium.io
GitHub ↗️
  • Welcome to Pylenium
  • Getting Started
    • 1. Virtual Environments
    • 2. Setup pytest
    • 3. Project Structure with pytest
    • 4. Writing Tests with Pylenium
  • Guides
    • πŸ“ŠVisualize Test Results with Allure
    • πŸ“Logging
    • 🟨Run Tests in Containers
    • πŸ”€Run Tests in Parallel
    • πŸ§ͺShould / Expected Conditions
    • 🌐Script with Standalone Pylenium
  • CLI
    • πŸ’»Pylenium CLI
    • πŸ“ŠAllure CLI
  • Configuration
    • πŸ“„pylenium.json
    • πŸš—Driver
    • πŸ–₯️Viewport
  • Fixtures
    • ↗️api
    • πŸͺ“axe
    • πŸ₯Έfake
    • βœ…py
    • β˜‘οΈpyc
    • ❌pys
  • Driver Commands
    • Overview
    • πŸ—ΊοΈNavigation
      • go
      • quit
      • reload
      • visit
    • πŸ”Find Elements
      • contains
      • find
      • findx
      • get
      • getx
    • ⏱️Driver.should()
    • 🌐Browser
      • execute_script
      • execute_async_script
      • maximize_window
      • screenshot
      • scroll_to
      • title
      • url
      • window_handles
      • window_size
      • viewport
    • πŸͺCookies
      • delete_all_cookies
      • delete_cookie
      • get_all_cookies
      • get_cookie
      • set_cookie
    • πŸ”„Switch To
      • default_content
      • frame
      • frame_by_element
      • parent_frame
      • window
      • new_window
      • new_tab
    • πŸ“ŠWeb Performance
      • Performance API
      • CDP Performance
    • fake
    • wait
    • webdriver
  • Element Commands
    • πŸ”Find Elements
    • ⏱️Element.should()
    • πŸ‘Actions
      • check
      • clear
      • click
      • deselect
      • double_click
      • drag_to
      • drag_to_element
      • focus
      • hover
      • right_click
      • scroll_into_view
      • select_by_index
      • select_by_text
      • select_by_value
      • submit
      • type
      • uncheck
      • upload
    • πŸ”’Element Data
      • css_value
      • get_attribute
      • get_property
      • tag_name
      • text
      • is_checked
      • is_displayed
      • is_enabled
      • is_selected
    • πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦Family
      • children
      • parent
      • siblings
    • open_shadow_dom
    • screenshot
    • webelement
  • Elements Commands
    • ⏱️Elements.should()
    • first
    • length
    • last
    • is_empty
  • Contribute
    • Clone and Setup the Project
Powered by GitBook
On this page
  • Expectations
  • Syntax
  • Examples
  • Yields
  1. Driver Commands

Driver.should()

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>

Examples

.contain_title()
def test_title_contains(py):
    py.visit("https://qap.dev")
    assert py.should().contain_title("QA")
.contain_url()
def test_url_contains(py):
    py.visit("https://qap.dev")
    assert py.should().contain_url("www.qap.dev")
.have_title()
def test_title_matches(py):
    py.visit("https://qap.dev")
    assert py.should().have_title("QA at the Point")
.have_url()
def test_url_matches(py):
    py.visit("https://qap.dev")
    assert py.should().have_url("https://www.qap.dev/")
.not_find()
def test_page_does_not_have_element(py):
    py.visit("https://qap.dev")
    assert py.should().not_find("#zaboomafoo")
.not_findx()
def test_page_does_not_have_element(py):
    py.visit("https://qap.dev")
    assert py.should().not_findx("//*[@id='zaboomafoo']")
.not_contain()
def test_text_should_not_be_present_on_page(py):
    py.visit("https://qap.dev")
    assert py.should().not_contain("zaboomafoo")
Customize timeout
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.

  • bool - for the Find Element expectations.

PreviousgetxNextBrowser

Last updated 1 year ago

⏱️