1

我正在使用葫芦对 iOS 本机应用程序进行测试。calabash 在场景失败时截取屏幕截图并将其命名为 screenshot_0 并将其保存在我的项目目录中。我想知道如何更改屏幕截图的路径以及如何更改文件名。

我使用了以下内容:

dir_path = "/Users/bmw/Desktop/Calabash/screenshots "
unless Dir.exist?(dir_path)
    Dir.mkdir(dir_path,0777)
    puts "=========Directory is created at #{dir_path}"
else
    puts "=========Directory already exists at #{dir_path}"
end

#Run after each scenario
After do |scenario|
  #Check, scenario is failed?
  if(scenario.failed?)
         time = Time.now.strftime('%Y_%m_%d_%Y_%H_%M_%S_')
         name_of_scenario = time + scenario.name.gsub(/\s+/, "_").gsub("/","_")
         puts "Name of snapshot is #{name_of_scenario}"
         file_path = File.expand_path(dir_path)+'/'+name_of_scenario +'.png'
         page.driver.simulator.save_screenshot file_path
         puts "Snapshot is taken"
    puts "#===========================================================#"
    puts "Scenario:: #{scenario.name}"
    puts "#===========================================================#"
  end
end

我在某处看到过page.driver.browser,simulator.save_screenshot ...并用模拟器替换了浏览器,但没有用...有没有办法改变ios sim保存模拟器的位置而不触及failure_helpers?

4

1 回答 1

1

Calabash 暴露和命名的环境变量SCREENSHOT_PATH可用于设置保存屏幕截图的路径。

至于文件名,您可能想尝试使用screenshotAPI。阅读您的评论,您似乎已经尝试过,但我认为您可能没有使用正确的签名。

查看源代码,screenshot我们看到它是这样定义的:

def screenshot(options={:prefix => nil, :name => nil})
  ...

如您所见,它需要一张地图,所以您应该尝试的是

screenshot({:name => name_of_scenario })

另请注意,文档说screenshot_embed使用screenshot.

于 2015-03-09T11:06:03.907 回答