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 #263

Open
Formartha opened this issue Nov 28, 2024 · 0 comments
Open

Comments

@Formartha
Copy link

Formartha commented Nov 28, 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()

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

1 participant