Skip to content

Commit b79cfff

Browse files
authored
Replace selenium library with browser library (#14)
1 parent f7c3533 commit b79cfff

File tree

8 files changed

+99
-52
lines changed

8 files changed

+99
-52
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Parallel Robot Framework pipeline
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- docs/examples/jenkins/parallel-robot-pipeline/**
8+
- .github/workflows/parallel-robot-pipeline.yml
9+
pull_request:
10+
branches:
11+
- main
12+
paths:
13+
- docs/examples/jenkins/parallel-robot-pipeline/**
14+
- .github/workflows/parallel-robot-pipeline.yml
15+
16+
jobs:
17+
run:
18+
name: Build, test, and push container image
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
- name: Build container image
24+
working-directory: docs/examples/jenkins/parallel-robot-pipeline/
25+
run: |
26+
docker build . --tag rf-screenshot
27+
- name: Test container image
28+
run: |
29+
for browser in chromium firefox; do
30+
docker run --rm -v $(pwd)/robot_output:/out -e BROWSER=$browser rf-screenshot -d /out -l none -r none -o $browser.xml -N $browser -v URL:https://kangasta.github.io/cicd-examples/
31+
done
32+
- name: Store logs
33+
if: always()
34+
uses: actions/upload-artifact@v3
35+
with:
36+
name: raw-logs
37+
path: robot_output
38+
retention-days: 1
39+
- name: Login to GitHub Container Registry
40+
if: github.ref == 'refs/heads/main'
41+
uses: docker/login-action@v2
42+
with:
43+
registry: ghcr.io
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
- name: Push container image to GitHub Container Registry
47+
if: github.ref == 'refs/heads/main'
48+
working-directory: docs/examples/jenkins/parallel-robot-pipeline/
49+
run: |
50+
docker build . --target base -t base
51+
52+
for tag in ${{ github.run_number }} latest; do
53+
docker tag base ghcr.io/kangasta/robot-browser:$tag
54+
docker push ghcr.io/kangasta/robot-browser:$tag
55+
done
56+
process-logs:
57+
name: Process logs
58+
if: always()
59+
needs: run
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/setup-python@v4
63+
with:
64+
python-version: '3.10'
65+
- name: Download logs
66+
uses: actions/download-artifact@v3
67+
with:
68+
path: work/
69+
- name: Install robot framework
70+
run: pip install robotframework>=4
71+
- name: Combine logs
72+
working-directory: work/
73+
run: |
74+
mkdir rebot_output
75+
rebot -d rebot_output -o output.xml -N "${{ github.workflow }}" --nostatusrc */*.xml
76+
- name: Store processed logs
77+
uses: actions/upload-artifact@v3
78+
with:
79+
name: combined-logs
80+
path: work/rebot_output

docs/examples/jenkins/parallel-robot-pipeline/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
*.log
44
*.png
55
*.xml
6+
7+
out/
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
FROM ubuntu:20.04 as base
2-
3-
ENV BROWSER='headlessfirefox'
4-
ENV BROWSER_OPTIONS=''
1+
FROM mcr.microsoft.com/playwright:v1.48.0-noble AS base
52

63
# Disable interactive configuration
74
ENV DEBIAN_FRONTEND='noninteractive'
@@ -10,16 +7,15 @@ WORKDIR /work
107
COPY ./entrypoint.sh ./requirements.txt /work/
118
RUN apt-get update && \
129
apt-get install -y \
13-
python3 \
14-
python3-pip \
15-
firefox \
16-
firefox-geckodriver && \
17-
pip install -r requirements.txt && \
10+
python3-pip && \
11+
pip install --break-system-packages -r requirements.txt && \
12+
rfbrowser init && \
1813
chmod +x entrypoint.sh
1914

2015
ENTRYPOINT ["./entrypoint.sh"]
2116

2217

2318
FROM base
2419

25-
COPY . .
20+
COPY suites/ suites/
21+
COPY --from=base /work/entrypoint.sh .

docs/examples/jenkins/parallel-robot-pipeline/README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,15 @@ System.setProperty("hudson.model.DirectoryBrowserSupport.CSP","sandbox allow-scr
2727
Build the Docker containers with `docker build`:
2828

2929
```sh
30-
# Chromium
31-
docker build . -f chromium.Dockerfile --tag rf-screenshot-gc
32-
33-
# Firefox
34-
docker build . -f firefox.Dockerfile --tag rf-screenshot-ff
30+
docker build . --tag rf-screenshot
3531
```
3632

3733
Execute the Robot Framework suites with `docker run`:
3834

3935
```sh
4036
# Chromium
41-
docker run --rm -v $(pwd)/out:/out rf-screenshot-gc -d /out -v URL:https://github.com/kangasta/jenkins-examples
37+
docker run --rm -v $(pwd)/out:/out -e BROWSER=chromium rf-screenshot -d /out -v URL:https://kangasta.github.io/cicd-examples/
4238

4339
# Firefox
44-
docker run --rm -v $(pwd)/out:/out rf-screenshot-ff -d /out -v URL:https://github.com/kangasta/jenkins-examples
40+
docker run --rm -v $(pwd)/out:/out -e BROWSER=firefox rf-screenshot -d /out -v URL:https://kangasta.github.io/cicd-examples/
4541
```

docs/examples/jenkins/parallel-robot-pipeline/chromium.Dockerfile

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/sh
2-
robot "$@" ./suites
2+
robot "$@" ./suites
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
robotframework>=4
2-
robotframework-seleniumlibrary>=4
2+
robotframework-browser>=18

docs/examples/jenkins/parallel-robot-pipeline/suites/screenshot.robot

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
*** Settings ***
22
Library OperatingSystem
3-
Library SeleniumLibrary
3+
Library Browser
44
Suite Setup Check URL and open browser
55
Suite Teardown Close browser
66

77
*** Variables ***
8-
${BROWSER} headlesschrome
9-
${BROWSER_OPTIONS} ${EMPTY}
8+
${BROWSER} chromium
109
${URL} ${EMPTY}
11-
${WAIT_PAGE_LOAD} 5 seconds
1210

1311
*** Tasks ***
1412
Capture Screenshot
1513
Skip if not $URL msg=Target URL not specified
16-
Go to ${URL}
17-
Sleep ${WAIT_PAGE_LOAD}
18-
Capture Page Screenshot
14+
New Page ${URL}
15+
Take Screenshot EMBED
1916

2017
*** Keywords ***
2118
Open browser defined by environment
22-
${browser_options}= Get Environment Variable BROWSER_OPTIONS ${BROWSER_OPTIONS}
2319
${browser}= Get Environment Variable BROWSER ${BROWSER}
24-
Open browser browser=${browser} options=${browser_options}
25-
Set Screenshot Directory ${OUTPUT DIR}${/}${browser}_screenshots
20+
New Browser ${browser}
21+
New Context viewport={'width': 1280, 'height': 720}
2622

2723
Check URL and open browser
2824
Skip if not $URL msg=Target URL not specified

0 commit comments

Comments
 (0)