-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Adding screenshots to allureReport #1215
-
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
Beta Was this translation helpful? Give feedback.
All reactions
@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
-
@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.
Beta Was this translation helpful? Give feedback.
All reactions
-
@taruntechno Yes, for the sb
fixture, use sb.driver
.
Beta Was this translation helpful? Give feedback.
All reactions
-
@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
Beta Was this translation helpful? Give feedback.
All reactions
-
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
.
Beta Was this translation helpful? Give feedback.
All reactions
-
@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
Beta Was this translation helpful? Give feedback.
All reactions
-
That could be an issue with the allure API, which is outside the scope of SeleniumBase.
Beta Was this translation helpful? Give feedback.