在经过ruby+webdriver+rspec作自动化测试的时候,为了便于观察用例执行状况,我基本上都会用web
rspec XX.rb --format doc -o result.logruby
若是遇到失败的状况,咱们想作一些截图操做,而且把截图信息也打印到报告中怎么办呢?经过查看了rspec打印日志到报告中的源码,了解到了一个方法能够打印日志到rspec的报告文件中。函数
1 #设置打印方法 2 def output 3 RSpec.configuration.reporter 4 end 5 6 #自动截图功能 7 def save_failure_screenShot 8 t = Time.now.strftime("%Y%m%d%H%M%S") 9 @dr.save_screenshot("../screenshot/#{t}.png") 10 Dir.chdir('../') 11 screenshot_path = Dir.pwd 12 output.message("Please refer the follow image file:") 13 output.message screenshot_path + "/screenshot/#{t}.png" 14 end
这样在用例中去调用自动截图的函数的时候,图片的信息就会同时打印到rspec的报告文件中。测试
文笔真是愈来愈差了,但愿能帮到你们!spa