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}
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
107Logout GUI
108    [Documentation]  Logout of OpenBMC GUI.
109
110    Click Element  ${xpath_root_button_menu}
111    Click Element  ${xpath_logout_button}
112    Wait Until Page Contains Element  ${xpath_login_button}
113
114
115Generate Test Error Log
116    [Documentation]  Generate test error log.
117
118    BMC Execute Command  ${CMD_UNRECOVERABLE_ERROR}
119
120
121Set Timezone In Profile Settings Page
122    [Documentation]  Set the given timezone in profile settings page.
123    [Arguments]  ${timezone}=Default
124
125    # Description of argument(s):
126    # timezone  Timezone to select (eg. Default or Browser_offset).
127
128    Wait Until Page Contains Element  ${xpath_root_button_menu}
129    Click Element  ${xpath_root_button_menu}
130    Click Element  ${xpath_profile_settings}
131    Click Element At Coordinates  ${xpath_default_UTC}  0  0
132    Click Element  ${xpath_profile_save_button}
133
134
135Refresh GUI
136    [Documentation]  Refresh GUI via refresh button in header.
137
138    Click Element  ${xpath_refresh_button}
139    # Added delay for page to load fully after refresh.
140    Sleep  5s
141
142
143Refresh GUI And Verify Element Value
144    [Documentation]  Refresh GUI using refresh button and verify that given element contains expected value.
145    [Arguments]  ${element}  ${expected_value}
146
147    # Description of argument(s):
148    # element         Element whose value need to be checked.
149    # expected_value  Expected value of for the given element.
150
151    # Refresh GUI.
152
153    Click Element  ${xpath_refresh_button}
154
155    # Check element value and verify that it contains expected value.
156    ${element_value}=  Get Text  ${element}
157    Log  ${element_value}
158    Should Contain  ${element_value}  ${expected_value}
159
160
161Reboot BMC via GUI
162    [Documentation]  Reboot BMC via GUI.
163
164    Click Element  ${xpath_operations_menu}
165    Click Element  ${xpath_reboot_bmc_sub_menu}
166    Click Button  ${xpath_reboot_bmc_button}
167    Wait Until Keyword Succeeds  30 sec  10 sec  Click Button  ${xpath_confirm_bmc_reboot}
168    Wait Until Keyword Succeeds  2 min  10 sec  Is BMC Unpingable
169    Wait For Host To Ping  ${OPENBMC_HOST}  1 min
170
171
172Add DNS Servers And Verify
173    [Documentation]  Login to GUI Network page,add DNS server on BMC
174    ...  and verify it via BMC CLI.
175    [Arguments]  ${dns_server}   ${expected_status}=Valid format
176
177    # Description of the argument(s):
178    # dns_server           A list of static name server IPs to be
179    #                      configured on the BMC.
180    # expected_status      Expected status while adding DNS server address
181    #                      (e.g. Invalid format / Field required).
182
183    Wait Until Page Contains Element  ${xpath_add_dns_ip_address_button}  timeout=15sec
184
185    Click Button  ${xpath_add_dns_ip_address_button}
186    Input Text  ${xpath_input_static_dns}  ${dns_server}
187    Click Button  ${xpath_add_button}
188    Run keyword if  '${expected_status}' != 'Valid format'
189    ...  Run keywords  Page Should Contain  ${expected_status}  AND  Return From Keyword
190
191    Wait Until Page Contains Element  ${xpath_add_dns_ip_address_button}  timeout=10sec
192    Wait Until Page Contains  ${dns_server}  timeout=40sec
193
194    # Check if newly added DNS server is configured on BMC.
195    ${cli_name_servers}=  CLI Get Nameservers
196    ${cmd_status}=  Run Keyword And Return Status
197    ...  List Should Contain Sub List  ${cli_name_servers}  ${dns_server}
198    Run Keyword If  '${expected_status}' == '${HTTP_OK}'
199    ...  Should Be True  ${cmd_status} == ${True}
200    ...  ELSE  Should Not Be True  ${cmd_status}
201
202
203Navigate To Server Power Page
204    [Documentation]  Navigate To Server Power Page.
205
206    Click Element  ${xpath_power_page}
207    Wait Until Element Is Not Visible  ${xpath_progress_bar}  timeout=30
208
209
210Power Off Server
211    [Documentation]  Powering off server.
212
213    Navigate To Server Power Page
214    ${present}=    Run Keyword And Return Status
215    ...  Element Should Be Visible    ${xpath_power_shutdown}
216    IF  ${present}
217      Click Element  ${xpath_power_shutdown}
218      Click Button  ${xpath_confirm}
219      Wait Until Element Is Visible  ${xpath_power_poweron}  timeout=60
220    ELSE
221      Log To console    Server is already powered Off.
222    END
223
224
225Power On Server
226    [Documentation]  Powering on server.
227
228    Navigate To Server Power Page
229    ${present}=    Run Keyword And Return Status
230    ...  Element Should Be Visible    ${xpath_power_power_on}
231    IF  (${present})
232      Click Element  ${xpath_power_power_on}
233      Wait Until Element Is Visible  ${xpath_power_shutdown}  timeout=60
234    ELSE
235      Log To console    Server is already powered On.
236    END
237
238
239Reboot Server
240    [Documentation]  Rebooting the server.
241
242    Navigate To Server Power Page
243    ${present}=    Run Keyword And Return Status
244    ...  Element Should Be Visible    ${xpath_power_reboot}
245    IF  ${present}
246      Click Element  ${xpath_power_reboot}
247      Wait Until Element Is Visible  ${xpath_confirm}  timeout=30
248      Click Button  ${xpath_confirm}
249      Wait Until Element Is Visible  ${xpath_power_reboot}  timeout=60
250    ELSE
251      Log To console    Server is already powered Off, can't reboot.
252    END
253