As QAs, we’ve all been in the instance where we created a certain number of tests for a feature and then pushed it right on the main branch of the app with 100% confidence that it will work (not only locally) and fail only if there is an issue. Well, I was one of these QAs, I was so confident that my tests would fire up red alerts only if there are real issues, but oh boy was I wrong.
#!/bin/bash
# Spec file to run
SPEC_FILE="PATH/TO/YOUR/TESTS"
# Initialize counters
pass_count=0
fail_count=0
# Run the test 20 times
for i in {1..20}; do
# Run the test and capture the result
npx playwright test --project=dev --workers=1
if [ $? -eq 0 ]; then
echo "Run $i: PASSED"
((pass_count++))
else
echo "Run $i: FAILED"
((fail_count++))
fi
done
# Display the results
echo "===================="
echo "Total Runs: 20"
echo "Passed: $pass_count"
echo "Failed: $fail_count"
As you can see above, tests will run 20 times, one after the other, and after each full run I will add 1 to the pass_count . If it fails, it will add to the fail_count . You can play with it more, adjust it to your needs, for example, you can check a certain test with the help of the title, or change how many times do you want it to run. It’s up to you really.




