Script Examples

Script Examples #

Locating elements #

By using CSS selector

element = e(driver, "css", ".some-class")

By using xPath

element = e(driver, "xpath", "//some-element")

By using ID

element = e(driver, "id", "some-id")

By using class name

element = e(driver, "className", "some-class")

By using name

element = e(driver, "name", "some-name")
def test(driver: TestUIDriver):
    # Example of verifying the pages title

    def move_to_element(driver, element):
        # Moves element in view.
        # param: driver: TestUIDriver
        # param: element: TestUIElement
        actions = driver.actions()
        actions.move_to_element(element.get_element()).perform()

    testdevlab_title = "We are experts in Software Quality Assurance. - TestDevLab"

    driver.navigate_to("https://www.testdevlab.com/")

    # Verify page title    
    if driver.get_driver().title != testdevlab_title:
        driver.set_error("page title does not match expected")
        driver.raise_errors()

    # Take screenshot of landing page
    driver.save_screenshot("website_testdevlab.png")

    # Navigate to careers page
    e(
        driver, "css", ".sections div:nth-child(4).sub-menu"
    ).wait_until_visible().click()
    e(
        driver, "css", "a[href^='/careers']"
    ).wait_until_visible().click()

    # Take screenshot of careers page
    driver.save_screenshot("careers_page.png")

    move_to_element(
        driver, e(driver, "xpath", "//h3[contains(text(), 'Development')]")
    )

    # Take screenshot of open positions page
    driver.save_screenshot("testdevlab_open_positions.png")
def test(driver: TestUIDriver):
    # Example of locating elements using CSS selector
    driver.navigate_to("https://www.google.com")

    # Wait 10 seconds until "body" element is visible and take a screenshot
    e(driver, "css", "body").wait_until_visible(seconds=10)
    driver.save_screenshot("website_google.png")

    # Find search bar element and type Loadero into it
    e(driver, "css", "input[type=text]").send_keys("Loadero")

    # Find search button and click it
    e(driver, "css", "input[value~='Google']").click()

    # Wait 10 seconds until search results are visible and take a screenshot
    e(driver, "css", "div#rso").wait_until_visible(seconds=10)
    driver.save_screenshot("search_results.png")

Using Py-TestUI Element Assertion methods #

element.
    (.no())
        .is_visible()
        .is_visible_in(seconds)
        .visible_for(seconds)
        .wait_until_visible(seconds, log)
        .wait_until_attribute(attr, text, seconds)
        .wait_until_contains_attribute(attr, text, seconds)
        .wait_until_contains_sensitive_attribute(attr, text, seconds, log)

You can find detailed descriptions and more examples in Py-TestUI wiki