Goal
Create new scenarios to cover error conditions, save and exit and submitting the form. In this lesson we are going to discover
- How to test error conditions and validate error messages
- Use Invalid config
- Validate Save and Exit
- Submit the form
Starting code
Start tag: lesson/05 (Configurators can use lesson/04)
Steps
Now we are in lesson 3 the forms are richer in functionality and we are starting to discover some extra buttons that were not there before.
Scenario description
We are going to create 2 scenarios for this lesson in 2 different files and a new folder H003
- Scenario: Login as External User, check error conditions when Submit and complete the required fields and validate no error messages displayed
- Scenario: Login as External User, complete a form and save and exit open the form again and submit
Error conditions and invalid config
Error conditions can appear at the field level as per the screenshot below or at the top of the screen as per the example at UX guidelines. For super heroes, we are going to concentrate on the field level error messages and validate that all those errors have the correct text associated with them

We are going to create a new folder H003 and a file called ErrorCondition.feature

Scenario: Login as External User, check error conditions when Submit and complete the required fields and validate no error messages displayed
Actions: We are going to concentrate on validating error messages without entering values in any field.
- I expect <field> to have error message <error message>
- I expect no error messages
- I expect no invalid config

Scenario: Login as External User, check error conditions when Submit and complete the required fields and validate no error messages displayed
Given I set application to heroes
Then I logon as External01@fostermoore.com with password External01
And I click menu Online Services
And I click menu Register a Super Hero
When I click button Submit
Then I expect no invalid config
And I expect Super Hero Name to have error message Super Hero Name must be entered
And I expect Do you usually or intend to don a cape? to have error message Do you usually or intend to don a cape? must be selected
And I expect Hero Powers to have error message Hero Powers must be selected
The test should look like the following screenshot

Now we will complete all the fields showing error message and then validate that no error messages are displayed on screen
Scenario: Login as External User, check error conditions when Submit and complete the required fields and validate no error messages displayed
Given I set application to heroes
Then I logon as External01@fostermoore.com with password External01
And I click menu Online Services
And I click menu Register a Super Hero
When I click button Submit
Then I expect no invalid config
And I expect Super Hero Name to have error message Super Hero Name must be entered
And I expect Do you usually or intend to don a cape? to have error message Do you usually or intend to don a cape? must be selected
And I expect Hero Powers to have error message Hero Powers must be selected
When I enter text Vertex in Super Hero Name
And I select radio button Yes in radio button group Do you usually or intend to don a cape?
And I select option Agility from dropdown Hero Powers
Then I expect no error messages

Save and Exit
Save and exit scenarios validate that the service Register a super hero can be saved to later complete the service. The reason for this scenario is just to make sure the data is correctly populated once we open the service again.
Scenario: Login as External User, complete a form and save and exit open the form again and submit
Actions: Save and Exit, open the form again
- And I click Continue for dashboard item <Entity>


Scenario: Login as External User, complete a form and save and exit open the form again and submit
Given I set application to heroes
Then I logon as External01@fostermoore.com with password External01
And I click menu Online Services
And I click menu Register a Super Hero
When I enter text SaveAndExitTest in Super Hero Name
And I select radio button Yes in radio button group Do you usually or intend to don a cape?
And I select option Agility from dropdown Hero Powers
When I click button Save and Exit
And I click button Go back
And I click button Save and Exit
And I click button Yes, exit now
And I expect no invalid config
And I click tab Things in Progress
And I click Continue for dashboard item SaveAndExitTest
And I expect no invalid config
When I click button Submit
Then I expect no invalid config
And I expect service-title Success
And I expect text Your super hero is now registered and ready to save the world!
And I expect text Super Hero Name > SaveAndExitTest
And I expect text Registration Date > #FORMATTED_TODAY#dd MMMM yyyy#FORMATTED_TODAY#
And I expect text Year of Arrival on Earth > not specified
And I expect text Do you have a uniform, costume or outfit? > Yes
And I expect text Do you usually or intend to don a cape? > Yes
And I expect text Hero Powers > Agility
Then I click button Back
And I expect text Welcome External01, what next?

If the actions are successful 2 things will happen a confirmation screen will show up and also a Back button. For these 2 items we created validations using expect text, also we are checking the Back button functionality is clickable and returns to the Dashboard.

Recap
In this lesson we discovered a few things:
- We tested error conditions and also validated the error conditions are not present on the screen after completing the required fields on the form.
- Validated invalid configuration via I do not expect invalid config.
- Saved and Exited and opened the transaction to confirm that we can submit the form again without issues.
- Submitted a form and validated the Success screen contains the information that we originally entered on the form.
- We can go back to the dashboard via the Back button.

