Page Should Contain | Please fill in this field
was a good suggestion.
I have had success with that keyword before when a text to verify with Robot Framework has been found in HTML-code when inspecting page.
Tried that keyword with this test also but no success.
I think that the problem is because that text "Please fill in this field." cannot be found anywhere when inspecting the page and that is probably why this keyword cannot find the text. I have found when googling that others have also tried to find that same text when inspecting but it can not be found and that is why it is so tricky.
With this same form that I am testing actually when both username and password are provided as invalid credentials then this line below can be found when inspected:
<p ng-show="$ctrl.loginError" class="text-red ng-binding" aria-hidden="false" style="">Unable to log in with provided credentials.</p>
So that "Unable to login in with provided credentials" is a different looking text and can be found from HTML-code. That particular text appearing after invalid login attempt (both invalid username and password provided) works technically differently and I got xpath to that text working with a different test case testing unsuccesfull login with both username and password.
Robot Framework-code to handle that verification is this:
${text} Get Text xpath://p[@class="text-red ng-binding"]
Should Be Equal as Strings ${text} Unable to log in with provided credentials.
That text "Unable to log in with provided credentials". also stays there after invalid login attempt has been made. But "Please fill in this field." appearing for a couple of seconds when only password is provided to login form can not be found anywhere and is impossible to point to using xpath. Also seems that Page Should Contain
can not verify that text.
Piece of HTML-code related to tested login-form (site is constructed by developers using Angular):
<form name="passwordConfirm" class="login-form ng-pristine ng-valid ng-hide" ng-show="$ctrl.passwordConfirm" aria-hidden="true">
<form class="login-form ng-invalid ng-invalid-required ng-invalid-recaptcha ng-dirty ng-valid-parse" ng-show="$ctrl.passwordLogin" aria-hidden="false" style="">
<p ng-show="$ctrl.loginError" class="text-red ng-binding ng-hide" aria-hidden="true"></p>
<h5 class="input-header">Username</h5>
<input ng-model="login_username" required="true" class="ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched" aria-invalid="true" style="">
<h5 class="input-header">Password</h5>
<input ng-model="login_password" type="password" required="true" class="ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" aria-invalid="false" style="">
Robot Framework-code, a keyword named EmptyUsername which handles testing that form:
EmptyUsername
[Documentation] Test what happens when username-field is empty but password is given and Sign in-button is pressed.
Comment Verify that login-form is found
Wait Until Page Contains Element xpath://div[@class="login-form"]
Wait Until Keyword Succeeds 2 1 Clear Element Text xpath://input[@ng-model="login_username"]
Comment Input password as next step below
Wait Until Keyword Succeeds 2 1 Input Text xpath://input[@ng-model="login_password"] abcd123
Comment Sign in-button is clicked as next step below
Wait Until Keyword Succeeds 2 1 Click Element xpath://button[@id="button-login"]
Page Should Contain Please fill in this field.
I found some other topics about constraint validation and verification here on stackoverflow. It seems that there is probably some solution but how to to write that with Robot is a bit tricky I think.
How to handle html5 constraint validation pop-up using Selenium?
How to validate html5 constraint validation message using Selenium-Webdriver and Java
How can I extract the text of HTML5 Constraint validation in https://www.phptravels.net/ website using Selenium and Java?
How to verify text in message generated by Constraint Validation API in HTML5?
I think closest one to use (probably successfully) with Robot Framework would be that last link above and there is that part
"Note that it is also possible to use getAttribute to get the validationMessage even though it is a property:"
String message = driver.findElement(By.name("email")).getAttribute("validationMessage");
It's just that how the JavaScript-syntax would go with Robot if that same idea could be used with Robot. I know that JavaScript can be used with Robot but syntax is not easy for me.
Page Should Contain | Please fill in this field
, Im not sure if that would be enough for your validation, Also could you provide a snippet of your robot and html – AutoTester213