Skip to content

Commit addef58

Browse files
authored
Update: [AEA-4809] - Re-enable logout tests, and some other minor things (#215)
## Summary **Remove items from this list if they are not relevant. Remove this line once this has been done** - Routine Change ### Details Uncomments the logout tests, and makes them compatible with the select your role tests. Also makes localhost testing available.
1 parent f8e2010 commit addef58

File tree

9 files changed

+129
-97
lines changed

9 files changed

+129
-97
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"context": "..",
99
"args": {}
1010
},
11+
"runArgs": [
12+
"--network=host"
13+
],
1114
"mounts": [
1215
"source=${env:HOME}${env:USERPROFILE}/.ssh,target=/home/vscode/.ssh,type=bind",
1316
"source=${env:HOME}${env:USERPROFILE}/.gnupg,target=/home/vscode/.gnupg,type=bind"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ For example:
7777
product=cpts-ui env=internal-dev PULL_REQUEST_ID=pr-300 tags=cpt-ui HEADLESS=true make run-tests
7878
```
7979

80+
Note that CPT-UI supports localhost testing. To do this, use the `env=localhost` variable. Make sure your localhost server is running!
81+
8082
### Method 4 (Not Recommended):
8183
Run the tests by running `behave` in a command prompt or terminal window.
8284
* This will run the tests and print the results to console

features/cpts_ui/logout.feature

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,39 @@ Feature: The user is able to logout of the application
99
############################################################################
1010
# Logging out
1111
############################################################################
12-
# Scenario: Display logout modal when user clicks logout
13-
# When I click the logout button
14-
# Then I see the logout confirmation modal
12+
Scenario: Display logout modal when user clicks logout
13+
When I click the logout button
14+
Then I see the logout confirmation modal
1515

16-
# Scenario: User confirms logout
17-
# Given the logout confirmation modal is displayed
18-
# When I confirm the logout
19-
# Then I see the logout successful page
16+
Scenario: User confirms logout
17+
Given the logout confirmation modal is displayed
18+
When I confirm the logout
19+
Then I see the logout successful page
2020

21-
# Scenario: User can log back in from the logout successful page
22-
# Given I am on the logout successful page
23-
# When I click the "log back in" button
24-
# Then I am on the login page
21+
Scenario: User can log back in from the logout successful page
22+
Given I am on the logout successful page
23+
When I click the "log back in" button
24+
Then I am on the login page
2525

2626
############################################################################
2727
# Closing the logout modal
2828
############################################################################
29-
# Scenario: Close the modal with the cross icon
30-
# Given the logout confirmation modal is displayed
31-
# When I close the modal with the cross
32-
# Then the logout confirmation modal is not displayed
33-
34-
# Scenario: Close the modal with the cancel button
35-
# Given the logout confirmation modal is displayed
36-
# When I close the modal with the cancel button
37-
# Then the logout confirmation modal is not displayed
38-
39-
# Scenario: Close the modal by clicking outside the modal
40-
# Given the logout confirmation modal is displayed
41-
# When I close the modal by clicking outside the modal
42-
# Then the logout confirmation modal is not displayed
43-
44-
# Scenario: Close the modal by pressing the escape key
45-
# Given the logout confirmation modal is displayed
46-
# When I close the modal by hitting escape
47-
# Then the logout confirmation modal is not displayed
29+
Scenario: Close the modal with the cross icon
30+
Given the logout confirmation modal is displayed
31+
When I close the modal with the cross
32+
Then the logout confirmation modal is not displayed
33+
34+
Scenario: Close the modal with the cancel button
35+
Given the logout confirmation modal is displayed
36+
When I close the modal with the cancel button
37+
Then the logout confirmation modal is not displayed
38+
39+
Scenario: Close the modal by clicking outside the modal
40+
Given the logout confirmation modal is displayed
41+
When I close the modal by clicking outside the modal
42+
Then the logout confirmation modal is not displayed
43+
44+
Scenario: Close the modal by pressing the escape key
45+
Given the logout confirmation modal is displayed
46+
When I close the modal by hitting escape
47+
Then the logout confirmation modal is not displayed

features/cpts_ui/select_your_role.feature

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ Feature: Role selection page renders roles properly when logged in
55
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4653
66
Scenario: User can navigate to the select your role page
77
Given I am logged in
8-
Then I am on the select your role page
8+
And I am on the select your role page
99

1010
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4656
1111
Scenario: User is redirected to the select your role page
1212
Given I am logged in
13-
Then I am on the select your role page
13+
And I am on the select your role page
1414

1515
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4653
1616
Scenario: User can see the summary container, but not the table contents by default
1717
Given I am logged in
18-
Then I am on the select your role page
18+
And I am on the select your role page
1919
Then I can see the summary container
2020
And I cannot see the summary table body
2121

2222
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4653
2323
Scenario: User can expand the summary table to see the contents. Clicking again hides it
2424
Given I am logged in
25-
Then I am on the select your role page
25+
And I am on the select your role page
2626
When I click on the summary expander
2727
Then I can see the summary table body
2828
And I can see the table body has a header row
@@ -34,40 +34,40 @@ Feature: Role selection page renders roles properly when logged in
3434
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4651
3535
Scenario: User can see roles with access cards
3636
Given I am logged in
37-
Then I am on the select your role page
37+
And I am on the select your role page
3838
Then I can see the roles with access cards
3939

4040
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4651
4141
Scenario: User can navigate to the your selected role page
4242
Given I am logged in
43-
Then I am on the select your role page
43+
And I am on the select your role page
4444
Then I can navigate to the your selected role page by clicking a card
4545

4646
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4655
4747
Scenario: User without access can see the header on the select your role page
4848
Given I am logged in without access
49-
Then I am on the select your role page
49+
And I am on the select your role page
5050
Then I cannot see the your selected role subheader
5151
And I can see the no access header
5252

5353
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4655
5454
Scenario: User without access can see the message on the select your role page
5555
Given I am logged in without access
56-
Then I am on the select your role page
56+
And I am on the select your role page
5757
Then I cannot see the your selected role subheader
5858
And I can see the no access message
5959

6060
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4655
6161
Scenario: User without access can see the summary container, but not the table contents by default
6262
Given I am logged in without access
63-
Then I am on the select your role page
63+
And I am on the select your role page
6464
Then I can see the summary container
6565
And I cannot see the summary table body
6666

6767
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4655
6868
Scenario: User without access can expand the summary table to see the contents. Clicking again hides it
6969
Given I am logged in without access
70-
Then I am on the select your role page
70+
And I am on the select your role page
7171
When I click on the summary expander
7272
Then I can see the summary table body
7373
And I can see the table body has a header row

features/environment.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
SANDBOX_INT_BASE_URL = "https://sandbox.api.service.nhs.uk/"
1818
REF_BASE_URL = "https://ref.api.service.nhs.uk/"
1919

20+
LOCALHOST_URL = "http://localhost:3000/"
21+
2022
AWS_BASE_URL = ".eps.national.nhs.uk/"
2123
PFP_AWS_PR_URL = "https://pfp-{{aws_pull_request_id}}.dev.eps.national.nhs.uk/"
2224
PFP_AWS_SANDBOX_PR_URL = (
@@ -34,6 +36,7 @@
3436
"REF": REF_BASE_URL,
3537
"INTERNAL-DEV-SANDBOX": SANDBOX_DEV_BASE_URL,
3638
"SANDBOX": SANDBOX_INT_BASE_URL,
39+
"LOCALHOST": LOCALHOST_URL,
3740
}
3841

3942
AWS_ENVS = {
@@ -109,9 +112,17 @@ def before_all(context):
109112
product = context.config.userdata["product"].upper()
110113
if count_of_scenarios_to_run(context) != 0:
111114
env = context.config.userdata["env"].upper()
112-
context.cpts_ui_base_url = f"https://{CPTS_UI_PREFIX}" + select_aws_base_url(
113-
env
114-
)
115+
print(f"Environment: {env}")
116+
117+
# Currently, only the CPT-UI product is supported for local testing
118+
if env == "LOCALHOST":
119+
context.cpts_ui_base_url = LOCALHOST_URL
120+
121+
else:
122+
context.cpts_ui_base_url = (
123+
f"https://{CPTS_UI_PREFIX}" + select_aws_base_url(env)
124+
)
125+
115126
context.eps_fhir_base_url = os.path.join(
116127
select_apigee_base_url(env), EPS_FHIR_SUFFIX
117128
)
@@ -123,11 +134,13 @@ def before_all(context):
123134
)
124135
context.pfp_base_url = os.path.join(select_apigee_base_url(env), PFP_SUFFIX)
125136
context.psu_base_url = os.path.join(select_apigee_base_url(env), PSU_SUFFIX)
137+
126138
if PULL_REQUEST_ID:
127139
print(f"--- Using pull request id: '{PULL_REQUEST_ID}'")
128140
pull_request_id = PULL_REQUEST_ID.lower()
129141
if "pr-" in pull_request_id:
130142
get_url_with_pr(context, env, product)
143+
131144
else:
132145
raise RuntimeError("no tests to run. Check your tags and try again")
133146
if product == "CPTS-UI":
Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,87 @@
11
# pylint: disable=no-name-in-module
2+
import re
23
from behave import given, then # pyright: ignore [reportAttributeAccessIssue]
34

45
from features.environment import (
56
MOCK_CIS2_LOGIN_ID_MULTIPLE_ACCESS_ROLES,
67
MOCK_CIS2_LOGIN_ID_NO_ACCESS_ROLE,
8+
MOCK_CIS2_LOGIN_ID_SINGLE_ACCESS_ROLE,
79
)
810

11+
select_your_role_url_pattern = re.compile(r".*/selectyourrole(?:/|\.html)$")
912

10-
@then("I am logged out")
11-
def i_am_logged_out(context):
12-
# No cookies with names starting with "CognitoIdentityServiceProvider" should be present
13-
cookies = context.page.context.cookies()
14-
cognito_cookies = [
15-
cookie
16-
for cookie in cookies
17-
if cookie["name"].startswith("CognitoIdentityServiceProvider")
18-
]
19-
assert len(cognito_cookies) == 0
13+
###############################################################################
14+
# GIVEN
15+
###############################################################################
2016

2117

22-
# @given("I am logged in") #AEA-4809
23-
# def login(context):
24-
# # TODO: This /site/ is not generic. Also, the .html will need to be removed when the SPA is fixed
25-
# context.page.goto(context.cpts_ui_base_url + "site/auth_demo.html")
26-
# context.page.get_by_role("button", name="Log in with mock CIS2").click()
27-
# context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_MULTIPLE_ACCESS_ROLES)
28-
# context.page.get_by_role("button", name="Sign In").click()
29-
# context.page.wait_for_url("**/selectyourrole.html")
18+
@given("I am on the home page")
19+
def i_am_on_home_page(context):
20+
context.page.goto(context.cpts_ui_base_url + "site/")
3021

31-
# # There should be cookies with names starting with "CognitoIdentityServiceProvider"
32-
# cookies = context.page.context.cookies()
33-
# cognito_cookies = [
34-
# cookie
35-
# for cookie in cookies
36-
# if cookie["name"].startswith("CognitoIdentityServiceProvider")
37-
# ]
38-
# assert len(cognito_cookies) > 0
22+
23+
@given("I am on the login page")
24+
def i_am_on_login_page(context):
25+
context.execute_steps("given I am on the home page")
26+
context.page.get_by_test_id("eps_header_placeholder2").click()
3927

4028

4129
@given("I am logged in")
4230
def login(context):
43-
context.page.goto(context.cpts_ui_base_url + "site/auth_demo.html")
31+
context.execute_steps("given I am on the login page")
32+
4433
context.page.get_by_role("button", name="Log in with mock CIS2").click()
4534
context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_MULTIPLE_ACCESS_ROLES)
4635
context.page.get_by_role("button", name="Sign In").click()
47-
context.page.wait_for_url("**/selectyourrole.html")
36+
context.page.wait_for_url(select_your_role_url_pattern)
37+
38+
# There should be cookies with names starting with "CognitoIdentityServiceProvider"
39+
cookies = context.page.context.cookies()
40+
cognito_cookies = [
41+
cookie
42+
for cookie in cookies
43+
if cookie["name"].startswith("CognitoIdentityServiceProvider")
44+
]
45+
assert len(cognito_cookies) > 0
4846

4947

5048
@given("I am logged in without access")
5149
def login_without_access(context):
52-
context.page.goto(context.cpts_ui_base_url + "site/auth_demo.html")
50+
context.execute_steps("given I am on the login page")
51+
5352
context.page.get_by_role("button", name="Log in with mock CIS2").click()
5453
context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_NO_ACCESS_ROLE)
5554
context.page.get_by_role("button", name="Sign In").click()
56-
context.page.wait_for_url("**/selectyourrole.html")
55+
context.page.wait_for_url(select_your_role_url_pattern)
5756

5857

59-
@then("I am on the login page")
60-
def i_am_on_login_page(context):
61-
# TODO: This needs to cover the .html for the broken SPA. Will need to be removed.
62-
assert context.page.url == context.cpts_ui_base_url + "site/login"
58+
@given("I am logged in with a single access role")
59+
def login_single_role(context):
60+
context.execute_steps("given I am on the login page")
61+
62+
context.page.get_by_role("button", name="Log in with mock CIS2").click()
63+
context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_SINGLE_ACCESS_ROLE)
64+
context.page.get_by_role("button", name="Sign In").click()
65+
context.page.wait_for_url(select_your_role_url_pattern)
66+
67+
68+
###############################################################################
69+
# WHEN
70+
###############################################################################
71+
72+
73+
###############################################################################
74+
# THEN STEPS
75+
###############################################################################
76+
77+
78+
@then("I am logged out")
79+
def i_am_logged_out(context):
80+
# No cookies with names starting with "CognitoIdentityServiceProvider" should be present
81+
cookies = context.page.context.cookies()
82+
cognito_cookies = [
83+
cookie
84+
for cookie in cookies
85+
if cookie["name"].startswith("CognitoIdentityServiceProvider")
86+
]
87+
assert len(cognito_cookies) == 0

features/steps/cpts_ui/logout_steps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,8 @@ def then_i_see_logout_successful_page(context):
103103
logout_page = Logout(context.page)
104104
expect(logout_page.logout_page_heading).to_be_visible()
105105
expect(logout_page.logout_page_content).to_be_visible()
106+
107+
108+
@then("I am on the login page")
109+
def then_i_am_on_login_page(context):
110+
context.page.wait_for_url("**/login")

features/steps/cpts_ui/search_for_a_prescription_steps.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44

55
from pages.home import Home
66
from pages.search_for_a_prescription import SearchForAPrescription
7-
from features.environment import MOCK_CIS2_LOGIN_ID_SINGLE_ACCESS_ROLE
8-
9-
10-
@given("I am logged in with a single access role")
11-
def login_single_role(context):
12-
context.page.goto(context.cpts_ui_base_url + "site/auth_demo.html")
13-
context.page.get_by_role("button", name="Log in with mock CIS2").click()
14-
context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_SINGLE_ACCESS_ROLE)
15-
context.page.get_by_role("button", name="Sign In").click()
16-
context.page.wait_for_url("**/searchforaprescription")
177

188

199
@when("I go to the search for a prescription page")

features/steps/cpts_ui/select_your_role_steps.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,15 @@
55
from pages.select_your_role import SelectYourRole
66

77

8-
@when("I go to the select your role page")
8+
@given("I go to the select your role page")
99
def i_go_to_the_select_your_role_page(context):
10-
# TODO: This site/*.html is not generic. Also, the .html will need to be removed when the SPA is fixed
11-
context.page.goto(context.cpts_ui_base_url + "site/selectyourrole.html")
10+
context.page.goto(context.cpts_ui_base_url + "site/")
11+
context.page.get_by_test_id("eps_header_selectYourRoleLink").click()
1212

1313

1414
@given("I am on the select your role page")
1515
def i_am_on_select_your_role_page(context):
16-
i_go_to_the_select_your_role_page(context)
17-
select_your_role_page = SelectYourRole(context.page)
18-
expect(select_your_role_page.summary).to_be_visible()
19-
20-
21-
@then("I am on the select your role page")
22-
def verify_on_select_your_role_page(context):
16+
context.execute_steps("given I go to the select your role page")
2317
select_your_role_page = SelectYourRole(context.page)
2418
expect(select_your_role_page.summary).to_be_visible()
2519

0 commit comments

Comments
 (0)