Skip to content

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

@Formartha

Description

@Formartha

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions