Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to locate validation of android native app after many efforts in automation

I am doing automation of Android native app and want to verify login validation with text. When I tried to pick it using Appium inspector and Uiautomator. Both unable to locate validation section so hard to pick it.

enter image description here

I tried code from different forums and Appium discussion but still unable to find that validation via automation. I've tried the following:

Code 1

JavascriptExecutor js = (JavascriptExecutor)driver;

WebElement field = driver.findElement(By.xpath("//android.widget.EditText[@text='Enter mobile number']"));
// Boolean is_valid = (Boolean)js.executeScript("return arguments[0].checkValidity();", field);

try {
    String message = (String) js.executeScript("return arguments[0].validationMessage;", field);
} catch (Exception E) {

Output :

Exception : org.openqa.selenium.WebDriverException: Method has not yet been implemented

Code 2

public boolean IsValidationFired() {
    if(driver.getPageSource().contains("Invalid")) {
        System.out.println("PASS");
    } else {
        System.out.println("FAIL");
    }
}

Output :

Print = FAIL

I am not sure if it is javascript popup or native app popup or toast message.But looking to inspect it and verify via automation.

Update

Code used to fire validation is : contactnu.setError("Invalid phone number.");

like image 202
Helping Hands Avatar asked Aug 31 '17 15:08

Helping Hands


People also ask

How many types of locators are there in Appium?

Using Selenium Methods:NOTE: Actually You can get locators by two ways in Appium (for id, name, className, and xpath).

How do I find a mobile app locator?

Know your locators For Android it is the element's content-desc attribute. Native element identifier. resource-id for android; name for iOS. Search for element by using the value of the text attribute.

What is use of Findelements () method in Appium test script?

When using Appium findElement by XPath, the program analyzes the XML structure of the app and locates a particular element relative to other elements. In fact, originally this strategy was developed to navigate XML data in order to locate unique UI elements. Remember that XPath selectors are not cross-platform.

How do I get an Elementid in Appium?

You can find the ID of an element using android uiautomatorviewer. just go to your SDK tools folder D:\Android\android-sdk\tools, here you can find uiautomatorviewer. Open it and take screen shots of your activity and find the id, class, package of any element.


1 Answers

I have been doing Android App testing automation from last 2 years. I have encountered the same issue many times. Unfortunately, uiAutomator does not detect these kind of elements so we can't perform any actions on such elements.

Appium internally sends command to uiAutomator and uiAutomatar performs the actions on the device. uiAutomator can perform actions if uiAutomator sees those elements.

So I suggest you to don't spend much time on using java script or xPath because I have already tried hose solutions but none of them worked.

However, There is one solution which is very lengthy. You can take screen shot of this screen from the device and store it into your machine at run time and check whether that text "Invalid phone number." is available in the image using SIKULI. OR else you can ask developer to change the error message to some visible component in the uiAutomator. Hope this helps you.

like image 124
Vinod Avatar answered Sep 20 '22 15:09

Vinod