πŸ§ͺShould / Expected Conditions

Pylenium provides fluent syntax to check for expected conditions.

Pylenium's Driver, Element, and Elements objects each have a Should API that allows you to write fluent-like code to wait and check for any expected conditions.

For example, to check that an element is visible on the webpage, you would do this:

Pylenium
def test_element_is_visible(py):
    py.visit("https://qap.dev")
    assert py.get("a[href='/about']").should().be_visible()

With Selenium, you normally use the ExpectedConditions class:

Selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait


def test_element_is_visible():
    driver = webdriver.Chrome()
    wait = WebDriverWait(driver, timeout=10)
    
    driver.get("https://qap.dev")
    element = wait.until(EC.visibility_of_element_located(By.CSS_SELECTOR, "a[href='/about']"))
    assert element.is_displayed()

Similar Pages

Last updated