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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With