I use Selenium WebDriver to implement functional tests for some of the projects I worked with. I am trying to use a page object design template with a Factory page to separate my locators. I also created a static WaitTool (singleton) object that implements several wait methods with additional timeout parameters.
My current problem is that I would like to use my wait methods before PageFactory tries to initialize WebElements. The reason I want to wait is because PageFactory might try to initialize page elements before they are available on the page.
Here is an example PageObject:
public class SignInPage extends PageBase { @FindBy(id = "username") @CacheLookup private WebElement usernameField; @FindBy(id = "password") @CacheLookup private WebElement passwordField; @FindBy(name = "submit") @CacheLookup private WebElement signInButton; public SignInPage(WebDriver driver) { super(driver); WaitTool.waitForPageToLoad(driver, this);
Here is an example of TestObject:
public class SignInTest extends TestBase { @Test public void SignInWithValidCredentialsTest() { SignInPage signInPage = PageFactory.initElements(driver, SignInPage.class); MainPage mainPage = signInPage.signInWithValidCredentials("sbrown", "sbrown"); assertThat(mainPage.getTitle(), is(equalTo(driver.getTitle()))); } }
I try to put my logic in the page object (including expectations) as much as possible, as this makes the test cases more readable.
source share