Robotium : Assert Text Containing Special Characters In Android Application While using solo.waitForText() and solo.searchText()
|Robotium Provides some functions to assert texts that is reflected on the screen as a part of it or as a toast message. But the problem arises when Text contains some special characters in it. Assertion fails for verifying special characters in the Text.
For Example :
Suppose we want to verify Text : “Password(s) cannot be empty.” ,which renders as a toast message on the screen.
This text contains braces & dot as special characters .So if we want to assert this our Code may go like:
assertTrue(“Message not shown”,solo.searchText(“Password(s) cannot be empty.“));
But this assertion in this way fails and error message “Message not shown” may reflect in the Log or in generated reports ,which indicates the the desired text “Password(s) cannot be empty.” is not reflected on the screen,while “Password(s) cannot be empty.” is actually reflected on the screen as a toast message.
Cause : The methods solo.searchText() and solo.waitForText() accept regex pattern.
Solution :
We have to use Pattern.quote(“Password(s) cannot be empty.”) for this purpose.
So the Code which will successfully assert Text containing special characters :
assertTrue(“Message not shown”,solo.searchText(Pattern.quote(“Password(s) cannot be empty.“)));
- Bring the auto Sync magic of Protractor to Selenium with Java - October 23, 2015
- Restarting Appium Server could improve various server freezing issues and may improve execution time - January 20, 2015
- Appium with iOS 8 and XCode 6 : What’s new? - November 5, 2014
- REST API automation testing using Apache HttpClient – The Approach - October 3, 2014
- An Overview of mobile application : Moving forward to automation - October 1, 2014
- An introduction to REST - September 29, 2014
- Run ChromeDriver with Chrome Driver Service to reduce script execution time significantly - September 26, 2014
- Selenium WebDriver – Get Cookies from an existing session and add those to a newly instantiated WebDriver browser instance. - September 26, 2014
- Simulate Copy Paste action using Java Robot and Clipboard class - September 26, 2014
- Android : How to test if Android Application has memory leaks - August 11, 2014