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 "body" element is visible
E(byCssSelector("#root")).waitFor(10).untilIsVisible();
// Select "body" element and take a screenshot
E(byCssSelector("body")).saveScreenshot("website_testdevlab.png");
// Check if the "Company" element is visible
// Wait up to defined timeout for "Company" element to be visible and click it
E(byCssSelector(".sections div:nth-child(4).sub-menu")).waitFor(10).untilIsVisible().click();
// Wait up to defined timeout for "Careers" to be visible
E(byCssSelector("a[href^='/careers']")).waitFor(10).untilIsVisible().click();
E(byCssSelector(".container .job-position-intro:nth-child(3)")).scrollTo().view("");
// Check if career position is visible, otherwise log error
E(byCssSelector(".container .job-position-intro:nth-child(3)")).shouldHave().visible();
E(byCssSelector("body")).saveScreenshot("testdevlab_career_positions.png");
}
public void testUIWithLoadero() {
// Example of locating elements using CSS selector
open("https://www.google.com")
// Wait 10 seconds until "body" is visible
.setElement(byCssSelector("body")).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