Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Adding screenshots to allureReport #1215

Answered by mdmintz
taruntechno asked this question in Q&A
Discussion options

Hello @mdmintz you have been amazing first of all for helping us testers achieve results really fast.

I am using pytest-bdd with seleniumbase and I am able to generate allure reports, by just running pytest --alluredir=.\allureReports\ and then doing allure serve allurereports. But it doesnt have the screenshots.

Screenshots do get saved in lates_logs folder but how can I link them to allurereports

You must be logged in to vote

@taruntechno If you add the arguments --dashboard and --html=report.html, you get reports with links to screenshots or containing screenshots in dashboard.html and in report.html. As for getting them into Allure, that's on their API. If they have specific instructions for that, I would check there. But above is how to get the screenshots in SeleniumBase reports.

Replies: 1 comment 9 replies

Comment options

@taruntechno If you add the arguments --dashboard and --html=report.html, you get reports with links to screenshots or containing screenshots in dashboard.html and in report.html. As for getting them into Allure, that's on their API. If they have specific instructions for that, I would check there. But above is how to get the screenshots in SeleniumBase reports.

You must be logged in to vote
9 replies
Comment options

@taruntechno Yes, for the sb fixture, use sb.driver.

Comment options

@mdmintz Didn't work Let me show you my code - Windows 10 is OS
Pytest-bdd is being used and this is the step_Def file for a feature file. As you can see I am passing wrong title and expecting a screenshot but nothing is being generated. screenshot does get saved in latest_logs as part of failure but not in a place where allure can access.

IN CASE of correct title it does save the screenshot but in case of wrong title when it fails it doesn't

@when("Website is displayed")
def google_website(sb):
sb.open("https://www.google.com/")

@then("User enters the details")
def verify_title(sb):
sb.assert_title("Wrong Title")
allure.attach(sb.driver.get_screenshot_as_png(), name='screenshot', attachment_type=allure.attachment_type.PNG)

Then I run pytest --alluredir=.\allureReports\

Allure reports are generate without screenshot

Comment options

You'll probably need a customized tearDown() method to save the allure screenshot on test failures. For that, see https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/base_test_case.py
You'll need to switch from the sb fixture format to the BaseCase format, which uses self instead of sb.

Comment options

@mdmintz so created a conftest.py where I put this code with pytest-bdd hooks but still doesnt work.
import allure

from seleniumbase import BaseCase

class BaseTestCase(BaseCase):

def pytest_bdd_step_error(request, feature, scenario, step, step_func, step_func_args, exception,self):
 allure.attach(self.driver.get_screenshot_as_png(), name='screenshot', attachment_type=allure.attachment_type.PNG)
def pytest_bdd_after_step(request, feature, scenario, step, step_func, step_func_args):
 print("Step Executed")

Second hook is being executed successfully but not the first one. in case of step fail

Comment options

That could be an issue with the allure API, which is outside the scope of SeleniumBase.

Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /