Reputation: 3
I have a hybrid app, which have the same features on iOS and Android. I want to use one repository to automate both platform. How can I identify the element for both platform without a if-else statement?
public class LoginPage extends BasePage {
String alertmsg;
@AndroidFindBy(xpath = "dynamic identifier....")
@iOSXCUITFindBy**(xpath= "//XCUIElementTypeStaticText[`name == \""+alertmsg+"\"`]")**
public WebElement alertBanner;
@AndroidFindBy(xpath = "//android.widget.EditText[@resource-id=\"username\"]")
@iOSXCUITFindBy(xpath = "//XCUIElementTypeTextField")
public WebElement usernameInputField;
@AndroidFindBy(xpath = "//android.widget.EditText[@resource-id=\"password\"]")
@iOSXCUITFindBy(xpath = "//XCUIElementTypeSecureTextField")
public WebElement passwordInputField;
@AndroidFindBy(xpath = "//android.widget.Button[@text=\"Log in\"]")
@iOSXCUITFindBy(xpath = "//XCUIElementTypeButton[@name='Log in' or @name='Anmelden']")
public WebElement loginBtn;
public void peformLogin(String username, String password){
usernameInputField.click();
usernameInputField.sendKeys(username);
passwordInputField.click();
passwordInputField.sendKeys(password);
loginBtn.click();
}
public void setAlertBannerTxt(String bannerTxt){
alertmsg = bannerTxt;
}
}
I tried to pass the concatenated xpath to the @iOSXCUITFindBy annotation, but it won't work, since the value is not present at the instantiation.
Upvotes: 0
Views: 138