Howto automate webview facebook login with appium?

0
down vote
favorite
I´m trying to write an appium functional test in node.js. The problem comes when I switch to the webdrivers context.

Here are my contexts:

[ ‘NATIVE_APP’, ‘WEBVIEW_com.******.***.development’ ]
This is the test case code:

it("should find facebook login button", function () {

return driver
  .elementById('facebook_login_button')
  .click()
  .sleep(10000)
  .contexts()
  .then(function (ctxs) {
    console.log(ctxs);
    return driver.context(ctxs[ctxs.length - 1]);
  })
  .elementByName('email')
  .sendKeys('test.*****@gmail.com')
  .sleep(5000)
  ;
});

And the output error from appium server:

error: Chromedriver: Error: An unknown server-side error occurred while processing the command. (Original error: unknown error: Device emulator-5554 is not online (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 10.0 x86_64)) at JWProxy.command$ (lib/proxy.js:149:15) at tryCatch status: 13, value: { message: ‘unknown error: Device emulator-5554 is not online\n (Driver info: chromedriver=2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a),platform=Windows NT 10.0 x86_64)’ }, httpCode: 200 }

Thanks in advance.

Just updated chromedriver to version 2.20 and everything works

Click Facebook login button which is native :

wd.findElement(By.id("com.hathy.fblogin:id/login_button")).click();

Switch to webview context :

//here we getting the list of context
Set<String> contextHandles = wd.getContextHandles();
for (String s : contextHandles) {
System.out.println("Context : " + s);
//if context contains webview then set the webview context
if (s.contains("WEBVIEW")) {
wd.context(s);
}
}

Do Facebook Login Flow in webview :

wd.findElement(By.xpath()).sendKeys("//input[@name='email']""<your_emailid>");
wd"//input[@name='pass']"".findElement(By.xpath()).sendKeys(<your_password>"); // test password
wd.findElement(By.xpath("//button[@name='login']")).click();
WebDriverWait driverWait = new WebDriverWait(wd, 10);
driverWait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@name='__CONFIRM__']"))); // waiting for the element to be clickable
System.out.println(wd.getPageSource()); // get the page source 
wd.findElement(By.pathx("//button[@name='__CONFIRM__']")).click(); //  this step login process is done.

Come back to Native view :

// here i need to get the context again
Set<String> contextHandles2 = wd.getContextHandles();
for (String s : contextHandles2) {
System.out.println("Context : " + s);
if (s.contains("NATIVE_APP")) {
wd.context(s);
}
}

Youtube video : https://www.youtube.com/analytics?o=U#dt=nt,fe=17092,fr=lw-001,fs=17065;fc=0,fcr=0,fi=v-AcBzbhQgDis,r=realtime,rsc=2