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