Created
March 20, 2019 17:37
-
-
Save andgineer/4ec6d58857bb8689907c87f63475525f to your computer and use it in GitHub Desktop.
Python allure pytest automatic Selenium webdriver screenshot
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
@pytest.hookimpl(tryfirst=True, hookwrapper=True) | |
def pytest_runtest_makereport(item, call): | |
outcome = yield | |
rep = outcome.get_result() | |
if rep.when == 'call' and rep.failed: | |
mode = 'a' if os.path.exists('failures') else 'w' | |
try: | |
with open('failures', mode) as f: | |
if 'browser' in item.fixturenames: | |
web_driver = item.funcargs['browser'] | |
else: | |
print('Fail to take screen-shot') | |
return | |
allure.attach( | |
web_driver.get_screenshot_as_png(), | |
name='screenshot', | |
attachment_type=allure.attachment_type.PNG | |
) | |
except Exception as e: | |
print('Fail to take screen-shot: {}'.format(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment