Capture screenshot when assert failed

1,648 views
Skip to first unread message

Benniu

unread,
Oct 20, 2011, 10:53:11 PM10/20/11
to Selenium Users
Hi, all

I'm using selenium webdriver 2.8 with ruby test unit.
The capture screenshot function is cool. But what I want is that the
screenshot can be captured automatically when assert failed.
How can achieve that?

Thank,
Ben

santhosh soma

unread,
Oct 21, 2011, 8:35:00 AM10/21/11
to seleniu...@googlegroups.com
Hi Benniu,
 
We have achieved that by using exception handling mechanism in java.If asserts fails we throw an exception and in catch block we caputure the screen shot.
 
Can you please let me know if you need more details.
 
Thanks
Santhosh.


 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


nagarajan raman

unread,
Oct 21, 2011, 9:26:40 AM10/21/11
to Selenium Users
Hi,

If you are using TestNG, then you can add new method inside
Reporter.class to capture screen shots.
Ex. Reporter.logPicture("Picpath", "message") you can directly get the
picture as a link in Report.

Thanks,
Nagarajan.

BenNiu Ji

unread,
Oct 21, 2011, 11:28:30 AM10/21/11
to seleniu...@googlegroups.com
Thanks Santhosh.
I know this could be achieved by try/catch in java. But I'm using ruby test unit rather than Java. Do you know how to achieve that in ruby?

Thanks,
Ben

2011/10/21 santhosh soma <santhos...@gmail.com>

BenNiu Ji

unread,
Oct 21, 2011, 11:29:26 AM10/21/11
to seleniu...@googlegroups.com
By the way, I'm using ci_reporter to generate the report

2011/10/21 BenNiu Ji <benn...@gmail.com>

Ricardo Moura

unread,
Oct 21, 2011, 11:52:40 AM10/21/11
to seleniu...@googlegroups.com
I believe this should solve your problem... no?

begin
# something potentially bad
rescue Exception=>e
# handle e
end

Mourasman

2011/10/21 BenNiu Ji <benn...@gmail.com>

Yeshwant Murali

unread,
Oct 22, 2011, 11:21:26 AM10/22/11
to seleniu...@googlegroups.com
I am using Selenium 2.7 with C#. Is there anything similar to Selenium.Capturescreenshot (if Im correct). I tried to find a way to capture screen shot but, when I run my scripts it keeps flickering and only a part of the screen is caputred as snapshot.
Any help in this regards?
Thanks in advance.
-Yeshwant

Arun Kumaresan

unread,
Jan 23, 2012, 3:49:39 PM1/23/12
to seleniu...@googlegroups.com
Here is a better code to take snapshot. The Beauty of this code is that it takes snapshot only if Test Script fails.
Regards,
Arun Kumaresan

Brian Goad

unread,
Mar 16, 2012, 3:29:27 PM3/16/12
to seleniu...@googlegroups.com
We are using TestUnit, and I have found success with this implementation:


  def teardown
    puts "Shutdown initialized"
    if !@test_passed
      @driver.save_screenshot Time.now.strftime("%F_%H%M%S") + "_" + @method_name + "-FAILED"
    end
    @driver.quit
    end
 
 

Reply all
Reply to author
Forward
0 new messages