Skip to content

Commit ed65615

Browse files
Add option to rerun tests (#526)
* Add option ROBOT_RERUN_FAILED to rerun failed tests * Apply suggestions from code review --------- Co-authored-by: Paul Podgorsek <[email protected]>
1 parent 0e59b4e commit ed65615

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

.github/workflows/docker-build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,9 @@ jobs:
154154
-e BROWSER=$BROWSER \
155155
-e TZ="America/New_York" \
156156
$IMAGE_NAME
157+
- name: Rerun Test
158+
run: |
159+
podman run --user=2000:2000 --shm-size=1g \
160+
-v `pwd`/test/rerun.robot:/opt/robotframework/tests/rerun.robot:Z \
161+
-e ROBOT_RERUN_FAILED=20 \
162+
$IMAGE_NAME

Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ ENV ROBOT_TESTS_DIR /opt/robotframework/tests
1515
# Set the working directory environment variable
1616
ENV ROBOT_WORK_DIR /opt/robotframework/temp
1717

18+
# Set the maximum number of rounds to rerun failed tests
19+
ENV ROBOT_RERUN_FAILED 0
20+
1821
# Setup X Window Virtual Framebuffer
1922
ENV SCREEN_COLOUR_DEPTH 24
2023
ENV SCREEN_HEIGHT 1080
@@ -55,11 +58,6 @@ ENV XVFB_VERSION 21.1.18
5558
# By default, no reports are uploaded to AWS S3
5659
ENV AWS_UPLOAD_TO_S3 false
5760

58-
# Prepare binaries to be executed
59-
COPY bin/chromedriver.sh /opt/robotframework/drivers/chromedriver
60-
COPY bin/chrome.sh /opt/robotframework/bin/chrome
61-
COPY bin/run-tests-in-virtual-screen.sh /opt/robotframework/bin/
62-
6361
# Install system dependencies
6462
RUN dnf upgrade -y --refresh \
6563
&& dnf install -y \
@@ -131,6 +129,11 @@ ENV PATH=/opt/microsoft/msedge:$PATH
131129
# Additionally, it cannot run fully on any OS due to https://github.com/microsoft/playwright/issues/29559
132130
RUN rfbrowser init chromium firefox
133131

132+
# Prepare binaries to be executed
133+
COPY bin/chromedriver.sh /opt/robotframework/drivers/chromedriver
134+
COPY bin/chrome.sh /opt/robotframework/bin/chrome
135+
COPY bin/run-tests-in-virtual-screen.sh /opt/robotframework/bin/
136+
134137
# Create the default report and work folders with the default user to avoid runtime issues
135138
# These folders are writeable by anyone, to ensure the user can be changed on the command line.
136139
RUN mkdir -p ${ROBOT_REPORTS_DIR} \

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,20 @@ rpa==1.50.0
199199
200200
**For large dependencies, it is still recommended to extend the project's image and to add them there, to avoid delaying the CI/CD pipelines with repeated dependency installations.**
201201
202+
### Rerunning tests
203+
204+
Failing tests can be rerun by setting the environment variable `ROBOT_RERUN_FAILED` to a value above 0. All reruns of failed tests are executed without parallelization.
205+
The number in environment variable `ROBOT_RERUN_FAILED` dictates how many rerun-rounds are made at maximum. All rerun-rounds will only test what failed in the previous round.
206+
The report files combine the results of all rounds, the last round providing the final result.
207+
208+
The default value for `ROBOT_RERUN_FAILED` is 0, meaning that tests will not be executed again if they fail.
209+
210+
```sh
211+
docker run \
212+
-e ROBOT_RERUN_FAILED=1 \
213+
ppodgorsek/robot-framework:latest
214+
```
215+
202216
<a name="security-considerations"></a>
203217

204218
## Security consideration

bin/run-tests-in-virtual-screen.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,34 @@ fi
5353

5454
ROBOT_EXIT_CODE=$?
5555

56+
if [[ ${ROBOT_EXIT_CODE} -gt 0 ]]
57+
then
58+
for ((i = 0 ; i < ${ROBOT_RERUN_FAILED} ; i++ ))
59+
do
60+
echo "Rerunning failed tests, round ${i}..."
61+
xvfb-run \
62+
--server-args="-screen 0 ${SCREEN_WIDTH}x${SCREEN_HEIGHT}x${SCREEN_COLOUR_DEPTH} -ac" \
63+
robot \
64+
--rerunfailed $ROBOT_REPORTS_FINAL_DIR/output.xml \
65+
--output $ROBOT_REPORTS_FINAL_DIR/output_rerun.xml \
66+
--outputDir $ROBOT_REPORTS_FINAL_DIR \
67+
${ROBOT_OPTIONS} \
68+
$ROBOT_TESTS_DIR
69+
70+
ROBOT_EXIT_CODE=$?
71+
72+
rebot \
73+
--outputDir $ROBOT_REPORTS_FINAL_DIR \
74+
--merge $ROBOT_REPORTS_FINAL_DIR/output_rerun.xml \
75+
$ROBOT_REPORTS_FINAL_DIR/output.xml
76+
77+
if [ ${ROBOT_EXIT_CODE} -eq 0 ]
78+
then
79+
break
80+
fi
81+
done
82+
fi
83+
5684
if [ ${AWS_UPLOAD_TO_S3} = true ]
5785
then
5886
echo "Uploading report to AWS S3..."

test/rerun.robot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*** Test Cases ***
2+
3+
Randomly Fail Test
4+
${rand}= Evaluate random.randint(0,3)
5+
IF ${rand} > 0
6+
Fail
7+
END

0 commit comments

Comments
 (0)