1*** Settings ***
2
3Documentation   Test OpenBMC GUI "Date and time" sub-menu of "Settings".
4
5Resource        ../../lib/gui_resource.robot
6
7Suite Setup     Suite Setup Execution
8Suite Teardown  Suite Teardown Execution
9Test Setup      Navigate To Date and Time Page
10
11*** Variables ***
12
13${xpath_date_time_heading}       //h1[text()="Date and time"]
14${xpath_select_manual}           //*[@data-test-id="dateTime-radio-configureManual"]
15${xpath_select_ntp}              //*[@data-test-id="dateTime-radio-configureNTP"]
16${xpath_manual_date}             //input[@data-test-id="dateTime-input-manualDate"]
17${xpath_manual_time}             //input[@data-test-id="dateTime-input-manualTime"]
18${xpath_ntp_server1}             //input[@data-test-id="dateTime-input-ntpServer1"]
19${xpath_ntp_server2}             //input[@data-test-id="dateTime-input-ntpServer2"]
20${xpath_ntp_server3}             //input[@data-test-id="dateTime-input-ntpServer3"]
21${xpath_select_save_settings}    //button[@data-test-id="dateTime-button-saveSettings"]
22${xpath_invalid_format_message}  //*[contains(text(), "Invalid format")]
23${LOOP_COUNT}                    2
24
25*** Test Cases ***
26
27Verify Navigation To Date And Time Page
28    [Documentation]  Verify navigation to date and time page.
29    [Tags]  Verify_Navigation_To_Date_And_Time_Page
30
31    Page Should Contain Element  ${xpath_date_time_heading}
32
33
34Verify Text Under Date And Time Page
35    [Documentation]  Verify the presence of the required text on the date and time page.
36    [Tags]  Verify_Text_Under_Date_And_Time_Page
37
38
39    Page Should Contain  To change how date and time are displayed
40    ...  (either UTC or browser offset) throughout the application, visit Profile Settings
41
42    Page Should Contain  If NTP is selected but an NTP server is not given or the
43    ...  given NTP server is not reachable, then time.google.com will be used.
44
45
46Verify Existence Of All Sections In Date And Time Page
47    [Documentation]  Verify existence of all sections in date and time page.
48    [Tags]  Verify_Existence_Of_All_Sections_In_Date_And_Time_Page
49
50    Page Should Contain  Configure settings
51
52
53Verify Existence Of All Buttons In Date And Time Page
54    [Documentation]  Verify existence of all buttons in date and time settings page.
55    [Tags]  Verify_Existence_Of_All_Buttons_In_Date_And_Time_Page
56
57    Page Should Contain Element  ${xpath_select_manual}
58    Page Should Contain Element  ${xpath_select_ntp}
59    Page Should Contain Element  ${xpath_select_save_settings}
60
61
62Verify Existence Of All Input Boxes In Date And Time Page
63    [Documentation]  Verify existence of all input boxes in date time page.
64    [Tags]  Verify_Existence_Of_All_Input_Boxes_In_Date_And_Time_Page
65
66    Click Element At Coordinates  ${xpath_select_manual}  0  0
67    Page Should Contain Element  ${xpath_manual_date}
68    Page Should Contain Element  ${xpath_manual_time}
69
70    Click Element At Coordinates  ${xpath_select_ntp}  0  0
71    Page Should Contain Element  ${xpath_ntp_server1}
72    Page Should Contain Element  ${xpath_ntp_server2}
73    Page Should Contain Element  ${xpath_ntp_server3}
74
75
76Verify Date And Time From Configuration Section
77    [Documentation]  Get date and time from configuration section and verify it via BMC CLI.
78    [Tags]  Verify_Date_And_Time_From_Configuration_Section
79
80    Click Element At Coordinates  ${xpath_select_manual}  0  0
81    ${manual_date}=  Get Value  ${xpath_manual_date}
82    ${manual_time}=  Get Value  ${xpath_manual_time}
83
84    ${cli_date_time}=  CLI Get BMC DateTime
85    Should contain  ${cli_date_time}  ${manual_date}  ${manual_time}
86
87
88Verify Display Of Date And Time In GUI Page
89     [Documentation]  Get date and time from Redfish and verify it via GUI date and time page.
90     [Tags]  Verify_Display_Of_Date_And_Time_In_GUI_Page
91
92    # Set Default timezone in profile settings page.
93    Set Timezone In Profile Settings Page  Default
94    Navigate To Date and Time Page
95
96    # Get date and time from Redfish.
97    ${redfish_date_time}=  CLI Get BMC DateTime
98    ${redfish_date}=  Convert Date  ${redfish_date_time}  result_format=%Y-%m-%d
99    ${redfish_time}=  Convert Date  ${redfish_date_time}  result_format=%H:%M
100
101    # Verify date and time via GUI date and time page.
102
103    Page Should Contain  ${redfish_date}
104    Page Should Contain  ${redfish_time}
105
106
107Verify Profile Setting Button In Date And Time Page
108    [Documentation]  Verify navigation to profile setting page after clicking
109    ...  on profile setting button in date and time page.
110    [Tags]  Verify_Profile_Setting_Button_In_Date_And_Time_Page
111
112    Click Element   ${xpath_profile_settings_link}
113    Wait Until Page Contains Element  ${xpath_profile_settings_heading}  timeout=10
114    Location Should Contain   profile-settings
115
116
117Verify Existence Of Timezone Buttons In Profile Settings Page
118    [Documentation]  Verify default UTC button and browser offset IST button
119    ...  in Profile settings page
120    [Tags]  Verify_Existence_Of_Timezone_Buttons_In_Profile_Settings_Page
121
122    Click Element   ${xpath_profile_settings_link}
123    Wait Until Page Contains Element  ${xpath_profile_settings_heading}  timeout=30
124    Page Should Contain Element  ${xpath_default_UTC}
125    Page Should Contain Element  ${xpath_browser_offset}
126
127
128Verify Date And Time Change To Browser Offset Time
129    [Documentation]  Verify date and time change to broswer's offset time when
130    ...  'Browser offset' option is selected in Profile settings page.
131    [Tags]   Verify_Date_And_Time_Change_To_Browser_Offset_Time
132
133    Click Element   ${xpath_profile_settings_link}
134    Wait Until Page Contains Element  ${xpath_profile_settings_heading}  timeout=10
135    Click Element At Coordinates  ${xpath_browser_offset}  0  0
136    Click Element   ${xpath_profile_save_button}
137    ${xpath_browser_offset_text}=  Get Text  ${xpath_browser_offset_textfield}
138
139    # We get an output ${xpath_browser_offset_text} = Browser offset (CST UTC-6).
140    # Need to compare "CST UTC-6" text so removing the spaces and other values.
141
142    ${text}=  Set Variable  ${xpath_browser_offset_text.split("(")[1].split(")")[0]}
143    Navigate To Date and Time Page
144    Page Should Contain  ${text}
145
146
147Verify NTP Server Input Fields In Date And Time Page
148    [Documentation]  Verify NTP server input fields in date and time page.
149    [Tags]  Verify_NTP_Server_Input_Fields_In_Date_And_Time_Page
150    [Setup]  Setup To Power Off And Navigate
151
152    Click Element At Coordinates  ${xpath_select_ntp}  0  0
153    Input Text  ${xpath_ntp_server1}  10.10.10.10
154    Input Text  ${xpath_ntp_server2}  20.20.20.20
155    Input Text  ${xpath_ntp_server3}  30.30.30.30
156    Click Element  ${xpath_select_save_settings}
157
158
159    # Refresh the NTP Page.
160    Click Element  ${xpath_refresh_button}
161    Wait Until Page Contains Element  ${xpath_select_ntp}  timeout=10s
162
163    Textfield Value Should Be  ${xpath_ntp_server1}  10.10.10.10
164    Textfield Value Should Be  ${xpath_ntp_server2}  20.20.20.20
165    Textfield Value Should Be  ${xpath_ntp_server3}  30.30.30.30
166
167
168Verify Setting Manual BMC Time
169    [Documentation]  Verify changing manual time and comparing it with CLI time.
170    [Tags]  Verify_Setting_Manual_BMC_Time
171    [Setup]  Run Keywords  Set Timezone In Profile Settings Page
172    ...  Default  AND  Setup To Power Off And Navigate
173
174    Click Element At Coordinates  ${xpath_select_manual}  0  0
175    Input Text  ${xpath_manual_date}  2023-05-12
176    Input Text  ${xpath_manual_time}  15:30
177    Click Element  ${xpath_select_save_settings}
178
179    # Wait for changes to take effect.
180    Sleep  120
181    ${manual_date}=  Get Value  ${xpath_manual_date}
182    ${manual_time}=  Get Value  ${xpath_manual_time}
183
184    ${cli_date_time}=  CLI Get BMC DateTime
185    Should contain  ${cli_date_time}  ${manual_date}  ${manual_time}
186
187
188Verify Setting Invalid Date And Time Is Not Allowed
189    [Documentation]  Verify if invalid date and invalid time input is given,
190    ...  it should throw error.
191    [Tags]  Verify_Setting_Invalid_Date_And_Time_Is_Not_Allowed
192    [Setup]  Setup To Power Off And Navigate
193
194    Click Element At Coordinates  ${xpath_select_manual}  0  0
195    Input Text  ${xpath_manual_date}  2023-18-48
196    Page Should Contain Element  ${xpath_invalid_format_message}
197    Input Text  ${xpath_manual_time}  29:48
198    Page Should Contain Element  ${xpath_invalid_format_message}
199
200
201Verify Changing BMC Time From NTP To Manual
202    [Documentation]  Verify that BMC time can be changed from NTP to
203    ...  manual time via GUI.
204    [Tags]  Verify_Changing_BMC_Time_From_NTP_To_Manual
205    [Setup]  Setup To Power Off And Navigate
206
207    # Add NTP server for BMC time to sync.
208    Click Element At Coordinates  ${xpath_select_ntp}  0  0
209    Input Text  ${xpath_ntp_server1}  time.google.com
210    Click Element  ${xpath_select_save_settings}
211
212    # Wait for changes to take effect.
213    Wait Until Page Contains Element  ${xpath_select_ntp}  timeout=30s
214
215    # Set the manual date and time.
216    ${cli_date_time}=  CLI Get BMC DateTime
217    ${date_changed}=  Add Time To Date  ${cli_date_time}  31 days
218    ${date_changed}=  Add Time To Date  ${date_changed}  05:10:00
219    Log  "Setting BMC date : ${date_changed} using Manual option"
220    ${date}=  Convert Date  ${date_changed}  result_format=%Y-%m-%d
221    ${time}=  Convert Date  ${date_changed}  result_format=%H:%M
222    Click Element At Coordinates  ${xpath_select_manual}  0  0
223    Input Text  ${xpath_manual_date}  ${date}
224    Input Text  ${xpath_manual_time}  ${time}
225    Click Element  ${xpath_select_save_settings}
226
227    # Refresh the NTP Page.
228    Click Element  ${xpath_refresh_button}
229    Wait Until Page Contains  ${date}  timeout=60s
230    Page Should Contain  ${time}
231
232    # Wait for the "Saved Successfully" window to close automatically.
233    Sleep  15
234
235
236Verify Moving From Manual To NTP
237    [Documentation]  Verify switching between manual mode and NTP mode.
238    [Tags]  Verify_Moving_From_Manual_To_NTP
239    [Setup]  Setup To Power Off And Navigate
240    [Template]  Switch From Manual To NTP
241
242    # loop_count
243    ${LOOP_COUNT}
244
245
246*** Keywords ***
247
248Suite Setup Execution
249   [Documentation]  Do test case setup tasks.
250
251    Launch Browser And Login GUI
252    Maximize Browser Window
253
254Suite Teardown Execution
255   [Documentation]  Do the post suite teardown.
256
257    Logout GUI
258    Close Browser
259
260Setup To Power Off And Navigate
261   [Documentation]  Power off system if not powered off and go to date and
262   ...  time page.
263
264   Redfish Power off  stack_mode=skip
265   Navigate To Date and Time Page
266
267Navigate To Date and Time Page
268    [Documentation]  Navigate to the date and time page from main menu.
269
270    Click Element  ${xpath_settings_menu}
271    Click Element  ${xpath_date_time_sub_menu}
272    Wait Until Keyword Succeeds  30 sec  10 sec  Location Should Contain  date-time
273    Wait Until Element Is Not Visible   ${xpath_page_loading_progress_bar}  timeout=30
274
275Set Manual Date and Time Via GUI
276    [Documentation]  Set BMC date and time to one month in future via GUI.
277
278    ${cli_date_time}=  CLI Get BMC DateTime
279    ${new_date}=  Add Time To Date  ${cli_date_time}  31 days
280    ${new_date_time}=  Add Time To Date  ${new_date}  05:10:00
281    Log  "Setting BMC date : ${new_date_time} using Manual option"
282    ${date}=  Convert Date  ${new_date_time}  result_format=%Y-%m-%d
283    ${time}=  Convert Date  ${new_date_time}  result_format=%H:%M
284    Click Element At Coordinates  ${xpath_select_manual}  0  0
285    Input Text  ${xpath_manual_date}  ${date}
286    Input Text  ${xpath_manual_time}  ${time}
287    Click Element  ${xpath_select_save_settings}
288
289    # Wait for changes to take effect.
290    Wait Until Element Is Enabled  ${xpath_select_ntp}  timeout=30s
291
292Switch From Manual To NTP
293    [Documentation]  Verify switching from manual mode to NTP mode.
294    [Arguments]  ${loop_count}=${LOOP_COUNT}
295
296    # Description of argument(s):
297    # loop_count        Number of loops to move from manual to NTP.
298
299    FOR  ${x}  IN RANGE  ${loop_count}
300       Set Manual Date and Time Via GUI
301       # Set BMC date time to sync with NTP server.
302       Click Element At Coordinates  ${xpath_select_ntp}  0  0
303       Input Text  ${xpath_ntp_server1}  216.239.35.0
304       Click Element  ${xpath_select_save_settings}
305
306       # Wait until saved successfully message is visible.
307       Wait Until Element Is Visible  ${xpath_success_message}  timeout=60
308
309       ${cli_date_time}=  CLI Get BMC DateTime
310       ${ntp_date}=  Convert Date  ${cli_date_time}  result_format=%Y-%m-%d
311       ${ntp_time}=  Convert Date  ${cli_date_time}  result_format=%H:%M
312       Wait Until Page Contains  ${ntp_date}   timeout=60s
313       Page Should Contain  ${ntp_time}
314
315       Wait Until Element Is Not Visible   ${xpath_success_message}  timeout=60
316       Log  "Completed Loop for ${x} time"
317    END
318