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.google.com")
        // Wait 10 seconds until page is visible
        .setElement(byCssSelector("[action=\"/search\"]")).waitFor(10).untilIsVisible()
        // Save a screenshot of https://google.com website
        .saveScreenshot("website_google.png")
        // Find search bar element
        .setElement(byCssSelector("input[type=text]"))
        // Type "loadero" in it
        .sendKeys("loadero")
        // Find search button and click it
        .setElement(byCssSelector("input[value~='Google']")).click()
        // Wait for search results to become visible
        .setElement(byCssSelector("div#rso")).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