3
votes

I am working as a practical trainee doing Robot Framework UI-tests. With one test case the idea is to provide a password to site's login form but leave username-field as empty. Then when Sign In-button is clicked there comes text "Please fill in this field" regarding empty username-field and that text only shows for couple of seconds before disappearing. The idea would be to verify that text after Sign In is clicked.

I tried to find that "Please fill in this field"-text inspecting login form with Google Chrome and looking at web site's source code but could not find that text anywhere from HTML site structure or JavaScript-files. I talked with a developer and he said that this text is provided by Bootstrap's validating. I then found on google that this validating functionality is called constraint validation and required> part in code is what adds that functionality.

Unfortunately I can't put a direct link to the site that I am testing as the site is on a test server only accessible by some computers and not in production but that site is build with angular and for example username-part is ng-model="login_username" when inspecting.

So my question is that when I can not point to that "Please fill in this field" text by xpath is there any other way to verify that this text indeed exists by using Robot Framework? I guess that maybe with JavaScript added to Robot-code that could be done but an example would help a lot if someone has done a test like that before. I have not a lot of experience of Robot/JavaScript-combination yet as I have started to study Robot earlier this year.

In a link below in "Text Input"-image there is exactly the same popup shown that I am getting when providing only password and clicking Sign In. So if I understood correctly that is a standard validation provided by Bootstrap.

https://css-tricks.com/form-validation-part-1-constraint-validation-html/

2
An easy validation would be to look for the text e.g 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 htmlAutoTester213

2 Answers

0
votes

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.

0
votes

When you inspect the form, the source code for this text is not displayed. This is due to the bootsrap ... the way to check this text "Please fill in this field" with Robot framework is as follows: $ {text} = Get Element Attribute (you give the xpath) And (validationMessage) Should Not Be Empty $ {text} We check if $ {text} is empty. If this is the case, it means that the Login field has been filled in, otherwise $ {text} will surely contain "Please fill in this field".