Skip to content

Commit 806576d

Browse files
douglasdotctang-mmp-gentili
committed
[New] Tutorial (#251)
Signed-off-by: Douglas Chiang <[email protected]> Co-authored-by: tang-mm <[email protected]> Co-authored-by: Paolo Gentili <[email protected]>
1 parent 2849062 commit 806576d

33 files changed

+998
-1
lines changed

.github/workflows/yarf.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,34 @@ jobs:
7070
version=$(jq -r '.version' /tmp/yarf-outdir/TestSubmissionSchema_output.json)
7171
check-jsonschema --schemafile https://raw.githubusercontent.com/canonical/test-submission-schema/refs/heads/main/test_submission_schema/schemas/v${version}.json /tmp/yarf-outdir/TestSubmissionSchema_output.json
7272
73+
- name: Install tutorial dependencies
74+
run: |
75+
sudo apt-get --yes --no-install-recommends install \
76+
python3-gi \
77+
gir1.2-gtk-4.0 \
78+
libadwaita-1-dev \
79+
gir1.2-adw-1
80+
81+
- name: Run tutorial examples
82+
run: |
83+
export WAYLAND_DISPLAY=wayland-0
84+
85+
# Start Mir on a virtual display (doesn't require graphics hardware)
86+
mir-test-tools.demo-server \
87+
--add-wayland-extensions zwlr_screencopy_manager_v1:zwlr_virtual_pointer_manager_v1 \
88+
--platform-display-libs mir:virtual \
89+
--virtual-output 1280x1024 &
90+
91+
# Wait for the compositor to start
92+
inotifywait --event create --include "^$XDG_RUNTIME_DIR/wayland-0\$" $XDG_RUNTIME_DIR
93+
94+
uv venv --python=/usr/bin/python3 --system-site-packages --project=$(pwd)/examples/yarf-example-simple-counter
95+
dbus-run-session -- uv --project=$(pwd)/examples/yarf-example-simple-counter run simple-counter &
96+
97+
uv run yarf --platform Mir examples/yarf-example-simple-counter/yarf_tests
98+
99+
dbus-run-session -- uv --project=$(pwd)/examples/yarf-example-simple-counter run simple-counter --theme light &
100+
uv run yarf --platform Mir --variant light examples/yarf-example-simple-counter/yarf_tests
73101
74102
- if: failure()
75103
name: Collect test results

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ repos:
66
rev: v5.0.0
77
hooks:
88
- id: trailing-whitespace
9+
exclude: ^docs/.*\.md$
910
- id: end-of-file-fixer
1011
- id: check-yaml
1112
- id: check-added-large-files

docs/tutorial/getting_started.md

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
# Getting started
2+
3+
**YARF** is a tool built upon [Robot Framework][robot-framework] that allows developers to build complex visual test scenarios and bootstrap them locally, and then work towards automated runs in continuous integration (CI) and use of platforms/fixtures with minimal effort. In YARF, we support the Mir as one of our default platform.
4+
5+
**Mir** is a display server that is suitable for local development and continuous integration. In this tutorial, we will use Mir to display an application called `simple-counter` and then use YARF to perform actions and run tests on it. For details please visit [here][mir-docs].
6+
7+
In this tutorial, we will go through the process of setting up YARF and a Mir server, then we will start a calculator app inside the Mir server and use YARF to do some simple calculations.
8+
9+
This tutorial is divided into the following sections:
10+
11+
1. Setup
12+
1. Exploring YARF
13+
14+
## Setup
15+
16+
### Installing YARF and dependencies
17+
18+
First of all, we will install YARF, we can simply run:
19+
20+
```{code-block} bash
21+
---
22+
caption: The command to install the YARF snap.
23+
---
24+
sudo snap install yarf
25+
```
26+
27+
Optionally connect the following snap interface to allow our optical character recognition (OCR) algorithm to speed up the process:
28+
29+
```{code-block} bash
30+
---
31+
caption: The command to connect YARF's process-control interface.
32+
---
33+
snap connect yarf:process-control
34+
```
35+
36+
Next, we need to install [`mir-test-tools`][mir-tests-tools], a snap that provides an HID enabled demo Mir server - In this server, we can control the mouse and keyboard.
37+
38+
```{code-block} bash
39+
---
40+
caption: The command to install mir-test-tools
41+
---
42+
sudo snap install mir-test-tools
43+
```
44+
45+
After that, we will install some dependencies that the `simple-counter` required:
46+
47+
```{code-block} bash
48+
---
49+
caption: Command for installing simple-counter dependencies.
50+
---
51+
sudo apt update
52+
sudo apt install \
53+
python3-gi \
54+
gir1.2-gtk-4.0 \
55+
libadwaita-1-dev \
56+
gir1.2-adw-1
57+
```
58+
59+
### Starting the Mir server
60+
61+
Now, let's start the Mir server:
62+
63+
```{code-block} bash
64+
---
65+
caption: The command to start the mir-test-tools demo server with virtual
66+
pointer.
67+
---
68+
export WAYLAND_DISPLAY=wayland-0
69+
70+
mir-test-tools.demo-server \
71+
--add-wayland-extensions zwlr_screencopy_manager_v1:zwlr_virtual_pointer_manager_v1 &
72+
```
73+
74+
```{note}
75+
`WAYLAND_DISPLAY` is a variable that is only used inside the Mir virtual server, not the running desktop.
76+
```
77+
78+
We should see some output like:
79+
80+
```{code-block} bash
81+
---
82+
caption: Output of starting mir-test-tools.demo-server.
83+
---
84+
$ mir-test-tools.demo-server \
85+
--add-wayland-extensions zwlr_screencopy_manager_v1:zwlr_virtual_pointer_manager_v1 &
86+
[1] 4160206
87+
88+
[2025-07-30 15:51:06.763863] <information> mirserver: Starting
89+
...
90+
[2025-07-30 15:51:08.360008] <information> mirserver: Initial display configuration:
91+
[2025-07-30 15:51:08.360031] <information> mirserver: * Output 1: unknown connected, used
92+
[2025-07-30 15:51:08.360039] <information> mirserver: . |_ Physical size 9.7" 193x155mm
93+
[2025-07-30 15:51:08.360042] <information> mirserver: . |_ Power is on
94+
[2025-07-30 15:51:08.360047] <information> mirserver: . |_ Current mode 1280x1024 120.00Hz
95+
[2025-07-30 15:51:08.360050] <information> mirserver: . |_ Preferred mode 1280x1024 120.00Hz
96+
[2025-07-30 15:51:08.360054] <information> mirserver: . |_ Orientation normal
97+
[2025-07-30 15:51:08.360059] <information> mirserver: . |_ Logical size 1280x1024
98+
[2025-07-30 15:51:08.360062] <information> mirserver: . |_ Logical position +0+0
99+
[2025-07-30 15:51:08.360065] <information> mirserver: . |_ Scaling factor: 1.00
100+
```
101+
102+
And a black window with a pointer should pop up:
103+
104+
```{figure} ./images/mir_test_tools_window.png
105+
---
106+
alt: The mir test tools window
107+
width: 50%
108+
---
109+
The mir test tools window
110+
```
111+
112+
### Starting the calculator app
113+
114+
Now, we can start our `simple-counter` by running under the same terminal:
115+
116+
```{code-block} bash
117+
---
118+
caption: The commands that starts a calculator.
119+
---
120+
gnome-calculator &
121+
```
122+
123+
Then we should see our simple counter popped up in the mir server:
124+
125+
```{figure} ./images/mir_test_tools_with_calculator_window.png
126+
---
127+
alt: The mir-test-tools window with the calculator running.
128+
---
129+
The `mir-test-tools` window with the calculator running.
130+
```
131+
132+
## Exploring YARF
133+
134+
After setup, we can start exploring YARF. In YARF we can control the pointer and keyboard using different functions called `keywords`, and we provided an interactive mode for users to test out different commands.
135+
136+
### Entering the interactive mode
137+
138+
To get into interactive mode, we can run:
139+
140+
```{code-block} bash
141+
---
142+
caption: YARF interactive mode with Mir platform.
143+
---
144+
$ yarf --platform Mir
145+
INFO:RPA.core.certificates:Truststore not in use, HTTPS traffic validated against `certifi` package. (requires Python 3.10.12 and 'pip' 23.2.1 at minimum)
146+
2025-07-30 17:28:11,998 - RPA.core.certificates - INFO - Truststore not in use, HTTPS traffic validated against `certifi` package. (requires Python 3.10.12 and 'pip' 23.2.1 at minimum)
147+
148+
149+
INFO: *** Welcome to the YARF interactive console. ***
150+
INFO: You can use this console to execute Robot Framework keywords interactively.
151+
INFO: The value of ${CURDIR} is CWD, you can change it using the `Set Variable` keyword.
152+
INFO: You can press RIGHT_ARROW to auto-complete the keyword.
153+
INFO: You can press CRTL + SPACE to view supported keywords on a prefix.
154+
>>>>> Enter interactive shell
155+
iRobot can interpret single or multiple keyword calls,
156+
as well as FOR, IF, WHILE, TRY
157+
and resource file syntax like *** Keywords*** or *** Variables ***.
158+
159+
Type "help" for more information.
160+
>
161+
```
162+
163+
Here, we can run `keywords` to see a list of commands that we can use:
164+
165+
```{code-block} bash
166+
---
167+
caption: YARF interactive mode keywords output.
168+
---
169+
...
170+
>>>>> Enter interactive shell
171+
iRobot can interpret single or multiple keyword calls,
172+
as well as FOR, IF, WHILE, TRY
173+
and resource file syntax like *** Keywords*** or *** Variables ***.
174+
175+
Type "help" for more information.
176+
> keywords
177+
...
178+
< Keywords of library kvm
179+
Click ${button} Button Click a button on the virtual pointer.
180+
Click ${button} Button On ${destination} Move the virtual pointer to the destination and click the button.
181+
Displace ${point} By (${x}, ${y}) Shift a point by the specified displacements along the x and y axes.
182+
Get Center Of ${region} Get the center point of a region.
183+
Move Pointer To ${destination} Move the pointer to an absolute position or image template.
184+
Move Pointer To ${destination} In ${domain} Move the pointer to an absolute position or image template.
185+
Move Pointer To (${x}, ${y}) Move the pointer to an absolute position.
186+
Move Pointer To Proportional (${x}, ${y}) Move the pointer to a destination position given as proportions to the size of the display output.
187+
Press ${button} Button Press a button on the virtual pointer.
188+
Press And Wait For Match
189+
Press Combo And Match If the provided template is not already matching, press a key combination until it does.
190+
Press Key And Match If the provided template is not already matching, press a key until it does.
191+
Release ${button} Button Release a button on the virtual pointer.
192+
Release Buttons Release all buttons on the virtual pointer.
193+
Walk Pointer To ${destination} Moves the pointer in incremental steps from the current pointer position to an absolute position or image template.
194+
Walk Pointer To (${x}, ${y}) Move the pointer in incremental steps from the current pointer position to an absolute position.
195+
Walk Pointer To Proportional (${x}, ${y}) Move the pointer in incremental steps from the current pointer position to a destination position given as proportions to the size of the display output.
196+
```
197+
198+
In YARF, we supports the Robot Framework built-in keywords and we also developed a list of keywords for more convenient use cases.
199+
For a more detailed list of keywords developed under YARF, please visit the [reference page][reference-resource-docs].
200+
201+
### Start using keywords
202+
203+
Now let's use the YARF interactive mode to do some simple maths. With the cursor blinking in the calculator. Use the following command in the interactive console:
204+
205+
```{code-block} bash
206+
---
207+
caption: Using the command `PlatformHid.Type String`.
208+
---
209+
> PlatformHid.Type String 7*6=
210+
>
211+
```
212+
213+
This command will type `7*6=` in the calculator and should give a result equals to `42`.
214+
215+
```{figure} ./images/calculator_with_simple_formula.png
216+
---
217+
alt: The calculator calculating a simple formula.
218+
---
219+
The calculator calculating a simple formula.
220+
```
221+
222+
Alternatively, instead of simulating keyboard input, we can also instruct YARF to simulate mouse clicks on the graphic interface using the `Click ${button} Button On ${destination}` keyword. To do this, we need to tell the keyword which UI element to target by providing a template.
223+
224+
In the interactive mode, we provided a `Grab Templates` keyword that opens an ROI (Region of Interest) selector to allow our users to select templates.
225+
226+
```{code-block} bash
227+
---
228+
caption: Console output from running the Grab Templates keyword on the
229+
calculator.
230+
---
231+
>>>>> Enter interactive shell
232+
...
233+
Interactive.Grab Templates 7 * 6 = # ΔT: 7.686s
234+
Click and drag to select and save an ROI, press Esc to exit the ROI selector.
235+
ROI saved as /path/to/7.png
236+
ROI saved as /path/to/*.png
237+
ROI saved as /path/to/6.png
238+
ROI saved as /path/to/=.png
239+
>
240+
```
241+
242+
```{figure} ./images/roi_selector_selecting_calculator_7.png
243+
---
244+
alt: The ROI selector selecting the 7 button in the calculator.
245+
---
246+
The ROI selector selecting the 7 button in the calculator.
247+
```
248+
249+
Just follow the instructions in the ROI selector to capture the following templates:
250+
251+
```{figure} ./images/calculator_templates.png
252+
---
253+
alt: The templates required for calculating 7*6=42.
254+
width: 50%
255+
---
256+
The templates required for calculating 7*6=42.
257+
```
258+
259+
Now with the templates in place we can use the function `Click ${button} Button On ${destination}` to click the buttons:
260+
261+
```{code-block} bash
262+
---
263+
caption: Console output from running the Grab Templates keyword on the
264+
calculator.
265+
---
266+
>>>>> Enter interactive shell
267+
...
268+
> Click LEFT Button On /path/to/7.png # ΔT: 0.114s
269+
INFO:root:Scanned image in 0.12 seconds
270+
> Click LEFT Button On *.png # ΔT: 0.138s
271+
INFO:root:Scanned image in 0.09 seconds
272+
> Click LEFT Button On 6.png # ΔT: 0.107s
273+
INFO:root:Scanned image in 0.09 seconds
274+
> Click LEFT Button On =.png # ΔT: 0.105s
275+
INFO:root:Scanned image in 0.11 seconds
276+
>
277+
```
278+
279+
Then we should see the pointer inside the mir server moving across the buttons on the calculator and give the answer `42` as the same before.
280+
281+
In this tutorial, we have successfully setup the mir server and use YARF to control the keyboard and pointer to do simple calculations on the calculator app. Feel free to try out other keywords!
282+
283+
[mir-docs]: https://canonical-mir.readthedocs-hosted.com/stable/
284+
[mir-tests-tools]: https://snapcraft.io/mir-test-tools
285+
[reference-resource-docs]: ../reference/rf_libraries-resources.md
286+
[robot-framework]: https://robotframework.org/
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)