Skip to content

Commit f403ed5

Browse files
committed
Implement basic validation errors in behave
1 parent 6cb7c22 commit f403ed5

File tree

4 files changed

+125
-3
lines changed

4 files changed

+125
-3
lines changed

tests/features/cannot_change_answers_after_submission.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Feature: Participants with submitted responses
44
When I go to "/start"
55
And I submit my participant id
66
Then I am on "/start"
7-
And I should see an error summary "Responses have already been submitted for this participant"
7+
And I see an error summary "Responses have already been submitted for this participant"

tests/features/steps/error_steps.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
from playwright.sync_api import expect
33

44

5-
@then(u'I should see an error summary "{error_summary}"')
6-
def then_I_should_see_an_error_summary(context, error_summary):
5+
@then(u'I see an error summary "{error_summary}"')
6+
def then_I_see_an_error_summary(context, error_summary):
77
expect(context.page.locator('.nhsuk-error-summary')).to_contain_text(error_summary)
8+
9+
@then(u'I see a form error "{error_message}"')
10+
def then_I_see_a_form_error(context, error_message):
11+
expect(context.page.locator('.nhsuk-error-message')).to_contain_text(error_message)

tests/features/steps/form_steps.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,32 @@ def when_I_fill_in_and_submit_my_date_of_birth(context, date_of_birth):
1818
context.page.get_by_label('Month').fill(month)
1919
context.page.get_by_label('Year').fill(year)
2020
context.page.click("text=Continue")
21+
22+
@when(u'I fill in and submit my height with "{height}"')
23+
def when_I_fill_in_and_submit_my_height(context, height):
24+
context.page.get_by_label('Centimetre').fill(height)
25+
context.page.click("text=Continue")
26+
27+
@when(u'I fill in and submit my height with "{feet}" feet and "{inches}" inch')
28+
@when(u'I fill in and submit my height with "{feet}" feet and "{inches}" inches')
29+
def when_I_fill_in_and_submit_my_height_with_feet_and_inches(context, feet, inches):
30+
context.page.get_by_label('Feet').fill(feet)
31+
context.page.get_by_label('Inches').fill(inches)
32+
context.page.click("text=Continue")
33+
34+
@when(u'I fill in and submit my weight with "{weight}"')
35+
def when_I_fill_in_and_submit_my_weight(context, weight):
36+
context.page.get_by_label('Kilograms').fill(weight)
37+
context.page.click("text=Continue")
38+
39+
@when(u'I fill in and submit my weight with "{stone}" stone and "{pounds}" pound')
40+
@when(u'I fill in and submit my weight with "{stone}" stone and "{pounds}" pounds')
41+
def stone_and_pounds(context, stone, pounds):
42+
context.page.get_by_label('Stone').fill(stone)
43+
context.page.get_by_label('Pounds').fill(pounds)
44+
context.page.click("text=Continue")
45+
46+
47+
@when('I submit the form')
48+
def when_I_submit_the_form(context):
49+
context.page.click("text=Continue")
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Feature: Validation errors
2+
Scenario: Date of birth form errors
3+
Given I have started the questionnaire
4+
When I go to "/date-of-birth"
5+
And I submit the form
6+
Then I am on "/date-of-birth"
7+
And I see a form error "Enter your date of birth."
8+
9+
Scenario: Height form errors
10+
Given I have started the questionnaire
11+
When I go to "/height"
12+
And I submit the form
13+
Then I am on "/height"
14+
And I see a form error "Enter your height."
15+
When I fill in and submit my height with "139.6"
16+
Then I am on "/height"
17+
And I see a form error "Height must be between 139.7cm and 243.8 cm"
18+
When I fill in and submit my height with "243.9"
19+
Then I am on "/height"
20+
And I see a form error "Height must be between 139.7cm and 243.8 cm"
21+
22+
Scenario: Height imperial form errors
23+
Given I have started the questionnaire
24+
When I go to "/height?unit=imperial"
25+
And I submit the form
26+
Then I am on "/height?unit=imperial"
27+
And I see a form error "Enter your height."
28+
When I fill in and submit my height with "5.2" feet and "2" inches
29+
Then I am on "/height?unit=imperial"
30+
And I see a form error "Feet must be in whole numbers"
31+
When I fill in and submit my height with "5" feet and "2.2" inches
32+
Then I am on "/height?unit=imperial"
33+
And I see a form error "Inches must be in whole numbers"
34+
When I fill in and submit my height with "8" feet and "1" inch
35+
Then I am on "/height?unit=imperial"
36+
And I see a form error "Height must be between 4 feet 7 inches and 8 feet"
37+
38+
Scenario: Weight form errors
39+
Given I have started the questionnaire
40+
When I go to "/weight"
41+
And I submit the form
42+
Then I am on "/weight"
43+
And I see a form error "Enter your weight."
44+
When I fill in and submit my weight with "25.3"
45+
Then I am on "/weight"
46+
And I see a form error "Weight must be between 25.4kg and 317.5kg"
47+
When I fill in and submit my weight with "317.6"
48+
Then I am on "/weight"
49+
And I see a form error "Weight must be between 25.4kg and 317.5kg"
50+
51+
Scenario: Weight imperial form errors
52+
Given I have started the questionnaire
53+
When I go to "/weight?unit=imperial"
54+
And I submit the form
55+
Then I am on "/weight?unit=imperial"
56+
And I see a form error "Enter your weight."
57+
When I fill in and submit my weight with "5.2" stone and "2" pounds
58+
Then I am on "/weight?unit=imperial"
59+
And I see a form error "Stone must be in whole numbers"
60+
When I fill in and submit my weight with "5" stone and "2.2" pounds
61+
Then I am on "/weight?unit=imperial"
62+
And I see a form error "Pounds must be in whole numbers"
63+
When I fill in and submit my weight with "3" stone and "12" pounds
64+
Then I am on "/weight?unit=imperial"
65+
And I see a form error "Weight must be between 4 stone and 50 stone"
66+
When I fill in and submit my weight with "50" stone and "1" pound
67+
Then I am on "/weight?unit=imperial"
68+
And I see a form error "Weight must be between 4 stone and 50 stone"
69+
70+
Scenario: Sex at birth form errors
71+
Given I have started the questionnaire
72+
When I go to "/sex-at-birth"
73+
And I submit the form
74+
Then I am on "/sex-at-birth"
75+
And I see a form error "Select your sex at birth."
76+
77+
Scenario: Gender form errors
78+
Given I have started the questionnaire
79+
When I go to "/gender"
80+
And I submit the form
81+
Then I am on "/gender"
82+
And I see a form error "Select the option that best describes your gender."
83+
84+
Scenario: Ethnicity form errors
85+
Given I have started the questionnaire
86+
When I go to "/ethnicity"
87+
And I submit the form
88+
Then I am on "/ethnicity"
89+
And I see a form error "Select your ethnic background."

0 commit comments

Comments
 (0)