Skip to content

Commit

Permalink
Refactor setups and teardowns
Browse files Browse the repository at this point in the history
Signed-off-by: Mariia Azbeleva <[email protected]>
  • Loading branch information
azbeleva committed Jan 3, 2025
1 parent 5d256bb commit f3eabd0
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 63 deletions.
12 changes: 6 additions & 6 deletions Robot-Framework/resources/common_keywords.resource
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

*** Settings ***
Resource ../config/variables.robot
Resource ../resources/gui_keywords.resource


*** Keywords ***
Expand All @@ -11,12 +12,12 @@ Check that the application was started
[Arguments] ${app_name} ${range}=2
FOR ${i} IN RANGE ${range}
@{found_pids} Find pid by name ${app_name}
Set Global Variable @{app_pids} @{found_pids}
${status} Run Keyword And Return Status Should Not Be Empty ${app_pids}
Set Global Variable @{APP_PIDS} @{found_pids}
${status} Run Keyword And Return Status Should Not Be Empty ${APP_PIDS}
IF ${status} BREAK
Sleep 1
END
Should Not Be Empty ${app_pids} ${app_name} is not started
Should Not Be Empty ${APP_PIDS} ${app_name} is not started
Log To Console ${app_name} is started

Check that the application is not running
Expand All @@ -37,11 +38,10 @@ Check If Ping Fails
Should Not Be Equal ${result.rc} ${0}

Run journalctl recording
${output} Execute Command journalctl > jrnl.txt
${output} Execute Command nohup journalctl -f >> jrnl.txt 2>&1 &
${output} Execute Command nohup journalctl -f >> /tmp/jrnl.txt 2>&1 &

Log journctl
${output} Execute Command cat jrnl.txt
${output} Execute Command cat /tmp/jrnl.txt
Log ${output}
@{pid} Find pid by name journalctl
Kill process @{pid}
Expand Down
4 changes: 2 additions & 2 deletions Robot-Framework/resources/connection_keywords.resource
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Initialize Variables And Connect
IF ${port_22_is_available} == False
FAIL Failed because port 22 of device was not available, tests can not be run.
END
${CONNECTION} Connect
Set Suite Variable ${CONNECTION}
${CONNECTION} Connect to ghaf host
Set Global Variable ${CONNECTION}

Initialize Variables, Connect And Start Logging
Initialize Variables And Connect
Expand Down
14 changes: 13 additions & 1 deletion Robot-Framework/resources/gui_keywords.resource
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Resource ../config/variables.robot
Library ../lib/gui_testing.py
Library Collections


*** Variables ***

${START_MENU} ./launcher.png
Expand All @@ -16,6 +17,7 @@ ${LOGGED_IN_STATUS} ${True}

GUI Log in
[Documentation] Login and verify that task bar is available
Switch Connection ${CONNECTION}
Verify logout
IF ${LOGGED_IN_STATUS}
Log To Console Already logged in. Skipping login.
Expand All @@ -26,10 +28,12 @@ GUI Log in
Type string and press enter ${USER_LOGIN}
Type string and press enter ${USER_PASSWORD}
END
Verify login

GUI Log out
[Documentation] Log out and optionally verify that desktop is not available
[Arguments] ${log_out_icon}=./logout.png
Switch Connection ${CONNECTION}
Start ydotoold
Get icon ghaf-artwork power.svg crop=0 background=black
Locate and click ./icon.png 0.95 5
Expand All @@ -38,6 +42,7 @@ GUI Log out

Type string and press enter
[Arguments] ${string}=${EMPTY}
Connect to VM ${GUI_VM}
Log To Console Typing
IF $string != '${EMPTY}'
Execute Command ydotool type ${string} sudo=True sudo_password=${PASSWORD}
Expand All @@ -55,7 +60,6 @@ Locate image on screen
FOR ${i} IN RANGE ${iterations}
Log To Console Taking screenshot
Execute Command rm screenshot.png
${rc}= Set Variable 1
${rc}= Execute Command grim screenshot.png return_stdout=False return_rc=${true} timeout=5
IF "${rc}" == "0"
SSHLibrary.Get File screenshot.png screenshot.png
Expand All @@ -80,6 +84,7 @@ Locate and click

Start ydotoold
[Documentation] Start ydotool daemon if it is not already running.
Connect to VM ${GUI_VM}
${ydotoold_state}= Execute Command sh -c 'ps aux | grep ydotoold | grep -v grep'
IF $ydotoold_state == '${EMPTY}'
Log To Console Starting ydotool daemon
Expand All @@ -106,9 +111,16 @@ Verify login
Log To Console Verifying login by trying to detect the launcher icon
Locate image on screen ${START_MENU} 0.95 15

