Understanding loadable components

The loadable component is an extension of the PageObject pattern. The LoadableComponent class in the WebDriver library will help test-case developers make sure that the page or a component of the page is loaded successfully. It tremendously reduces the efforts to debug your test cases. The PageObject should extend this LoadableComponent abstract class and, as a result, it is bound to provide an implementation for the following two methods:

protected abstract void load()
protected abstract void isLoaded() throws java.lang.Error

The page or component that has to be loaded in the load() and isLoaded() methods determines whether the page or component is fully loaded. If it is not fully loaded, it throws an error.

Let's now modify the AdminLoginPage PageObject to extend the LoadableComponent class and see how it looks, using the following code:

public class AdminLoginPageUsingLoadableComponent extends LoadableComponent<AdminLoginPageUsingLoadableComponent> {

WebDriver driver;

@FindBy(id = "user_login")
WebElement email;

@FindBy(id = "user_pass")
WebElement password;

@FindBy(id = "wp-submit")
WebElement submit;

public AdminLoginPageUsingLoadableComponent(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}

public AllPostsPage login(String username, String pwd) {
email.sendKeys(username);
password.sendKeys(pwd);
submit.click();
return PageFactory.initElements(driver, AllPostsPage.class);
}

@Override
protected void load() {
driver.get("http://demo-blog.seleniumacademy.com/wp/wp-admin");
}

@Override
protected void isLoaded() throws Error {
Assert.assertTrue(driver.getCurrentUrl().contains("wp-admin"));
}
}

The URL that has to be loaded is specified in the load() method and the isLoaded() method validates whether or not the correct page is loaded. Now, the changes that are to be done in your test case are as follows:

AdminLoginPageUsingLoadableComponent loginPage = new AdminLoginPageUsingLoadableComponent(driver).get();

The get() method from the LoadableComponent class will make sure the component is loaded by invoking the isLoaded() method.                                                

..................Content has been hidden....................

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