xref: /openbmc/openbmc-test-automation/gui/lib/gui_resource.robot (revision 286e2f07a1261ad043902a6db05d39429a31a1d4)
1*** Settings ***
2Documentation  This is a resource file containing user-defined keywords for new Vue based OpenBMC GUI.
3
4Library        XvfbRobot
5Library        SeleniumLibrary
6Library        SSHLibrary  30 Seconds
7Resource       ../../lib/state_manager.robot
8Variables      ../data/gui_variables.py
9
10
11*** Variables ***
12${OPENBMC_GUI_URL}              https://${OPENBMC_HOST}:${HTTPS_PORT}
13${xpath_power_page}          //*[@data-test-id='appHeader-container-power']
14${xpath_power_shutdown}      //*[@data-test-id='serverPowerOperations-button-shutDown']
15${xpath_power_power_on}      //*[@data-test-id='serverPowerOperations-button-powerOn']
16${xpath_power_reboot}        //*[@data-test-id='serverPowerOperations-button-reboot']
17${xpath_confirm}             //button[contains(text(),'Confirm')]
18
19# Default GUI browser and mode is set to "Firefox" and "headless"
20# respectively here.
21${GUI_BROWSER}               ff
22${GUI_MODE}                  headless
23
24
25*** Keywords ***
26
27Open Browser With URL
28    [Documentation]  Open browser with specified URL and returns browser id.
29    [Arguments]  ${URL}  ${browser}=ff  ${mode}=${GUI_MODE}
30
31    # Description of argument(s):
32    # URL      Openbmc GUI URL to be open
33    #          (e.g. https://openbmc-test.mybluemix.net/#/login).
34    # browser  Browser used to open above URL
35    #          (e.g. gc for google chrome, ff for firefox).
36    # mode     Browser opening mode(e.g. headless, header).
37
38    IF  '${mode}' == 'headless'
39       ${browser_ID}=  Launch Headless Browser  ${URL}  ${browser}
40    ELSE
41       ${browser_ID}=  Open Browser  ${URL}  ${browser}
42    END
43    RETURN  ${browser_ID}
44
45
46Launch Header Browser
47    [Documentation]  Open the browser with the URL and
48    ...              login on windows platform.
49    [Arguments]  ${browser_type}=${GUI_BROWSER}
50
51    # Description of argument(s):
52    # browser_type  Type of browser (e.g. "firefox", "chrome", etc.).
53
54    ${BROWSER_ID}=  Open Browser  ${OPENBMC_GUI_URL}  ${browser_type}
55    Maximize Browser Window
56    Set Global Variable  ${BROWSER_ID}
57
58
59Launch Headless Browser
60    [Documentation]  Launch headless browser.
61    [Arguments]  ${URL}=${OPENBMC_GUI_URL}  ${browser}=${GUI_BROWSER}
62
63    # Description of argument(s):
64    # URL      Openbmc GUI URL to be open
65    #          (e.g. https://openbmc-test.mybluemix.net/#/login).
66    # browser  Browser to open given URL in headless way
67    #          (e.g. gc for google chrome, ff for firefox).
68
69    Start Virtual Display
70    ${browser_ID}=  Open Browser  ${URL}    ${browser}
71    Set Window Size  1920  1080
72
73    RETURN  ${browser_ID}
74
75
76Launch Browser And Login GUI
77    [Documentation]  Launch browser and login to OpenBMC GUI, retry 2 attempts
78    ...              in 1 minute time.
79
80    Wait Until Keyword Succeeds  195 sec   65 sec  Retry Browser Login Attempts
81
82
83Retry Browser Login Attempts
84    [Documentation]  Launch browser and login to OpenBMC GUI.
85
86    Open Browser With URL  ${OPENBMC_GUI_URL}
87    Login GUI  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
88
89
90Login GUI
91    [Documentation]  Login to OpenBMC GUI.
92    [Arguments]  ${username}=${OPENBMC_USERNAME}  ${password}=${OPENBMC_PASSWORD}
93
94    # Description of argument(s):
95    # username  The username to be used for login.
96    # password  The password to be used for login.
97
98    Go To  ${OPENBMC_GUI_URL}
99    Wait Until Element Is Enabled  ${xpath_login_username_input}
100    Input Text  ${xpath_login_username_input}  ${username}
101    Input Password  ${xpath_login_password_input}  ${password}
102    Wait Until Element Is Enabled  ${xpath_login_button}
103    Click Element  ${xpath_login_button}
104    Wait Until Page Contains  Overview  timeout=60s
105    Wait Until Element Is Not Visible
106    ...  ${xpath_page_loading_progress_bar}  timeout=120s
107
108Launch Browser And Login GUI With Given User
109    [Documentation]  Launch browser and login eBMC with specified user
110    ...  credentials through GUI.
111    [Arguments]  ${user_name}  ${user_password}
112
113    # Description of argument(s):
114    # user_name        User name to login to eBMC.
115    # user_password    User password to login to eBMC.
116
117    Open Browser With URL  ${OPENBMC_GUI_URL}
118    LOGIN GUI  ${user_name}  ${user_password}
119
120Logout GUI
121    [Documentation]  Logout of OpenBMC GUI.
122
123    Click Element  ${xpath_root_button_menu}
124    Click Element  ${xpath_logout_button}
125    Wait Until Page Contains Element  ${xpath_login_button}
126
127
128Generate Test Error Log
129    [Documentation]  Generate test error log.
130
131    BMC Execute Command  ${CMD_UNRECOVERABLE_ERROR}
132
133
134Set Timezone In Profile Settings Page
135    [Documentation]  Set the given timezone in profile settings page.
136    [Arguments]  ${timezone}=Default
137
138    # Description of argument(s):
139    # timezone  Timezone to select (eg. Default or Browser_offset).
140
141    Wait Until Page Contains Element  ${xpath_root_button_menu}
142    Click Element  ${xpath_root_button_menu}
143    Click Element  ${xpath_profile_settings}
144    Click Element At Coordinates  ${xpath_default_UTC}  0  0
145    Click Element  ${xpath_profile_save_button}
146
147
148Refresh GUI
149    [Documentation]  Refresh GUI via refresh button in header.
150
151    Click Element  ${xpath_refresh_button}
152    # Added delay for page to load fully after refresh.
153    Sleep  5s
154
155
156Refresh GUI And Verify Element Value
157    [Documentation]  Refresh GUI using refresh button and verify that given element contains expected value.
158    [Arguments]  ${element}  ${expected_value}
159
160    # Description of argument(s):
161    # element         Element whose value need to be checked.
162    # expected_value  Expected value of for the given element.
163
164    # Refresh GUI.
165
166    Click Element  ${xpath_refresh_button}
167
168    # Check element value and verify that it contains expected value.
169    ${element_value}=  Get Text  ${element}
170    Log  ${element_value}
171    Should Contain  ${element_value}  ${expected_value}
172
173
174Reboot BMC via GUI
175    [Documentation]  Reboot BMC via GUI.
176
177    Click Element  ${xpath_operations_menu}
178    Click Element  ${xpath_reboot_bmc_sub_menu}
179    Click Button  ${xpath_reboot_bmc_button}
180    Wait Until Keyword Succeeds  30 sec  10 sec  Click Button  ${xpath_confirm_bmc_reboot}
181    Wait Until Keyword Succeeds  2 min  10 sec  Is BMC Unpingable
182    Wait For Host To Ping  ${OPENBMC_HOST}  1 min
183
184
185Add DNS Servers And Verify
186    [Documentation]  Login to GUI Network page,add DNS server on BMC
187    ...  and verify it via BMC CLI.
188    [Arguments]  ${dns_server}   ${expected_status}=Valid format
189
190    # Description of the argument(s):
191    # dns_server           A list of static name server IPs to be
192    #                      configured on the BMC.
193    # expected_status      Expected status while adding DNS server address
194    #                      (e.g. Invalid format / Field required).
195
196    Wait Until Page Contains Element  ${xpath_add_dns_ip_address_button}  timeout=15sec
197
198    Click Button  ${xpath_add_dns_ip_address_button}
199    Input Text  ${xpath_input_static_dns}  ${dns_server}
200    Click Button  ${xpath_add_button}
201    Run keyword if  '${expected_status}' != 'Valid format'
202    ...  Run keywords  Page Should Contain  ${expected_status}  AND  Return From Keyword
203
204    Wait Until Page Contains Element  ${xpath_add_dns_ip_address_button}  timeout=10sec
205    Wait Until Page Contains  ${dns_server}  timeout=40sec
206
207    # Check if newly added DNS server is configured on BMC.
208    ${cli_name_servers}=  CLI Get Nameservers
209    ${cmd_status}=  Run Keyword And Return Status
210    ...  List Should Contain Sub List  ${cli_name_servers}  ${dns_server}
211    IF  '${expected_status}' == '${HTTP_OK}'
212       Should Be True  ${cmd_status} == ${True}
213    ELSE
214       Should Not Be True  ${cmd_status}
215    END
216
217
218Navigate To Server Power Page
219    [Documentation]  Navigate To Server Power Page.
220
221    Click Element  ${xpath_power_page}
222    Wait Until Element Is Not Visible  ${xpath_progress_bar}  timeout=30
223
224
225Power Off Server
226    [Documentation]  Powering off server.
227
228    Navigate To Server Power Page
229    ${present}=    Run Keyword And Return Status
230    ...  Element Should Be Visible    ${xpath_power_shutdown}
231    IF  ${present}
232      Click Element  ${xpath_power_shutdown}
233      Click Button  ${xpath_confirm}
234      Wait Until Element Is Visible  ${xpath_power_poweron}  timeout=60
235    ELSE
236      Log To console    Server is already powered Off.
237    END
238
239
240Power On Server
241    [Documentation]  Powering on server.
242
243    Navigate To Server Power Page
244    ${present}=    Run Keyword And Return Status
245    ...  Element Should Be Visible    ${xpath_power_power_on}
246    IF  (${present})
247      Click Element  ${xpath_power_power_on}
248      Wait Until Element Is Visible  ${xpath_power_shutdown}  timeout=60
249    ELSE
250      Log To console    Server is already powered On.
251    END
252
253
254Reboot Server
255    [Documentation]  Rebooting the server.
256
257    Navigate To Server Power Page
258    ${present}=    Run Keyword And Return Status
259    ...  Element Should Be Visible    ${xpath_power_reboot}
260    IF  ${present}
261      Click Element  ${xpath_power_reboot}
262      Wait Until Element Is Visible  ${xpath_confirm}  timeout=30
263      Click Button  ${xpath_confirm}
264      Wait Until Element Is Visible  ${xpath_power_reboot}  timeout=60
265    ELSE
266      Log To console    Server is already powered Off, can't reboot.
267    END
268