FiXiT FiXiT - 1 month ago 7
Android Question

How to Automate facebook login test using Appium in Android

Hi I am new to Appium testing. I am testing facebook login in my app but the problem is I am not able to select the ids in UIAutomatorViewer as it will open the facebook webview.So I tried switching the context from NATIVE to WEB but still its not working.

Here is the code

public void fbLogin() throws InterruptedException {
System.out.println("IN FB_LOGIN TEST ");
this.getDriver().context("NATIVE_APP");// set the context to Native
_fb_sign_in_button.click(); // click on the fb button in native app
Thread.sleep(10000); // sleep
Set<String> contextNames = getDriver().getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW")) {
getDriver().context(contextName);
}
}
this.getDriver().findElementByXPath("//android.widget.EditText[@index='0']").sendKeys("abc@gmail.com");


can some one suggest whats going wrong?

Answer
  1. Facebook login through the app:

    • you can use UIAutomatorViewer to get view ids like here, from this discussion;
    • you don't even need to "getDriver().context(contextName);" in this case (but not sure);
  2. Facebook login through WebView:

    • you have to debug the WebView (as a browser) to get needed elements xpath;
    • with the elements xpath (in my case email field xpath was "//*[@id='u_0_2']") you can search for a field WebElement element = driver.findElementByXPath("//*[@id='u_0_2']") and then click on it or type something whatever;
  3. Don't have any solution if it's in the browser.

Comments