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