Hi,
I am trying to automate the login test using test template, however, I realized that the application I am automating there is two steps that is little different between two verifications, and it is cause the test to fail does it mean in this case test template won’t be the best way to automate the login test?
*** Keywords ***
Invalid Login Scenarios
[Arguments] ${username} ${password} ${error_message}
Wait Until Element Is Visible ${LogIn_Sign_Up_Logo}
Click Element ${LogIn_Sign_Up_Logo}
Wait Until Element Is Visible ${Log in Your Account Text}
Element Text Should Be ${Log in Your Account Text} Log in to xxx
Input Text ${txtbox_username} ${username}
Click Button ${btn_continue}
Input Text ${txtbox_password} ${password} --- This step is only for the second verification and because of this, every time the first verification runs, it fails the test
Click Button ${btn_login_continue} --- This step is only for the second verification and because of this, every time the first verification runs, it fails the test
*** Test Cases *** USERNAME PASSWORD ERROR MESSAGE
Verify Login Fails - Invalid Username williamsthomas@ q*Q0OnSszL Email is not valid.
Verify Login Fails - Invalid Password williamsthomas@example.org abdce@fde Wrong email or password
you didn’t mention it, I’m guessing Invalid Login Scenarios is your test template? in this case it was reasonably easy to guess but it won’t always be, try to include as much relevant information as possible in your questions so people can help you.
Now for the issue:
If I understand correctly, with your first test case, Wait Until Element Is Visible ${Log in Your Account Text} fails because you didn’t get the next screen instead you got “Email is not valid.” and you want the test case to pass at this point and not continue.
Perhaps what you need is something like this:
*** Keywords ***
Invalid Login Scenarios
[Arguments] ${username} ${password} ${error_message}
Wait Until Element Is Visible ${LogIn_Sign_Up_Logo}
Click Element ${LogIn_Sign_Up_Logo}
${passed}= Run Keyword And Return Status Wait Until Element Is Visible ${error_message} ${optional_short_timeout}
# if ${error_message} is found, no need to do anything else in the test
IF not ${passed}
# if ${error_message} is not found, continue the test
Wait Until Element Is Visible ${Log in Your Account Text}
Element Text Should Be ${Log in Your Account Text} Log in to xxx
Input Text ${txtbox_username} ${username}
Click Button ${btn_continue}
Input Text ${txtbox_password} ${password} --- This step is only for the second verification and because of this, every time the first verification runs, it fails the test
Click Button ${btn_login_continue} --- This step is only for the second verification and because of this, every time the first verification runs, it fails the test
# you may also want to add this line to make the test fail if you don't get the expected message or worse an invalid login actually succeeds to log in
Wait Until Element Is Visible ${error_message}
END
You can remove ${optional_short_timeout} if you don’t want it, it will just mean that step will take the standard timeout time to complete, If I’m correct in assuming that this validation happens in the browser you can change ${optional_short_timeout} to a small number like 2 seconds and then your second test won’t take so long to complete.
I usually add another data column, flagging if it is a negative test, or even a keyword and arguments to execute.
This could become:
*** Keywords ***
Invalid Login Scenarios
[Arguments] ${username} ${password} ${error_message} ${kind}="password"
# (...)
Click Button ${btn_continue}
IF "${kind}" == "password"
Input Text ${txtbox_password} ${password} # --- This step is only for the second verification and because of this, every time the first verification runs, it fails the test
Click Button ${btn_login_continue} # --- This step is only for the second verification and because of this, every time the first verification runs, it fails the test
END
*** Test Cases *** USERNAME PASSWORD ERROR MESSAGE KIND
Verify Login Fails - Invalid Username williamsthomas@ q*Q0OnSszL Email is not valid username
Verify Login Fails - Invalid Password williamsthomas@example.org abdce@fde Wrong email or password
Hi Dave, sorry for the format when posting the question. I will keep in mind to mentioned more details.
Thank you so much for taking your time to look at this and post the solution. Appreciate your time and help
Hi Helio,
Thank you so much for taking your time to reply, this approach worked for me. Always learning a ton from you. Appreciate that you are here for the rescue Thank you, thank you!!