Krunal Patel
Krunal Patel

Reputation: 35

How to capture error message text in appium

Screenshot of error message

UI Automator Capture

Error message is against EditText field. We don't have any direct locator available which points to error message. Can anyone suggest what alternate we have to handle this in appium.

Upvotes: 0

Views: 1743

Answers (2)

Poornima Hegde
Poornima Hegde

Reputation: 163

Try this method if you are not able to assert Error message against EditText field.

  1. Trigger text message on the screen
  2. Capture screenshots
  3. Convert image to text file

    def assettoast(string)
     sname = (0...8).map { (65 + rand(26)).chr }.join
     $driver.driver.save_screenshot("#{sname}")
    
     #Make sure tesseract is installed in the system. If not you can install using "brew install tesseract" in mac
     system ("tesseract #{sname} #{sname}")
    
     text_file="#{sname}.txt"
     var= get_string_from_file(string, text_file)
     raise if var != true
    end
    
  4. Check whether error message is there in text file

    def get_string_from_file(word, filename)
     File.readlines(filename).each do |line|
     return true if line.include?(word)
     end
    end
    

Upvotes: 3

dmle
dmle

Reputation: 3658

There is no you will get using uiautomatorviewer and Google's original UiAutomator. Check old thread

However you may try Appium own implementation UiAutomator2 and Appium desktop inspector, maybe it will parse error.

Otherwise there is new appium end-point to compare images:

/session/:sessionId/appium/compare_images

You can use it to verify the error on screen

Upvotes: 0

Related Questions