Test Automation - How To Attach Public IP Address to Allure Report using Playwright TypeScript Auto Fixtures

Test Automation - How To Attach Public IP Address to Allure Report using Playwright TypeScript Auto Fixtures

Introduction

In this article, I will explain how to attach our public IP address to Allure reports using Playwright with TypeScript. This approach builds on a previous implementation in Python, adapting it for the Playwright ecosystem. I've shared the solution presented in this article in my Playwright Typescript example project.

The technological stack used to implement the solution is:


Why should we attach our IP address to the report?

  1. This is done mainly for debugging purposes - if the automation fails, we can filter the logs in a centralized logging system like Amazon CloudWatch.
  2. The IP also helps to detect a machine while running a parallel run with multiple containers or VMs.

Implementing the Solution

First, let's create a custom fixture in a file named logIpOnFailure.ts:


This fixture does the following:

  1. It extends the base Playwright test.
  2. It creates an auto-use fixture called logIpOnFailure.
  3. After the test runs, it checks if the test failed.
  4. If the test fails, a request is sent to retrieve the machine's IP address.
  5. The address is then attached to the Allure report as a text attachment.

Now, let's see how to use this fixture in a test:


  1. We import our custom test object from the logIpOnFailure fixture.
  2. We write a simple test that navigates to the Playwright website and checks the title.
  3. If this test fails, our logIpOnFailure fixture will automatically attach the IP address to the Allure report.


Conclusion

By implementing this solution, we've enhanced our Allure reports with valuable debugging information. Now, each test failure will include the public IP address of the machine that ran the test, making it easier to trace issues in distributed testing environments.

This approach demonstrates the flexibility of Playwright's fixture system and how it can be leveraged to extend Allure reporting capabilities seamlessly.

Happy testing!

要查看或添加评论,请登录

Nir Tal的更多文章

社区洞察

其他会员也浏览了