Addition of new User management Test Cases

Below mentioned testcases are automated in this checkin.
1. Verify Error When Duplicate User Is Created
2. Delete User And Verify
3. Verify Invalid Password Error

Resolves https://github.com/openbmc/openbmc-test-automation/issues/1613

Change-Id: I04aa57fe2ffcfed53c2a1a44fe533a29286b8c49
Signed-off-by: Anusha Dathatri <adathatr@in.ibm.com>
diff --git a/gui/test/users/test_obmc_gui_manage_user.robot b/gui/test/users/test_obmc_gui_manage_user.robot
index 92212c2..de361b5 100644
--- a/gui/test/users/test_obmc_gui_manage_user.robot
+++ b/gui/test/users/test_obmc_gui_manage_user.robot
@@ -15,16 +15,24 @@
 ${xpath_input_username}               //input[@name='UserName']
 ${xpath_input_password}               //input[@name='Password']
 ${xpath_input_retype_password}        //input[@name='VerifyPassword']
-${xpath_input_user_role}              //select[@id='user-manage__role']
-${xpath_input_enabled_checkbox}       //input[@name='Enabled']
+${xpath_input_user_role}              //select[@id='role']
+${xpath_input_enabled_checkbox}       //label[@for="user-manage__enabled"]
 ${xpath_input_lockout_time}           //input[@id='lockoutTime']
 ${xpath_input_failed_login_attempts}  //input[@id='lockoutThreshold']
 ${xpath_select_manage_users}          //a[contains(text(), "Manage user account")]
 ${xpath_select_users}                 //button[contains(@class, "users")]
 ${xpath_save_setting_button}          //button[text() ="Save settings"]
-${xpath_create_user_button}           //button[text() ="Create User"]
+${xpath_create_user_button}           //button[text() ="Create user"]
 ${xpath_edit_button}                  //button[text() ="Edit"]
 ${xpath_delete_button}                //button[text() ="Delete"]
+${label}                              //label[@class="control-check"]
+${xpath_edit_save_button}             //*[@id="user-accounts"]/form/section/div[7]/button[2]
+&{user_password}                      testUser1=testUserPwd1  root=0penBmc
+&{action_msg_relation}                add=User has been created successfully
+                  ...                 modify=User has been updated successfully
+                  ...                 add_dup=Username exists
+&{user_invalid_password}              root=rootPwd1
+
 
 
 *** Test Cases ***
@@ -68,14 +76,100 @@
     Page Should Contain Element  ${xpath_edit_button}
     Page Should Contain Element  ${xpath_delete_button}
 
+Verify Error When Duplicate User Is Created
+    [Documentation]  Verify error when duplicate user is created.
+    [Tags]  Verify_Error_When_Duplicate_User_Is_Created
+    [Setup]  Delete Given Users
+
+    Add Or Modify User  root  &{user_password}[root]  action=add_dup
+
+Delete User And Verify
+    [Documentation]  Delete user and verify.
+    [Tags]  Delete_User_And_Verify
+    [Setup]  Delete Given Users
+
+    Add Or Modify User  testUser1  &{user_password}[testUser1]
+    Delete Given Users  delete_user=testUser1
+    Page Should Not Contain  testUser1
+
+Verify Invalid Password Error
+    [Documentation]  Verify the error message when user logs in with invalid password.
+    [Tags]  Verify_Invalid_Password_Error
+    [Setup]  Delete Given Users
+    [Teardown]  Login OpenBMC GUI
+
+    LogOut OpenBMC GUI
+    Login And Verify Message  root  &{user_invalid_password}[root]  Invalid username or password
 
 *** Keywords ***
 
 Test Setup Execution
    [Documentation]  Do test case setup tasks.
 
-    Click Element  ${xpath_select_users}
+    Click Button  ${xpath_select_users}
+    Sleep  2s
     Wait Until Page Contains Element  ${xpath_select_manage_users}
     Click Element  ${xpath_select_manage_users}
     Wait Until Page Contains  User account information
 
+Add Or Modify User
+   [Documentation]  Creates or edits user.
+   [Arguments]  ${username}  ${password}  ${role}=Administrator  ${enabled}=${True}
+   ...          ${action}=add
+   # Description of argument(s):
+   # username  Name of the user to be created.
+   # role      Role of the new user.
+   # enabled   If True, User is enabled (Default), False, User is disabled.
+   # action    add - Creates a new user.
+   #           modify - Edits an existing user.
+   #           add_dup - Tries to add a duplicate user and verifies the error message.
+
+   Run Keyword If  '${action}' == 'add' or '${action}' == 'add_dup'
+              ...  Input Text  ${xpath_input_username}  ${username}
+   Input Password  ${xpath_input_password}  ${password}
+   Input Password  ${xpath_input_retype_password}  ${password}
+   Log  ${role}
+   Select From List By Value  ${xpath_input_user_role}  ${role}
+   Run Keyword If  '${enabled}' == 'True'  Click Element  ${xpath_input_enabled_checkbox}
+   Run Keyword If  '${action}' == 'modify'
+   ...  Click Button  ${xpath_edit_save_button}
+   ...  ELSE  Click Button  ${xpath_create_user_button}
+   Capture Page Screenshot
+   Page Should Contain  &{action_msg_relation}[${action}]
+
+Delete Given Users
+   [Documentation]  Deletes users based on the input.
+   [Arguments]  ${delete_user}=nonRoot
+   # Description of argument(s):
+   # delete_user  values - nonRoot/username
+   #              If nonRoot - Deletes all non-root users,
+   #                 username - Deletes the given user.
+
+   Wait Until Page Contains  root
+   Run Keyword If  '${delete_user}' != 'nonRoot'  Page Should Contain  ${delete_user}
+   # Row id that gets deleted in every iteration.
+   ${deleting_row_id}=  Set Variable  1
+   :FOR  ${row}  IN RANGE  1  16
+   \    ${xpath_user}=  Set Variable  //*[@id="user-accounts"]/div[4]/div[2]/div[${deleting_row_id}]/div[1]
+   \    ${status}=  Run Keyword And Return Status  Page Should Contain Element  ${xpath_user}
+   \    Exit For Loop If  '${status}' == 'False'
+   \    ${user}=  Get Text  ${xpath_user}
+   \    ${deleting_row_id}  Run Keyword If  '${user}' == 'root' or '${deleting_row_id}' == '2'  Set Variable  2
+   \    ...  ELSE  Set Variable  1
+   \    Continue For Loop If  '${user}' == 'root'
+   \    ${xpath_delete_user}  Run Keyword If  '${user}' == '${delete_user}' or '${delete_user}' == 'nonRoot'
+   \    ...  Set Variable  //*[@id="user-accounts"]/div[4]/div[2]/div[${deleting_row_id}]/div[5]/button[2]
+   \    Run Keyword If  '${user}' == '${delete_user}' or '${delete_user}' == 'nonRoot'
+   \    ...  Run Keywords  Click Button  ${xpath_delete_user}
+   \    ...  AND  Page Should Contain  User has been deleted successfully
+   \    ...  AND  Reload Page
+   \    ...  AND  Exit For Loop If  '${user}' == '${delete_user}'
+
+Login And Verify Message
+   [Documentation]  Verifies the error message displayed on screen while logging in.
+   [Arguments]  ${username}  ${password}  ${msg}
+
+    Input Text  ${xpath_textbox_username}  ${username}
+    Input Password  ${xpath_textbox_password}  ${password}
+    Click Element  ${xpath_button_login}
+    Page Should Contain  ${msg}