Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

XML not generating for the playwright test running in Bitbucket pipeline

ragsagarm
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 19, 2024

 

 

Currently, I am running my Playwright tests with a JavaScript framework in a Bitbucket pipeline for CI/CD. However, the issue is that my XML file is not being generated in the source directory within the root folder after committing the code to Bitbucket. The pipeline is picking up the results.xml file from the existing source directory instead of the newly generated file. Although the results.xml is stored as an artifact, the pipeline continues to use the outdated version from the root directory.

this is my yml script for the pipeline 


 

image: mcr.microsoft.com/playwright:v1.42.1-jammy
pipelines:
default:
- step:
name: Build and Test
caches:
- node
script:
- npm ci
- npx playwright test --reporter=html,junit
- mv test-results/junit.xml results.xml
artifacts:
- playwright-report/**
- results.xml
- jira-issues.json
after-script:
- |
echo "Checking for test results file..."
if [ -f "results.xml" ]; then
echo "Test results file found."
failed_tests=$(grep -c '<failure' "results.xml")
echo "Number of failed tests: $failed_tests"
if [ $failed_tests -gt 0 ]; then
echo "Installing dependencies..."
npm install request xml2js
echo "Creating JIRA issues..."
node create-jira-issues.js --results="results.xml" --node="create-jira-issues.js"
else
echo "No failed tests. Skipping JIRA issue creation."
fi

echo "Installing Testmo CLI..."
npm install -g @testmo/testmo-cli
echo "Adding HTML artifact to Testmo..."
testmo automation:resources:add-artifact \
--name "HTML Report" \
--file "playwright-report/index.html" \
echo "Updating Testmo with test results..."
testmo automation:run:submit \
--project-id 1 \
--name "Build $BITBUCKET_BUILD_NUMBER" \
--source "test" \
--results="results.xml" \
--resources testmo-resources.json
else
echo "Test results file not found. Skipping JIRA issue creation and Testmo update."
fi

1 answer

1 vote
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 22, 2024

Hello @ragsagarm and welcome to the Community!

Artifact in bitbucket are used to share files between different steps. In the example that you shared, you have a single step only, so artifacts are not really being used (the after-script section is considered part of the same step, it does not run in a separate container).

Having said that, my understanding is that your repository contains a file named results.xml, but during the pipelines, you create an updated version or this file, and want to use this updated version in the rest of the commands.

It would be important to validate if the results.xml file is actually being updated by the commands you're executing, so I would suggest printing the output of that file in different sections of your build : 

script:

- cat results.xml #1 print the original file present in the repo
npm ci
npx playwright test --reporter=html,junit
- cat test-results/junit.xml #2 print the file generated by playwright
mv test-results/junit.xml results.xml
- cat results.xml #3 print the file to check if the file content was updated with the content generated by previous commands

after-script:
- |
cat results.xml # print the file to see if the content matches with #3
echo "Checking for test results file..."
 

This would help to identify at which point of your build the file is not getting updated, so you can make the necessary changes.

Thank you, @ragsagarm !

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events