Negative Validations

abstract Applications should correctly reject invalid data and show meaningful error messages. Negative Validations are test flows that input such invalid data and verify the error messages.
info Form fields that take user input can be restricted or free-form.
  • Restricted fields are radio buttons, checkboxes, select boxes etc. where only valid values can be chosen.
  • Free-form form fields are textboxes, textareas etc. Validations are normally needed on such fields because the user may input incorrect values.

    • First Name which should be between 1 and 32 characters: Should not accept 0 character or >32 character long strings
    • Email field: Should not accept invalid emails like abc@examplecom or
info Note that there are 3 aspects to a negative validation:
  1. The input value should be rejected
  2. An appropriate and meaningful error message should be shown
  3. The error message should appear at the right place
So, for automation we will need to know the following:
  1. The UI Element to input the value into
  2. The Input Value
  3. The Error Message
  4. The UI Error Element - placeholder where the error value is shown
goal Using Negative Validations feature, define and run a test flow with various invalid data and check that the application rejects them with the correct error message .

Discover Values for Negative Validations

The values we need to check for Negative Validations can be derived from various sources: In the User Registration case, let us see what validation messages are shown.
Navigate to the registration page manually and click on Submit without entering any value.

The following error messages are seen:
This suggests that we could check for blank name and names with more than 32 characters for First Name.

Add Negative Validations

  1. Navigate to Automate → Entities → Select Entity $user → Select Attribute firstname
  2. Choose Negative Validations tab
  3. Add values to check for under Input Value column. Let us check for an empty value. Leave the Input Value empty.
  4. Add the Error Message that should be visible on the UI.
    1. You can either copy paste this from the application UI or from documentation
    2. If you want to get it from the UI, you can Ctrl + Mouse Hover on the error message on the UI. The message will appear in the text box at the left bottom. You can copy paste from there.
    In this case, the error message is "First Name must be between 1 and 32 characters!"
  5. We can add a comment about the value for further clarity. Eg. "Should not be blank".
  6. Add one more row for a character string with >32 characters Thisislongstringwhichshouldnotwork, as shown in the image
  7. Click Save Entity to save

Set UI Element and UI Error Element

As mentioned above, we will also need to know the UI Element where the input will be made, and the UI Error Element where the error message will appear.
  1. Navigate to the UI Element sub-tab
  2. It should already be populated with UI Element for First Name Input
    If not already populated, go to the application and Ctrl + Mouse Hover on the First Name textbox.
    The UI Element textbox at the bottom will get populated. Drag the value onto the UI Element column.
  3. For UI Error Element, we will Ctrl + Mouse Hover over the error message. We notice that the identifiers are either using the error text itself or are using a generic css classname.
    Let us use the anchor button to get a better identifier.

    1. Navigate to the Opencart window, Ctrl + Mouse Hover on Label First Name. A red outline highlights the label and it appears in the UI Element box.
    2. Click on the Anchor button. The Anchor button gets an orange line at the bottom to show that it is on.
    3. Navigate to the Opencart window, Ctrl + Mouse Hover on the error message for the First Name.
      A red outline highlights the error message and it gets added to the UI Element box.
    4. Click on the drop-down arrow next to the UI Element box. It shows the various identifiers.
      Notice that the identifiers use _near(_label("First Name")) to show that we are identifying the error message box relative to the First Name label.
      Using _near, _in, _under etc. makes the identifiers more resilient to changes in the application UI.
    5. Select the option _div("text-danger", _near(_label("First Name")))
    6. Drag the UI Element box and drop to the UI Error Element.
    7. Click the Anchor button again to turn of relative identification.
We have set both the UI Element and UI Error Element

Using Suggestions

For some types of values, Flowcharts can suggest possible invalid values to check for.
For example, an email is of a standard format no matter what the application is.
So Flowcharts provides suggestions for such standard data types.

Let us add Negative validations for $
  1. Navigate to Automate → Entities → Select Entity $user → Select Attribute email
  2. Choose Negative Validations tab
  3. Click on Suggest button.
  4. Select datatype email
  5. A long of list of values are shown with comments. For now, select the first two suggestions.
  6. Click on Add button. These values get added to Negative Validations.
  7. Identify the error message from Opencart window with Ctrl + Mouse Hover method.
  8. Copy the identified error message and paste into the Error message column for both the rows.
  9. Make sure to also add UI Element:_emailbox("email") and UI Error Element:_div("text-danger", _near(_label("E-Mail"))) for email
  10. Click Save Entity to save

Run the Negative Validations

  1. Check for the path settings:
    Click on path tab and select the checkbox for Enable Validations.
  2. Click on the Run button.
  3. Run Settings dialog opens. Select the checkbox Run Negative validations only and deselect others.
  4. Click on Run button.

View Report for Negative Validations

Follow the steps to check the Report after running/executing the Negative validations :
  1. Click on the Reports button.
  2. The Report window will open in a new tab.
  3. Click on Registration P0 NEGATIVE VALIDATION.
  4. Suit Report tab opens. Click on Registration P0 NEGATIVE VALIDATION.
  5. It opens the Script Report tab. Click on Expand All to view details of each attribute, or click on each validation to see its details.
    1. Report for the case where firstname is blank
    2. Report for the case where firstname is more than 32 characters long
    3. Report for the case where email address is not correct
outcome Congratulations! You have successfully run a few Negative Validations!