Search code examples
androidcucumbercalabash

cucumber-calabash android - stop screenshots being overwritten in each html result


Problem: screenshots are being overwritten in each device's result html file

Scenario: I am running calabash-android to test a single mobile app running on multiple devices.

The SCREENSHOT_PATH environment variable is set as c:/AndroidApp/Results/deviceScreenshots/

This location will store all screenshots taken.

In a batch file an output format of html is specified and an output location of C:\AndroidApp\Results\device1\deviceId

For multiple devices we have a separate line per device, so device1, device2 etc.. etc..

When I finish the run and examine the screenshots for each device, I am seeing that screenshots are being overwritten and they are being taken from the environment variable location.

e.g: Environment variable folder has 10 screenshots

device 1 has taken 10 screen shots device 2 has taken 10 screen shots

device 2 contains the same 10 screen shots as device one, due to the environment variable folder's imagenames being screenshot1.png, screenshot2.png etc etc

I have specified an unique device folder for each device html result output, so we do have unique result files, however the screenshots are being overwritten as being taken from the Environment variable folder.

any ideas? thanks all.

Graeme


Solution

  • we tried a different approach by appending the screenshot name with a timeDate stamp instead of using an incremental integer counter.

    added the following line of code to the operations.rb file. (not the failureHelpers.rb) to store the date in a specific format to the t1 variable, and output that t1 variable to the prefix.

    @@t1 = DateTime.now.strftime("%Y%m%dT%H%M%S%3N")
    path = "#{prefix}#{name}_#{@@t1}.png" 
    

    code snippet of operations.rb is now:

    def screenshot(options={:prefix => nil, :name => nil})
    prefix = options[:prefix] || ENV['SCREENSHOT_PATH'] || ""
    name = options[:name]
    
    if name.nil?
      name = "screenshot"
        else
          if File.extname(name).downcase == ".png"
            name = name.split(".png")[0]
          end
        end
    
        @@t1 = DateTime.now.strftime("%Y%m%dT%H%M%S%3N")
        path = "#{prefix}#{name}_#{@@t1}.png" 
    

    hope this helps, its not the solution to the original problem, just a re-thought out solution to the problem..phew...

    anyway, thank you all for contributing , interesting puzzle indeed.

    and thanks to my fellow tester here at work, was his work really not mine.