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?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
do some webdriver stuff in Firefox... save screenshot on any exception to a dated image file:
For me help this solution:
You can start form exploring
self._outcome.errors[1]
where it is possible to find information about the errors.i.e. below code will work only for assertion errors
Here is a solution using a decorator that wrapps every method on a class that starts
test_
with a wrapper that takes a screenshot if the method raises and Exception. Thebrowser_attr
is used to tell the decorator how to obtain the web browser (driver).For Future reference/People here is a solution that works in Python3, that works both for an Exception and on a failed Assert.
(Based on https://stackoverflow.com/a/23176373/9427691)
The
are Python3 only, so for Python2 use
instead.
For the ones that only want a Screen-shot on exceptions. You should take a look at this link: http://blog.likewise.org/2015/01/automatically-capture-browser-screenshots-after-failed-python-ghostdriver-tests/
Another method would be to add the following to your
tearDown
method:This would be assuming a test class like this: