Saving a screenshot in playback mode

I want to save a screenshot in Watir with a file name like ddmmyyyy_hhmmss.png .

I'm trying to follow ...

 @@filename = Time.now browser.screenshot.save (@@filename.png) 

... but it saves the file as @@filename.png . Also I need to save the file in a specific place.

Could you help me?


Hi Zelco

I tried your suggestion, but I get the following error message:

 C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/common/driver_extensions/takes_screenshot.rb:18:in `initialize': Invalid argument - 2013-01-03 11:02:21 +1100.png (Errno::EINVAL) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/common/driver_extensio ns/takes_screenshot.rb:18:in `open' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/common/driver_extensio ns/takes_screenshot.rb:18:in `save_screenshot' 

I think the problem is the date and time stamp format.

+4
source share
2 answers

Try the following:

 browser.screenshot.save ("#{@@filename}.png") 

If you want to save the file in a specific location, try the following:

 browser.screenshot.save ("/path/to/file/#{@@filename}.png") 

Of course, replace /path/to/file/ with the actual path.

+8
source

Thanks for the help.

I used the following format to format the date and time, and now it saves the screen shot in the desired location.

filename = DateTime.now.strftime ("% d% b% Y% H% M% S")

browser.screenshot.save ("Test / # {filename} .png")

Hello

+2
source

All Articles