Move cursor
Start ydotoold
${x} Evaluate random.randint(50, 500) modules=random
${y} Evaluate random.randint(50, 500) modules=random
Execute Command ydotool mousemove --absolute -x ${x} -y ${y} sudo=True sudo_password=${PASSWORD}

Verify logout
[Documentation] Check that dekstop is not available by running 'grim' which should have return code 1 in this case
[Arguments] ${iterations}=5

${status}= Set Variable ${EMPTY}
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
FOR ${i} IN RANGE ${iterations}
Expand Down
9 changes: 7 additions & 2 deletions Robot-Framework/resources/ssh_keywords.resource
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ Connect to netvm
BREAK
END
IF ${failed_connection} FAIL Couldn't connect NetVM
Set Global Variable ${netvm_ssh} ${connection}
RETURN ${netvm_ssh}
Set Global Variable ${NETVM_SSH} ${connection}
RETURN ${NETVM_SSH}

Connect to VM
[Arguments] ${vm_name} ${user}=${LOGIN} ${pw}=${PASSWORD}
Expand Down Expand Up @@ -159,6 +159,9 @@ Start XDG application
${output} Execute Command cat /run/current-system/sw/share/applications/${app_name}.desktop
${path} Get App Path From Desktop ${output}
Execute Command nohup sh -c '${path}' > output.log 2>&1 &
Sleep 8
${output} Execute Command cat output.log
Log ${output}

Start Firefox
[Documentation] It's needed to set display variable manually because there is no real monitor connected to DUT
Expand Down Expand Up @@ -328,6 +331,7 @@ Check if ssh is ready on netvm

Check if ssh is ready on vm
[Arguments] ${vm} ${timeout}=30
Switch Connection ${NETVM_SSH}
${start_time} Get Time epoch
FOR ${i} IN RANGE ${timeout}
${output} ${rc} Execute Command nc -zvw3 ${vm} 22 return_rc=True
Expand Down Expand Up @@ -491,6 +495,7 @@ Connect to VM if not already connected

Detect first boot
[Documentation] Determine desktop state after boot by attempting login to gui-vm as testuser
Connect
Log To Console Detecting if this is first boot by trying test user credentials
Verify service status range=15 [email protected] expected_status=active expected_state=running
Connect to netvm
Expand Down
25 changes: 18 additions & 7 deletions Robot-Framework/test-suites/bat-tests/__init__.robot
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ Resource ../../resources/ssh_keywords.resource
Resource ../../resources/serial_keywords.resource
Resource ../../resources/common_keywords.resource
Resource ../../resources/connection_keywords.resource
Suite Setup Initialize Variables, Connect And Start Logging
Suite Teardown End Logging And Close Connections
Suite Setup BAT tests setup
Suite Teardown BAT tests teardown


*** Keywords ***

End Logging And Close Connections
IF ${CONNECTION}
Connect
Log journctl
BAT tests setup
Initialize Variables, Connect And Start Logging

IF "Lenovo" in "${DEVICE}"
Connect to netvm
Connect to VM ${GUI_VM}
Save most common icons and paths to icons
Create test user
GUI Log in
END
Close All Connections

BAT tests teardown
Connect to ghaf host
Log journctl
Connect to netvm
GUI Log out
Close All Connections
24 changes: 12 additions & 12 deletions Robot-Framework/test-suites/bat-tests/apps.robot
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Force Tags apps
Resource ../../resources/ssh_keywords.resource
Resource ../../config/variables.robot
Resource ../../resources/common_keywords.resource
Suite Teardown Close All Connections
Test Setup Run Keywords Move cursor AND Switch Connection ${CONNECTION}


