Script Examples

Script Examples #

Locating elements #

By using CSS selector

UIElement element = E(byCssSelector("your.Id"));

By using ID

UIElement element = E(byId("your.Id"));

By using xPath

UIElement element = E(byXpath("//some"));

It is possible to use all strategies by switching back and forth.

public void testUIWithLoadero() {
    // Example of element verification
    open("https://www.testdevlab.com");
    // Wait 10 seconds until page is visible
    E(byCssSelector("#__next")).waitFor(10).untilIsVisible();

    // Take a screenshot
    E(byCssSelector("#__next")).saveScreenshot("website_testdevlab.png");

    // Wait up to defined timeout for "Approach" to be visible and click it
    E(byCssSelector("[class*='Menu_item']:nth-of-type(2)")).waitFor(10).untilIsVisible().click();

    E(byCssSelector("[class*='TestDevLab_comparison']")).scrollTo();
    // Check if TestDevLab comparison is visible, otherwise throw error
    E(byCssSelector("[class*='TestDevLab_comparison']")).waitFor(10).untilIsVisible();
    E(byCssSelector("#__next")).saveScreenshot("testdevlab_comparison.png");
}
public void testUIWithLoadero() {
    // Example of locating elements using CSS selector
    open("https://www.bing.com")

        // Wait 10 seconds until page is visible
        .setElement(byCssSelector(".dimmer")).waitFor(10).untilIsVisible()

        // Save a screenshot of https://bing.com website
        .saveScreenshot("website_bing.png")

        // Find search bar element
        .setElement(byCssSelector("[type=search]"))

        // Type "loadero" in it
        .sendKeys("loadero")

        // Find search button and click it
        .setElement(byCssSelector("#search_icon")).click()

        // Wait for search results to become visible
        .setElement(byCssSelector("[aria-label='Search Results']")).waitFor(10).untilIsVisible()
        
        // Take a screenshot of the search results
        .saveScreenshot("loadero_search_results.png");
}

Using TestUI Element Assertion methods #

element.(shouldBe()/shouldHave())
    (.not())
        .visible()
        .enabled()
        .Exists()
        .exactText("someText")/containText("")/containNoCaseSensitiveText("")
        .value("someValue")
        .attribute("attributeName").equalTo("value")
        .theAttribute("attribute")
element.waitFor(timeInteger)
    .untilIs(Not)Visible()
    .untilIs(Not)Enabled()
    .until(Not)Exist()
    .untilHas(Not)Text("someText")
    .untilHas(Not)Value("someValue")
    .untilHas(Not)Attribute("someAttribute")

You can find detailed descriptions and more examples in TestUI wiki