1

i am using calabash to do testing on a iOS native app. calabash takes a screenshot and names it screenshot_0 on scenario failure and saves it in my project directory. i want to know how i can change the path of the screenshot and how i can change the name of the file.

i used the following:

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

i had seen page.driver.browser,simulator.save_screenshot somewhere... and replaced browser with simulator and that did not work... is there any way to change location where ios sim saves simulator without touching failure_helpers?

alannichols
  • 1,496
  • 1
  • 10
  • 20
s5v
  • 495
  • 5
  • 20
  • i replaced page.driver.simulator.save_screenshot file_path to screenshot file_path and got the error message: no implicit conversion of Symbol into integer (typeError) – s5v Mar 06 '15 at 10:22
  • I'm not sure about the error, but it's probably due having passed unexpected parameters to the `screenshot` method, see my answer for more details. – mokagio Mar 09 '15 at 11:07

1 Answers1

1

Calabash exposes and environment variable named SCREENSHOT_PATH you can use to set the path where to save the screenshots.

As for the file name, you might want to try and use the screenshot API. Reading your comment you seem to have tried it already, but I think you might not have used the proper signature.

Looking at the source for screenshot we see that it's defined like this:

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

As you can see it's expecting a map, so what you should try is

screenshot({:name => name_of_scenario })

Also note that the documentation says that the use of screenshot_embed is preferred to screenshot.

mokagio
  • 16,391
  • 3
  • 51
  • 58
  • ah. i did that( screenshot({:name => name_of_scenario }) ) and i still did not get the screenshot in the right place. will try screenshot_embed and try that today. thank you. – s5v Mar 13 '15 at 03:54