-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PoC gui test automation app launch test
Create generic keyword for launching and closing any app with gui test automation. Add example test cases for chromium and firefox. Signed-off-by: Samuli Leivo <[email protected]>
- Loading branch information
1 parent
4ad9e19
commit 9a8003f
Showing
11 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# SPDX-FileCopyrightText: 2022-2024 Technology Innovation Institute (TII) | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from pyscreeze import locate, center | ||
import logging | ||
|
||
|
||
def locate_image(image): | ||
screenshot = "./screenshot.png" | ||
image_box = locate(image, screenshot) | ||
image_center = center(image_box) | ||
logging.info(image_box) | ||
logging.info(image_center) | ||
image_center_in_mouse_coordinates = convert_resolution(image_center) | ||
logging.info(image_center_in_mouse_coordinates) | ||
return image_center_in_mouse_coordinates | ||
|
||
def convert_resolution(coordinates): | ||
# Screenshot image resolution is 1920x1200 but ydotool mouse movement resolution was tested to be 960x600. | ||
# Let's have hard coded resolution scaling factor for now. | ||
# However, if ghaf resolution is changed this might not work anymore. | ||
scaling_factor = 2 | ||
mouse_coordinates = { | ||
'x': coordinates[0] / scaling_factor, | ||
'y': coordinates[1] / scaling_factor | ||
} | ||
return mouse_coordinates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# SPDX-FileCopyrightText: 2022-2024 Technology Innovation Institute (TII) | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
*** Settings *** | ||
Documentation Testing launching applications | ||
Force Tags gui | ||
Resource ../../resources/ssh_keywords.resource | ||
Resource ../../config/variables.robot | ||
Resource ../../resources/common_keywords.resource | ||
Library ../../lib/gui_testing.py | ||
Library Collections | ||
Suite Teardown Close All Connections | ||
|
||
|
||
*** Variables *** | ||
@{app_pids} ${EMPTY} | ||
|
||
|
||
*** Test Cases *** | ||
|
||
Start and close chromium via GUI on LenovoX1 | ||
[Documentation] Start Chromium via GUI test automation and verify related process started | ||
... Close Chromium via GUI test automation and verify related process stopped | ||
[Tags] bat SP-T97-1 lenovo-x1 | ||
Start and close app via GUI on LenovoX1 chromium-vm chromium | ||
|
||
Start Firefox via GUI | ||
[Documentation] Passing this test requires that display is connected to the target device | ||
... | ||
... Start Firefox via GUI test automation and verify related process started | ||
... Close Firefox via GUI test automation and verify related process stopped | ||
[Tags] SP-T45-1 experimental | ||
Start and close app via GUI firefox agx | ||
|
||
|
||
*** Keywords *** | ||
|
||
Start and close app via GUI on LenovoX1 | ||
[Documentation] Start Application via GUI test automation and verify related process started | ||
... Close Application via GUI test automation and verify related process stopped | ||
[Arguments] ${app-vm}=chromium-vm | ||
... ${app}=chromium | ||
... ${launch_icon}=../gui-ref-images/${app}/launch_icon.png | ||
... ${close_button}=../gui-ref-images/${app}/close_button.png | ||
|
||
Verify service status range=15 service=microvm@${app-vm}.service expected_status=active expected_state=running | ||
Connect to netvm | ||
Connect to VM ${GUI_VM} | ||
Check if ssh is ready on vm ${app-vm} | ||
|
||
Run Keyword And Ignore Error Execute Command -b /run/current-system/sw/bin/ydotoold --socket-path /tmp/.ydotool_socket sudo=True sudo_password=${PASSWORD} timeout=3 | ||
|
||
${mouse_x} ${mouse_y} Locate image on screen ../gui-ref-images/start_menu_x1.png | ||
Execute Command ydotool mousemove --absolute -x ${mouse_x} -y ${mouse_y} sudo=True sudo_password=${PASSWORD} | ||
Execute Command ydotool click 0xC0 sudo=True sudo_password=${PASSWORD} | ||
BuiltIn.Sleep 1 | ||
${mouse_x} ${mouse_y} Locate image on screen ${launch_icon} | ||
Execute Command ydotool mousemove --absolute -x ${mouse_x} -y ${mouse_y} sudo=True sudo_password=${PASSWORD} | ||
Execute Command ydotool click 0xC0 sudo=True sudo_password=${PASSWORD} | ||
|
||
# Move the cursor to the upper left corner so that it will not block searching further gui screenshots | ||
Execute Command ydotool mousemove --absolute -x 10 -y 10 sudo=True sudo_password=${PASSWORD} | ||
|
||
Connect to VM ${app-vm} | ||
Check that the application was started ${app} | ||
|
||
Connect to VM ${GUI_VM} | ||
${mouse_x} ${mouse_y} Locate image on screen ${close_button} | ||
Execute Command ydotool mousemove --absolute -x ${mouse_x} -y ${mouse_y} sudo=True sudo_password=${PASSWORD} | ||
Execute Command ydotool click 0xC0 sudo=True sudo_password=${PASSWORD} | ||
|
||
# Move the cursor to the upper left corner so that it will not block searching further gui screenshots | ||
Execute Command ydotool mousemove --absolute -x 10 -y 10 sudo=True sudo_password=${PASSWORD} | ||
Execute Command pkill ydotoold sudo=True sudo_password=${PASSWORD} | ||
|
||
Connect to VM ${app-vm} | ||
Check that the application is not running ${app} | ||
|
||
# In case closing the app via GUI failed | ||
[Teardown] Kill process @{app_pids} | ||
... Connect to VM ${GUI_VM} | ||
... Execute Command pkill ydotoold sudo=True sudo_password=${PASSWORD} | ||
|
||
|
||
Start and close app via GUI | ||
[Documentation] Start Application via GUI test automation and verify related process started | ||
... Close Application via GUI test automation and verify related process stopped | ||
... Only for ghaf builds where desktop is running on ghaf-host | ||
[Arguments] ${app}=firefox ${target}=agx | ||
... ${launch_icon}=../gui-ref-images/${app}/launch_icon.png | ||
... ${close_button}=../gui-ref-images/${app}/close_button.png | ||
|
||
Connect | ||
|
||
Execute Command export YDOTOOL_SOCKET=/tmp/.ydotools_socket | ||
Run Keyword And Ignore Error Execute Command -b /run/current-system/sw/bin/ydotoold sudo=True sudo_password=${PASSWORD} timeout=3 | ||
|
||
${mouse_x} ${mouse_y} Locate image on screen ../gui-ref-images/start_menu_${target}.png | ||
Execute Command ydotool mousemove --absolute -x ${mouse_x} -y ${mouse_y} sudo=True sudo_password=${PASSWORD} | ||
Execute Command ydotool click 0xC0 sudo=True sudo_password=${PASSWORD} | ||
BuiltIn.Sleep 1 | ||
${mouse_x} ${mouse_y} Locate image on screen ${launch_icon} | ||
Execute Command ydotool mousemove --absolute -x ${mouse_x} -y ${mouse_y} sudo=True sudo_password=${PASSWORD} | ||
Execute Command ydotool click 0xC0 sudo=True sudo_password=${PASSWORD} | ||
|
||
# Move the cursor to the upper left corner so that it will not block searching further gui screenshots | ||
Execute Command ydotool mousemove --absolute -x 10 -y 10 sudo=True sudo_password=${PASSWORD} | ||
|
||
BuiltIn.Sleep 1 | ||
Check that the application was started ${app} | ||
|
||
${mouse_x} ${mouse_y} Locate image on screen ${close_button} | ||
Execute Command ydotool mousemove --absolute -x ${mouse_x} -y ${mouse_y} sudo=True sudo_password=${PASSWORD} | ||
Execute Command ydotool click 0xC0 sudo=True sudo_password=${PASSWORD} | ||
|
||
# Move the cursor to the upper left corner so that it will not block searching further gui screenshots | ||
Execute Command ydotool mousemove --absolute -x 10 -y 10 sudo=True sudo_password=${PASSWORD} | ||
Execute Command pkill ydotoold sudo=True sudo_password=${PASSWORD} | ||
|
||
Check that the application is not running ${app} | ||
|
||
# In case closing the app via GUI failed | ||
[Teardown] Kill process @{app_pids} | ||
... Execute Command pkill ydotoold sudo=True sudo_password=${PASSWORD} | ||
|
||
Locate image on screen | ||
[Documentation] Take a screenshot. Locate given image on the screenshot. | ||
... Return center coordinates of the image in mouse coordinate system | ||
[Arguments] ${image_to_be_searched} | ||
Log To Console Taking screenshot | ||
Execute Command grim screenshot.png | ||
Log To Console Saving screenshot | ||
SSHLibrary.Get File screenshot.png screenshot.png | ||
Log To Console Locating image on screenshot | ||
${coordinates} Locate image ${image_to_be_searched} | ||
Log To Console Coordinates: ${coordinates} | ||
${mouse_x} Get From Dictionary ${coordinates} x | ||
${mouse_y} Get From Dictionary ${coordinates} y | ||
RETURN ${mouse_x} ${mouse_y} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ | |
python-kasa | ||
pytz | ||
pandas | ||
pyscreeze | ||
])) | ||
]; | ||
}; | ||
|