Last active
April 17, 2024 13:17
-
-
Save prashanth-sams/f0cc2102fc3619b11748e0cbda22598b to your computer and use it in GitHub Desktop.
Screenshot Example | pytest-html-reporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
import unittest | |
from pytest_html_reporter import attach | |
class TestClass(unittest.TestCase): | |
def __init__(self, driver): | |
super().__init__(driver) | |
def setUp(self): | |
global driver | |
self.driver = webdriver.Chrome() | |
def test_demo(self): | |
self.driver.get("http://devopsqa.wordpress.com/") | |
assert 5 == 4 | |
def tearDown(self): | |
self.screenshot_on_failure() | |
self.driver.close() | |
self.driver.quit() | |
def screenshot_on_failure(self): | |
for self._testMethodName, error in self._outcome.errors: | |
if error: | |
attach(data=self.driver.get_screenshot_as_png()) | |
if __name__ == '__main__': | |
unittest.main() |
I am also facing same issue
I am unable to see the screenshots when running the attach(data=self.driver.get_screenshot_as_png())
Unable to see a screenshot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can this be used in a Conftest?
I'm facing issues for pytest is that I can't have classes as they haven't been implemented yet.