Skip to content

Commit 6a54fe6

Browse files
committed
Migrate not a smoker exit tests to behave
Also use imperative I statements for behave features
1 parent 37feceb commit 6a54fe6

11 files changed

+45
-38
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ lung_cancer_screening/assets/compiled/*
1919
.DS_Store
2020
.venv
2121
.devcontainer/ca.crt
22+
tests/TEST-*.xml

behave.ini

Lines changed: 0 additions & 5 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,4 @@ requires = ["poetry-core>=2.0.0,<3.0.0"]
2929
build-backend = "poetry.core.masonry.api"
3030

3131
[tool.behave]
32-
junit = true
33-
junit_directory = "tests"
34-
paths = ["tests"]
32+
paths = ["tests/features"]
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
Feature: Participants with submitted responses
22
Scenario: Cannot change responses once submitted
3-
Given a participant abc123 exists
4-
And the participant abc123 has submitted their responses
5-
And the participant is on the "/start" path
6-
When the participant abc123 submits their participant id
7-
Then the participant should be on the "/start" path
8-
And the participant should see en error summary "Responses have already been submitted for this participant"
3+
Given I have already submitted my responses
4+
When I go to "/start"
5+
And I submit my participant id
6+
Then I am on "/start"
7+
And I should see an error summary "Responses have already been submitted for this participant"

tests/features/environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def after_all(context):
4949
LiveServer.tearDownClass()
5050

5151

52-
def before_scenario(_context, _scenario):
52+
def before_scenario(context, _scenario):
5353
"""Set up before each scenario."""
5454
# behave-django automatically handles database transactions per scenario
55-
pass
55+
context.page = context.browser.new_page()
5656

5757

5858
def after_scenario(context, _scenario):
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: Non smokers
22
Scenario: Non smokers are not elligible
3-
Given a participant abc123 exists
4-
And the participant is on the "/have-you-ever-smoked" path
5-
When the participant fills in and submits their smoking status with "No, I have never smoked"
6-
Then the participant should be on the "/non-smoker-exit" path
7-
And the participant should see a title "You do not need an NHS lung health check"
3+
Given I have started the questionnaire
4+
When I go to "/have-you-ever-smoked"
5+
And I fill in and submit my smoking status with "No, I have never smoked"
6+
Then I am on "/non-smoker-exit"
7+
And I see a title "You do not need an NHS lung health check"

tests/features/steps/error_steps.py

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

44

5-
@then(u'the participant should see en error summary "{error_summary}"')
6-
def then_the_participant_should_see_an_error_summary(context, error_summary):
7-
expect(context.page.locator('#maincontent')).to_contain_text(error_summary)
5+
@then(u'I should see an error summary "{error_summary}"')
6+
def then_I_should_see_an_error_summary(context, error_summary):
7+
expect(context.page.locator('.nhsuk-error-summary')).to_contain_text(error_summary)

tests/features/steps/form_steps.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from behave import when
22

33

4-
@when('the participant {participant_id} submits their participant id')
5-
def when_the_participant_submits_their_participant_id(context, participant_id):
6-
context.page.fill('input[name="participant_id"]', participant_id)
4+
@when('I submit my participant id')
5+
def when_I_submit_my_participant_id(context):
6+
context.page.fill('input[name="participant_id"]', context.participant_id)
77
context.page.click('button[type="submit"]')
88

9-
@when('the participant fills in and submits their smoking status with "{smoking_status}"')
10-
def when_the_participant_fills_in_and_submits_their_smoking_status(context, smoking_status):
9+
@when('I fill in and submit my smoking status with "{smoking_status}"')
10+
def when_I_fill_in_and_submit_my_smoking_status(context, smoking_status):
1111
context.page.get_by_label(smoking_status).check()
1212
context.page.click("text=Continue")
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
from behave import given, then
1+
from behave import when, then
22
from playwright.sync_api import expect
33

44

5-
@given('the participant is on the "{path}" path')
6-
def given_the_participant_is_on_the_path(context, path):
7-
context.page = context.browser.new_page()
5+
@when('I go to "{path}"')
6+
def given_I_go_to(context, path):
87
context.page.goto(f"{context.live_server_url}{path}")
98

10-
@then('the participant should be on the "{path}" path')
11-
def then_the_participant_should_be_on_the_path(context, path):
9+
@then('I am on "{path}"')
10+
def then_I_am_on(context, path):
1211
expect(context.page).to_have_url(f"{context.live_server_url}{path}")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from behave import given, then
2+
from playwright.sync_api import expect
3+
4+
5+
@then(u'I see a title "{title}"')
6+
def then_I_see_a_title(context, title):
7+
expect(context.page.locator('.title')).to_have_text(title)

0 commit comments

Comments
 (0)