|
1 | 1 | # pylint: disable=no-name-in-module |
| 2 | +import re |
2 | 3 | from behave import given, then # pyright: ignore [reportAttributeAccessIssue] |
3 | 4 |
|
4 | 5 | from features.environment import ( |
5 | 6 | MOCK_CIS2_LOGIN_ID_MULTIPLE_ACCESS_ROLES, |
6 | 7 | MOCK_CIS2_LOGIN_ID_NO_ACCESS_ROLE, |
| 8 | + MOCK_CIS2_LOGIN_ID_SINGLE_ACCESS_ROLE, |
7 | 9 | ) |
8 | 10 |
|
| 11 | +select_your_role_url_pattern = re.compile(r".*/selectyourrole(?:/|\.html)$") |
9 | 12 |
|
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 | +############################################################################### |
20 | 16 |
|
21 | 17 |
|
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/") |
30 | 21 |
|
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() |
39 | 27 |
|
40 | 28 |
|
41 | 29 | @given("I am logged in") |
42 | 30 | 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 | + |
44 | 33 | context.page.get_by_role("button", name="Log in with mock CIS2").click() |
45 | 34 | context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_MULTIPLE_ACCESS_ROLES) |
46 | 35 | 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 |
48 | 46 |
|
49 | 47 |
|
50 | 48 | @given("I am logged in without access") |
51 | 49 | 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 | + |
53 | 52 | context.page.get_by_role("button", name="Log in with mock CIS2").click() |
54 | 53 | context.page.get_by_label("Username").fill(MOCK_CIS2_LOGIN_ID_NO_ACCESS_ROLE) |
55 | 54 | 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) |
57 | 56 |
|
58 | 57 |
|
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 |
0 commit comments