*** Variables ***
Expand All @@ -31,8 +31,8 @@ Start Chrome on LenovoX1
[Tags] bat pre-merge SP-T92 lenovo-x1
Verify service status range=15 [email protected] expected_status=active expected_state=running
Connect to netvm
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Check if ssh is ready on vm ${CHROME_VM}
${vm_ssh} Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Start XDG application 'Google Chrome'
Connect to VM ${CHROME_VM}
Check that the application was started chrome
Expand All @@ -41,9 +41,9 @@ Start Chrome on LenovoX1
Start Zathura on LenovoX1
[Documentation] Start Zathura in dedicated VM and verify process started
[Tags] bat pre-merge SP-T105 lenovo-x1
[Setup] Connect to netvm
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Connect to netvm
Check if ssh is ready on vm ${ZATHURA_VM}
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Start XDG application 'PDF Viewer'
Connect to VM ${ZATHURA_VM}
Check that the application was started zathura
Expand All @@ -54,9 +54,9 @@ Start Zathura on LenovoX1
Start Gala on LenovoX1
[Documentation] Start Gala in dedicated VM and verify process started
[Tags] bat pre-merge SP-T104 lenovo-x1
[Setup] Connect to netvm
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Connect to netvm
Check if ssh is ready on vm ${GALA_VM}
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Start XDG application GALA
Connect to VM ${GALA_VM}
Check that the application was started gala
Expand All @@ -65,9 +65,9 @@ Start Gala on LenovoX1
Start Element on LenovoX1
[Documentation] Start Element in dedicated VM and verify process started
[Tags] bat pre-merge SP-T52 lenovo-x1
[Setup] Connect to netvm
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Connect to netvm
Check if ssh is ready on vm ${COMMS_VM}
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Start XDG application Element
Connect to VM ${COMMS_VM}
Check that the application was started element
Expand All @@ -76,9 +76,9 @@ Start Element on LenovoX1
Start Slack on LenovoX1
[Documentation] Start Slack in dedicated VM and verify process started
[Tags] bat pre-merge SP-T181 lenovo-x1
[Setup] Connect to netvm
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Connect to netvm
Check if ssh is ready on vm ${COMMS_VM}
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Start XDG application Slack
Connect to VM ${COMMS_VM}
Check that the application was started slack
Expand All @@ -87,9 +87,9 @@ Start Slack on LenovoX1
Start Appflowy on LenovoX1
[Documentation] Start Appflowy in dedicated VM and verify process started
[Tags] appflowy # Removed bat tag & lenovo-x1 tag until final decision of this app is made
[Setup] Connect to netvm
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Connect to netvm
Check if ssh is ready on vm appflowy-vm
Connect to VM ${GUI_VM} ${USER_LOGIN} ${USER_PASSWORD}
Start XDG application AppFlowy
Connect to VM ${APPFLOWY_VM}
Check that the application was started appflowy
Expand Down
11 changes: 2 additions & 9 deletions Robot-Framework/test-suites/bat-tests/business_vm.robot
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Resource ../../resources/ssh_keywords.resource
Resource ../../resources/virtualization_keywords.resource
Resource ../../config/variables.robot
Resource ../../resources/common_keywords.resource

Suite Teardown Close All Connections
Test Setup Move cursor
Test Teardown Kill process @{APP_PIDS}


*** Test Cases ***
Expand All @@ -22,7 +22,6 @@ Start Microsoft Outlook on LenovoX1
Start XDG application "Microsoft Outlook"
Connect to VM ${BUSINESS_VM}
Check that the application was started outlook
[Teardown] Kill process @{app_pids}

Start Microsoft 365 on LenovoX1
[Documentation] Start Microsoft 365 in Business-vm and verify process started
Expand All @@ -32,7 +31,6 @@ Start Microsoft 365 on LenovoX1
Start XDG application "Microsoft 365"
Connect to VM ${BUSINESS_VM}
Check that the application was started microsoft365
[Teardown] Kill process @{app_pids}

Start Microsoft Teams on LenovoX1
[Documentation] Start Microsoft Teams in Business-vm and verify process started
Expand All @@ -42,7 +40,6 @@ Start Microsoft Teams on LenovoX1
Start XDG application Teams
Connect to VM ${BUSINESS_VM}
Check that the application was started teams
[Teardown] Kill process @{app_pids}

Start Trusted Browser on LenovoX1
[Documentation] Start Trusted Browser in Business-vm and verify process started
Expand All @@ -52,7 +49,6 @@ Start Trusted Browser on LenovoX1
Start XDG application "Trusted Browser"
Connect to VM ${BUSINESS_VM}
Check that the application was started chrome
[Teardown] Kill process @{app_pids}

Start Video Editor on LenovoX1
[Documentation] Start Video Editor in Business-vm and verify process started
Expand All @@ -62,7 +58,6 @@ Start Video Editor on LenovoX1
Start XDG application "Video Editor"
Connect to VM ${BUSINESS_VM}
Check that the application was started lossless
[Teardown] Kill process @{app_pids}

Start Text Editor on LenovoX1
[Documentation] Start Text Editor in Business-vm and verify process started
Expand All @@ -72,7 +67,6 @@ Start Text Editor on LenovoX1
Start XDG application "Text Editor"
Connect to VM ${BUSINESS_VM}
Check that the application was started text-editor
[Teardown] Kill process @{app_pids}

Start Xarchiver on LenovoX1
[Documentation] Start Xarchiver in Business-vm and verify process started
Expand All @@ -82,4 +76,3 @@ Start Xarchiver on LenovoX1
Start XDG application "Xarchiver"
Connect to VM ${BUSINESS_VM}
Check that the application was started xarchiver
[Teardown] Kill process @{app_pids}
Loading

0 comments on commit f3eabd0

Please sign in to comment.