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.
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.");
Using Selenium Methods:NOTE: Actually You can get locators by two ways in Appium (for id, name, className, and xpath).
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With