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:
- Programming Language: TypeScript
- Testing Framework: Playwright Test
- Reporting Framework: Allure
- HTTP Library: Playwright’s built-in request API
![](https://media.licdn.com/dms/image/v2/D4D12AQHnpHYdW8q4-w
Why should we attach our IP address to the report?
- This is done mainly for debugging purposes - if the automation fails, we can filter the logs in a centralized logging system like Amazon CloudWatch.
- 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:
- It extends the base Playwright test.
- It creates an auto-use fixture called.
- After the test runs, it checks if the test failed.
- If the test fails, a request is sent to retrieve the machine’s IP address.
- 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:
- We import our custom object from the fixture.
- We write a simple test that navigates to the Playwright website and checks the title.
- If this test fails, our 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!