0

This may be simple question for the experts. I am a beginner in appium and all these days i have been trying to make my test script for printing a page title in my script. Here is the part of My code below: i am unable to print the page title and then do a validation. Can someone help?

driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
      System.out.println(driver.getRemoteAddress()); 
}

public void ApkPushValidation() throws Exception {

Assert.assertEquals("Verify your phone number", driver.findElementByName("Verify your phone number").getText());

    driver.wait(5000);
    String i = driver.getTitle();
    System.out.println(i);


if (driver.getTitle().equals("Verify your phone number") ) {

    System.out.println("app installation is passed");

} else {

System.out.println("App installation is failed");

}

//System.out.println(i);---> my expectation is that this will print out Verify your Phone number. However this is not printing the page title.
Smajl
  • 7,555
  • 29
  • 108
  • 179

4 Answers4

1

Use UIAutomatorViewer to find out the xpath of the title.

use the following website for example on how to use the x-path. "http://software-testing-tutorials-automation.blogspot.ca/2015/10/ui-automator-viewer-get-android-app.html"

Salman Arshad
  • 59
  • 1
  • 14
0

I think that driver.getTitle() is a method for Web page interaction, not meant for Native apps. I would suggest to use XPath or some other element locator to find the title.

0

Instead if getTitle(); try to use xPath, name or Id available for the title. Use Appium inspector or UI automator to locate that element and change it like this:

String i = driver.findElementById("Your ID").getText();
if (i.equals("Verify your phone number") ) {
    System.out.println("app installation is passed");

} else {

System.out.println("App installation is failed");

}
Gaurav
  • 1,332
  • 11
  • 22
0

What you probably what to perform should be done using the following piece of code :

WebElement title = driver.findElementByName("Verify your phone number"); // defining the element only once for multiple use
// different locator strategies could be used for locating the element above

Assert.assertEquals("Verify your phone number", title.getText());  
driver.wait(5000);
String i = title.getText();
System.out.println(i);    
if (i.equals("Verify your phone number") ) {
    System.out.println("app installation is passed");
} else {
    System.out.println("App installation is failed");
}

More on driver.getTitle() : It has been inherited from RemoteWebDriver and possibly should return the title of a webpage/webview instead of an native application view which seems to be your case.

Note: would add more to this about getTitle() as I get to know.

Naman
  • 27,789
  • 26
  • 218
  • 353