Jun-13-2018, 08:46 PM
Hi,
I can't figure how to add screen shots for pytest-html or even to do a mall change like modifying the Environment details, I'm able to see the basic html report when removing the conftest file but when adding It getting the error:
pytest-html reports
TestClass.py
I can't figure how to add screen shots for pytest-html or even to do a mall change like modifying the Environment details, I'm able to see the basic html report when removing the conftest file but when adding It getting the error:
Error:INTERNALERROR> driver.get_screenshot_as_file(name)
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'get_screenshot_as_file'
I'm using below command to trigger the test:py.test -s -v TestClass.py --html=Htmlreport.htmlI tried to follow below recommandation with no luck:
pytest-html reports
TestClass.py
def test_Login_with_valid_credentials(self): self.driver.get(self.baseURL) self.lp.UserLogin(parameter1, parameter2) # time.sleep(3) result=self.lp.VerifyLogin() self.driver.quit() assert result==Trueconftest.py
from selenium import webdriver import pytest driver = None @pytest.mark.hookwrapper def pytest_runtest_makereport(item): """ Extends the PyTest Plugin to take and embed screenshot in html report, whenever test fails. :param item: """ pytest_html = item.config.pluginmanager.getplugin('html') outcome = yield report = outcome.get_result() extra = getattr(report, 'extra', []) if report.when == 'call' or report.when == "setup": xfail = hasattr(report, 'wasxfail') if (report.skipped and xfail) or (report.failed and not xfail): file_name = report.nodeid.replace("::", "_")+".png" _capture_screenshot(file_name) if file_name: html = '<div><img src="%s" alt="screenshot" style="width:304px;height:228px;" ' \ 'onclick="window.open(this.src)" align="right"/></div>' % file_name extra.append(pytest_html.extras.html(html)) report.extra = extra def _capture_screenshot(name): driver.get_screenshot_as_file(name) @pytest.fixture(scope='session', autouse=True) def browser(): global driver if driver is None: driver = webdriver.Firefox() return driverYour help will be appreciated :)