This project contains automated tests using Playwright, integrated with Allure for test reporting. The tests are executed within a Docker container, and Allure reports are generated after each test run, which can be viewed in a browser.
- Dockerfile: Docker configuration for running the tests and generating reports.
- package.json: Node.js package dependencies and scripts to run the tests and generate reports.
- playwright.config.ts: Config file that provides information to Playwright.
- tests/: Directory containing Playwright test files.
- support/: Directory containing support files for the tests.
- support/api: Directory containing support files containing information about endpoints and Types caste files.
- support/requests: Directory containing support files for sending out different types of Rest requests.
- support/data: Directory containing support files for data that would be sent out with different endpoints.
- resource/: Directory contaning any resource required for tests, example pdf, png, jpg files.
- test-results/: Directory containing resources generated by Playwright HTML reporter and the report generated after a run
- allure-results/: Directory where Allure results are stored after the tests.
- allure-report/: Directory where Allure generates the final report.
Ensure you have the following installed on your local machine:
git clone https://github.com/adi0709/PlaywrightPetStore.git
cd <repository-directory>To build the Docker image using the provided Dockerfile, run the following command:
docker build -t playwright-allure-tests .This command creates a Docker image named playwright-allure-tests, which will be used to run the tests.
After building the Docker image, you can run the tests by executing:
docker run --rm -p 5252:5252 -v $(pwd)/allure-report:/app/allure-report playwright-allure-testsThis command does the following:
- Executes the tests inside the Docker container.
- Generates an Allure report after test execution.
- Maps the local port 5252 to the port 5252 in the container, allowing you to view the Allure report in your browser.
- Mounts the allure-report directory on your local machine to the /app/allure-report directory in the container, enabling you to access the generated reports from the host.
Once the tests have completed, the Allure report server will be started inside the Docker container. You can access the report by visiting:
http://localhost:5252To stop the Docker container, press CTRL+C in your terminal.
- Make sure to update all the dependencies
If you want to run the tests on your local machine (without Docker):
- Install dependencies:
npm install- Install Java from https://www.java.com/en/download/help/download_options.html
- Add Java to environment paths https://www.java.com/en/download/help/path.html
- Verify java was installed
java -version- Run the tests and generate Allure reports:
npm run test:allure-report- The report will automatically open in your default browser.
npm run test:allure-report: Runs Playwright tests, generates Allure results, and opens the Allure report in a browser.npm run test:html-report: Runs Playwright tests, generates default playwright results. To view the results open playwright-report folder and accessindex.htmlfile.
- Ensure that the allure-results directory inside the container is not empty after test execution.
- Verify that the Playwright configuration (playwright.config.ts) is properly set up to generate Allure results. It should include the following reporter:
reporter: [['allure-playwright']],
- Ensure you are correctly mapping the port using
-p 5252:5252in thedocker runcommand. - Check the
package.jsonscript to make sure Allure is being served on the correct port (5252). - Make sure no other service is already running on port (
5252)
You can use the following command to check if the port is occupied:
lsof -i :5252If any process is using port 5252, stop it:
kill -9 <PID>Run the following in Command Prompt:
netstat -ano | findstr :5252Then, use Task Manager or taskkill to kill the process using the port:
taskkill /PID <PID> /FIf the port is already in use and you cannot stop the process using it, try changing to a different port (e.g., 5253):
npx playwright test --reporter=allure-playwright && npx allure generate ./allure-results --clean -o ./allure-report && npx allure open --port 5253 ./allure-report