【问题标题】:change path of screenshot taken by calabash in ios simulator on scenario failure using ruby更改 ios 模拟器中葫芦在使用 ruby​​ 的场景失败时截取的屏幕截图路径
【发布时间】:2015-05-28 00:24:51
【问题描述】:

我正在使用 calabash 在 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?

【问题讨论】:

  • 我将 page.driver.simulator.save_screenshot file_path 替换为屏幕截图 file_path 并收到错误消息:没有将 Symbol 隐式转换为整数 (typeError)
  • 我不确定这个错误,但可能是由于将意外参数传递给了screenshot 方法,有关详细信息,请参阅我的答案。

标签: ios ruby screenshot calabash calabash-ios


【解决方案1】:

Calabash 暴露和environment variable named SCREENSHOT_PATH 可以用来设置保存截图的路径。

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

查看source for screenshot,我们看到它是这样定义的:

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

正如你所看到的,它需要一张地图,所以你应该尝试的是

screenshot({:name => name_of_scenario })

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

【讨论】:

  • 啊。我这样做了( screenshot({:name => name_of_scenario }) ),但我仍然没有在正确的位置获得屏幕截图。今天将尝试 screenshot_embed 并尝试。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多