LeanFT WaitUntil

An example of how to use LeanFT WaitUntil for waiting until object is loaded.

Background :

Suppose you want to verify that when entering a value in a search box, a suggestion box opens. The only way to identify the suggestion box is via a CSS selector.


This example shows how to:
– fire an event that triggers the opening of a suggestion box
– identify the suggestion box using a CSS selector
– use WaitUntil to ensure that the suggestion box opens before continuing
– use Assert to validate that the suggestion box opens
– use try-catch to add a message to the report if the validation fails

@Test public void verify_SearchSuggestionsAreOpenUponUserInput() throws Exception{ //Launch the Chrome browser and navigate to the web site. Browser browser = BrowserFactory.launch(BrowserType.CHROME); browser.navigate("http://www.google.com"); // Use try-catch to add a warning to the run report if the assert validation fails. try { // Enter the value "LeanFT" in the search box. EditField search = browser.describe(EditField.class,new EditFieldDescription.Builder().name("q").build()); search.setValue("LeanFT"); // Simulate a single key down event to trigger the opening of the suggestion box. search.fireEvent(EventInfoFactory.createEventInfo("onkeydown")); // Wait until the suggestion box opens. WebElement suggestions = browser.describe(WebElement.class,new CSSDescription(".sbsb_a")); WaitUntilTestObjectState.waitUntil(suggestions,new WaitUntilEvaluator(){ public boolean evaluate(WebElement suggestionBox){ try{ return suggestionBox.exists() && suggestionBox.isVisible(); } catch(Exception e){ return false; } } }); // Enclosing the Assert method in a try-catch statement ensures the application // does not throw a runtime error if the Assert returns false. // Use Assert to verify that the suggestion box exists. assertTrue(suggestions.exists()); assertTrue(suggestions.isVisible()); } catch(AssertionError e){ // Adds a step to the results report on failure. Reporter.reportEvent("verify_SearchSuggestionsAreOpenUponUserInput","Failed during validation",Status.Failed, e); throw e; } finally{ browser.close(); } }


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s