如何捕获Appium中的错误消息文本

时间:2018-07-06 13:42:55

标签: java appium

Screenshot of error message

UI Automator Capture

错误消息针对EditText字段。我们没有任何指向错误消息的直接定位器。任何人都可以建议我们必须用什么替代方法来解决这个问题。

2 个答案:

答案 0 :(得分:3)

如果您不能对EditText字段断言错误消息,请尝试此方法。

  1. 在屏幕上触发短信
  2. 捕获屏幕截图
  3. 将图像转换为文本文件

    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. 检查文本文件中是否存在错误消息

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

答案 1 :(得分:0)

没有人会使用uiautomatorviewer和Google的原始UiAutomator。检查旧的thread

但是您可以尝试Appium自己的实现UiAutomator2和Appium desktop inspector,它可能会解析错误。

否则,会有新的appium端点来比较图像:

/session/:sessionId/appium/compare_images

您可以使用它来验证屏幕上的错误