The Appium driver does not wait to identify elements in the hybrid application and time out. Then the test fails. Here is my Java code for testing a hybrid application. Here I used the TestNG structure. First, I switch to the web context of the application and make an explicit wait until the element is visible.
@BeforeMethod
public void Setup() throws MalformedURLException
{
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
cap.setCapability(MobileCapabilityType.APP_PACKAGE, "com.example.touch");
cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.example.touch.MainActivity");
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
}
@Test
public void LoginTest() {
java.util.Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
if (contextName.contains("WEBVIEW")){
driver.context(contextName);
}
}
try {
System.out.println("uy");
Thread.sleep(10000);
} catch (InterruptedException e) {
}
WebDriverWait wait;
wait = new WebDriverWait(driver,60);
wait.until(ExpectedConditions.visibilityOf(driver.findElementByXPath("*[@id='login-page']####")));
driver.findElementByXPath("//*[@id='login-page']####").sendKeys("abc");
driver.findElementByXPath("//*[@id='login-page']####").sendKeys("xyz");
driver.findElementByXPath("//*[@id='login-button']####").click();
}
@AfterMethod
public void End() {
driver.quit();
}
This is the error message I get from the appium server after running the TestNG test.
info: [debug] [BOOTSTRAP] [debug] * [@id = 'login-page']/div [1]/div [5]/div/input XPATH contextId: multiple: false info: [debug] [BOOTSTRAP] [debug] : { "status": 7, "value": " , ." } info: [debug] 1527. . info: [debug] : { "status": 7, "value": { "message": " .", "origValue": " , ." }, "SessionId": "51df32dc-3fdf-4b84-95f2-dd020590b861" } info: < - POST/wd/hub/session/51df32dc-3fdf-4b84-95f2-dd020590b861/ 500 1527,819 - 230 info: → DELETE/wd/hub/session/51df32dc-3fdf-4b84-95f2-dd020590b861 {}