Reputation: 806
I am developing Appium tests for an Android app. The problem happens during the login to facebook which works through a WebView. The login to facebook is necessary for the app login and the app registration. The login to facebook is in both cases (app login and app registration) the same, so I execute in both cases the same method:
private void logInAtFacebook(String email, String password) {
findElementWithTimeout(By.className("android.webkit.WebView"), 10);
Set<String> contextHandles = driver.getContextHandles();
for (String s : contextHandles) {
if (s.contains("WEBVIEW")) {
driver.context(s);
}
}
findElement(By.xpath("//input[@name='email']")).sendKeys(email);
findElement(By.xpath("//input[@name='pass']")).sendKeys(password);
findElement(By.xpath("//button[@name='login']")).click();
findElement(By.xpath("//button[@name='__CONFIRM__']")).click();
driver.context("NATIVE_APP");
}
It is weird, that the app login with facebook works, but the app registration with facebook crashes. The second last line in the above method...
findElement(By.xpath("//button[@name='__CONFIRM__']")).click();
...doesn't return, but the button is clicked in the UI. In other words, the execution stops at this line, so that the next line...
driver.context("NATIVE_APP");
... is never executed. I am really confused. Why is the same code working for the app login, but not for the registration?!
Iv'e copied the logs from Android Studio:
First, the last lines before it crashes during app registration:
01-30 14:18:25.016 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.103 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.184 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.260 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.322 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.401 24439-24450/de.blabla I/art: Background partial concurrent mark sweep GC freed 133(8KB) AllocSpace objects, 3(18MB) LOS objects, 13% free, 24MB/28MB, paused 9.861ms total 80.852ms
01-30 14:18:44.416 24439-24439/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:18:44.516 24439-24475/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df02443c260: ver 2 0 (tinfo 0x7df02440ce80)
01-30 14:18:44.633 24439-24439/de.blabla W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 24439
01-30 14:18:44.807 24439-24475/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df02443c260: ver 2 0 (tinfo 0x7df02440ce80)
01-30 14:18:45.111 24439-24475/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df02443c260: ver 2 0 (tinfo 0x7df02440ce80)
And the same lines of the working app login:
01-30 14:21:17.179 25078-25078/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:21:30.464 25078-25078/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:21:30.573 25078-25078/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:21:30.640 25078-25078/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:21:30.644 25078-25089/de.blabla I/art: Background partial concurrent mark sweep GC freed 156(6KB) AllocSpace objects, 2(12MB) LOS objects, 11% free, 30MB/34MB, paused 3.293ms total 143.091ms
01-30 14:21:30.717 25078-25078/de.blabla W/art: Attempt to remove non-JNI local reference, dumping thread
01-30 14:21:30.843 25078-25112/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df024436640: ver 2 0 (tinfo 0x7df02440c900)
01-30 14:21:31.002 25078-25078/de.blabla W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 25078
01-30 14:21:31.153 25078-25112/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df024436640: ver 2 0 (tinfo 0x7df02440c900)
01-30 14:21:31.564 25078-25112/de.blabla D/EGL_emulation: eglMakeCurrent: 0x7df024436640: ver 2 0 (tinfo 0x7df02440c900)
01-30 14:21:31.721 25078-25248/de.blabla ... *no it continues the test as it should*
Upvotes: 0
Views: 1099
Reputation: 806
I found an inconvenient workaround, but it works for now:
private void logInAtFacebook(String email, String password) {
findElementWithTimeout(By.className("android.webkit.WebView"), 10);
Set<String> contextHandles = driver.getContextHandles();
for (String s : contextHandles) {
if (s.contains("WEBVIEW")) {
driver.context(s);
}
}
findElement(By.xpath("//input[@name='email']")).sendKeys(email);
findElement(By.xpath("//input[@name='pass']")).sendKeys(password);
findElement(By.xpath("//button[@name='login']")).
driver.context("NATIVE_APP");
driver.findElementByAccessibilityId("Continue").click();
}
The problem had something to do with the click within the WebView, so I decided to go back to context "NATIVE_APP"
before the last click on the "Continue-Button" happens.
I'm still hoping for a better way to fix this!
Upvotes: 1
Reputation: 578
Have you tried sending app to background for 0 seconds just after "__ CONFIRM__" button is clicked?
Example:
findElement(By.xpath("//button[@name='login']")).click();
findElement(By.xpath("//button[@name='__CONFIRM__']")).click();
driver.runAppInBackground(0);
driver.context("NATIVE_APP");
Sometimes when tasks are done in background, you lose focus and you are not able to find, click or even make a screenshot with Appium...
Let me know if it worked
Upvotes: 1