2

Tried the login use case with appium for android native app. But button click not working. But I am getting all test passed.Tried with mobile driver also.

        @BeforeClass
        public static void setUp() throws MalformedURLException
        {
            DesiredCapabilities capabilities=new DesiredCapabilities();
        capabilities.setCapability("BROWSER_NAME","Chrome");
            capabilities.setCapability("VERSION","4.3");
            capabilities.setCapability("deviceName","SGH-T999L");
            capabilities.setCapability("platformName","Android");
            capabilities.setCapability("appPackage","org.odk.collect.android");
            capabilities.setCapability("appActivity","com.fieldforce.android.activities.LoginActivity");
            webDriver=new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

    //        webDriver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
        }
        @Test
        public void testLogin() throws Exception
        {
    //        webDriver.switchTo().window("NATIVE_APP");
            WebDriverWait wait = new WebDriverWait(webDriver, 10);
            WebElement  userName= webDriver.findElement(By.id("txt_username"));
            userName.sendKeys("733894");
            WebElement  password= webDriver.findElement(By.id("txt_password"));
            password.sendKeys("Pass@123");

          WebElement  login_button=  webDriver.findElement(By.id("org.odk.collect.android:id/btn_login"));

            wait.until(ExpectedConditions.visibilityOf(login_button));
            login_button.click();



        }

 @AfterClass
    public static void tearDown()
    {
        webDriver.quit();
    }
g_m
  • 37
  • 1
  • 7

5 Answers5

1

Of course the test will pass, as you are just trying to click on Login Button, it doesn't matter for your test case whether it should pass or fail unless you add some Assert after clicking on login button.

Try adding some wait after click on login

driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

And then try asserting something in @test for method testLogin like add below two statement in the end, and make them compatible with locator you get after login

Actualtext = driver.findElement(By.xpath("locator to verify after login")).getText();
Assert.assertEquals(Actualtext, "assert Text");
Gaurav Lad
  • 1,788
  • 1
  • 16
  • 30
1

I got the same issue.

Please make sure your submit button(UI) is not covered by the phone keyboard.

If it covers, Solution : hide the keyboard before run the click [.click()] function.

keyboard hide code is here How to dismiss the keyboard in appium using Java?

Reason: Coz Appium clicks the button using x&y UI coordinates and if the keyboard covers the submit button it clicks on the keyboard not on the button.

Community
  • 1
  • 1
Lahiru Pinto
  • 1,621
  • 19
  • 20
1

In my case I've also tried similar button clicking with no result. I've realized that I wasn't clicking the right element.

To verify what I was clicking I've printed element's Text and TagName:

List<MobileElement> views = driver.findElements(By.className ("android.widget.TextView"));
        System.out.println("1: "+views.get(2).getText());
        System.out.println("2: "+views.get(2).getTagName());
        views.get(2).click();

Output was:

1: OK

2: android.widget.TextView

My classNames I got through UI Automator Viewer, Android/Sdk/tools/bin/uiautomatorviewer application.

Although, before list's getting you could temporarily use Thread.sleep(5000); with your own values to check assumption about slow element loading and replace it with proper time waiting method if required in case of time problem.

Sometimes a button could have multilayer structure and it is required to get the right layer you could click. In my case there were two layers.

Community
  • 1
  • 1
Gryu
  • 2,102
  • 2
  • 16
  • 29
1

As your keyboard hiding the Login button, so hide the keyboard by,

driver.hidekeyboard();
Angel F Syrus
  • 1,984
  • 8
  • 23
  • 43
0

Would suggest using

WebElement  login_button=  webDriver.findElement(By.id("btn_login")); //as used for other WebElement

Also i believe a general login page shall ideally be having the login visible, if that not be the case, you might want to perform a scroll down on the page instead of

wait.until(ExpectedConditions.visibilityOf(login_button));

PS - If you are receiving any error/exception post this. Please add to the question and let know.

Naman
  • 27,789
  • 26
  • 218
  • 353