Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

saving a screen shot in watir

Tags:

watir

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

I am trying following...

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

...but it saves file as @@filename.png. Also I need to save file in particular location.

Could you please help me out?


Hello Zeljko,

I tried your suggestion, but I am getting 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 issue is format of the date and time stamp.

like image 364
Deepak Shah Avatar asked Jan 02 '13 04:01

Deepak Shah


2 Answers

Try this:

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

If you want to save the file in a particular location, try this:

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

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

like image 50
Željko Filipin Avatar answered Sep 28 '22 19:09

Željko Filipin


Thanks for the help.

I used following to format the date and time part and now it is saving screen-shot in required location.

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

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

Regards

like image 39
Deepak Shah Avatar answered Sep 28 '22 17:09

Deepak Shah