Hi,
I am using Appium PageFactory to define my page objects. A simplified example would be:
public class LoginPage {
@AndroidFindBy(accessibility = "test-Username")
@iOSXCUITFindBy(id = "test-Username")
private WebElement usernameTxtFld;
public LoginPage(AppiumDriver driver) {
PageFactory.initElements(new AppiumFieldDecorator(driver) , this);
}
public void enterUsername(String name) {
WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOf(element)).sendKeys(name);
}
}
In my test class, I am initialising my page objects as:
LoginPage loginPage = new LoginPage(driver);
I would like to understand what exactly is this PageFactory.initElements(new AppiumFieldDecorator(driver) , this); statment doing and why is it necessary in context of page objects? is this similar to calling driver.findElement(element)?
If I do not use this statement inside my constructor, then what happens? can i not interact with my elements in page object directly like usernameTxtFld.click()?
Further if I am later interacting with Web elements to perform methods such as click() or sendKeys() etc. then at which point the webelement is located by Appium? I am confused if it is located at the time of calling of PageFactory.init() method, or the element gets located only first when we interact with element using methods like click() etc.?
I want to set explicit waits when interacting with elements but I am not sure if explicit wait will be applied here or not when locating the element visibility:
WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOf(element)).click();
which approach is recommended for waiting here. My aim is to apply explicit waiting instead of implicit waiting. The above explicit waiting or something like @WithTimeOut annotation s below:
@WithTimeout(timeOut = yourTime, chronoUnit = yourTimeUnit)
@AndroidFindBy(accessibility = "test-Username")
@iOSXCUITFindBy(id = "test-Username")
private WebElement usernameTxtFld;
I could not understand it from the documentation below, so i would appreciate if you could help me understand the working of PageFactory.init() and the default waiting mechanisms before interacting with element.