Automatic screenshots when test fail by Selenium Webdriver in Python

0
0

I want to automatic capturing screenshots if my webdriver tests failed (any exception or assertion error). I am using Python unittest and Selenium Webdriver. Does anyone have any solution to this problem?

  • You must to post comments
0
0

do some webdriver stuff in Firefox… save screenshot on any exception to a dated image file:

from datetime import datetime
from selenium import webdriver
browser
= webdriver.Firefox()
try:
# do some webdriver stuff here
except Exception as e:
print e
now
= datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
browser
.get_screenshot_as_file('screenshot-%s.png' % now)
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website