Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to attach failed test screenshot to Report Portal using Playwright #385

Open
Formartha opened this issue Nov 27, 2024 · 1 comment
Open

Comments

@Formartha
Copy link
Contributor

Formartha commented Nov 27, 2024

Hello,

I have a fixture that implements opening browser and other activities, this is a fixture on a scope of a function.
I would like to add the ability to upload a screenshot to report portal on failure, however, it seems like when it fails, the native report portal logger is unable to send logs from this fixture. the failure handling is on the finally stage.

What should be done?

    @pytest.mark.block_asyncio
    def setup_and_teardown(self, request):
        logging.setLoggerClass(RPLogger)
        logger.info("Starting PlayWright client")
        self.sb_actions.disable_email_notification_if_exists()
        # Determine if --headed was passed
        headed = request.config.getoption("--headed")
        headless = not headed
        self.video_dir = os.path.join(Config.data["logging_directory"], "videos")
        self.trace_dir = os.path.join(Config.data["logging_directory"], "traces")
        self.screenshot_dir = os.path.join(Config.data["logging_directory"], "screenshots")
        os.makedirs(self.video_dir, exist_ok=True)

        setup_successful = False

        with sync_playwright() as p:
            browser = p.chromium.launch(headless=headless)
            self.page = browser.new_page(record_video_dir=self.video_dir)

            self.start_tracing()
            try:
                self.setup_playwright_test()
                setup_successful = True
                yield  # opening browser session
                self.teardown_playwright_test()
            finally:
                if setup_successful:
                    self.stop_tracing()
                    self.cleanup(request)
                    browser.close()
@AmsterGet
Copy link
Member

Hello @Formartha !
You are using the Pytest test framework.
So, I'll move the issue to the right place.

@AmsterGet AmsterGet transferred this issue from reportportal/agent-js-playwright Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants