Synchronizing methods

Earlier, the login method was introduced, and in that method, we will now call one of the synchronization methods waitFor(title, timer) that we created in the utility classes. This method will wait for the login page to appear with the title element as defined. So, in essence, after the URL is loaded, the login method is called, and it synchronizes against a predefined page title. If the waitFor method doesn't find it, it will throw an exception, and the login will not be attempted.

It's important to predict and synchronize the page object methods so that they do not get out of "sync" with the application and continue executing when a state has not been reached during the test. This becomes a tedious process during the development of the page object methods, but pays big dividends in the long run when making those methods "robust".  Also, users do not have to synchronize before accessing each element. Usually, you would synchronize against the last control rendered on a page when navigating between them.

In the same login method, it's not enough to just check and wait for the login page title to appear before logging in; users must also wait for the next page to render, that being the home page of the application. So, finally, in the login method we just built, another waitFor will be added:

public void login(String username,
String password)
throws Exception {

BrowserUtils.waitFor(getPageTitle(),
getElementWait());

if ( !this.username.getAttribute("value").equals("") ) {
this.username.clear();
}

this.username.sendKeys(username);

if ( !this.password.getAttribute( "value" ).equals( "" ) ) {
this.password.clear();
}

this.password.sendKeys(password);

submit.click();

// exception handling
if ( BrowserUtils.elementExists(error,
Global_VARS.TIMEOUT_SECOND) ) {

String getError = error.getText();
throw new Exception("Login Failed with error = " + getError);
}

// wait for the home page to appear
BrowserUtils.waitFor(new MyAppHomePO<WebElement>().getPageTitle(),
getElementWait());
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.183.137