From 2613dedf828b199d7ecef97318404d2eb22b3416 Mon Sep 17 00:00:00 2001 From: Ben Millar Date: Thu, 6 Mar 2025 10:18:50 +0000 Subject: [PATCH 1/2] Test links have target = _blank --- .../categories/test_out_of_scope.py | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/tests/functional_tests/categories/test_out_of_scope.py b/tests/functional_tests/categories/test_out_of_scope.py index 99a9dc18a..a5a4b4b80 100644 --- a/tests/functional_tests/categories/test_out_of_scope.py +++ b/tests/functional_tests/categories/test_out_of_scope.py @@ -54,28 +54,23 @@ def test_mental_capacity(page: Page): onward_links = [ - ( - "free or affordable legal help", - "Finding free or affordable legal help - Citizens Advice", - ), - ("Citizen’s Advice", "Contact us - Citizens Advice"), - ("Advicelocal", "Find an adviser | Advicelocal"), - ("exceptional case funding", "Legal aid: Funding for exceptional cases - GOV.UK"), - ( - "What did you think of this service?", - "Give feedback on Check if you can get legal aid - GOV.UK", - ), + "free or affordable legal help", + "Citizen's Advice", + "Advicelocal", + "exceptional case funding", + "What did you think of this service?", ] @pytest.mark.usefixtures("live_server") -@pytest.mark.parametrize("onward_link_text, expected_title", onward_links) -def test_onward_links(page: Page, onward_link_text, expected_title): +@pytest.mark.parametrize("onward_link_text", onward_links) +def test_onward_links_open_in_new_tab(page: Page, onward_link_text): page.get_by_role("link", name="More problems covered by legal aid").click() page.get_by_role("link", name="Next steps to get help").click() page.get_by_role("button", name="Next steps to get help").click() - with page.expect_popup() as popup_info: - page.get_by_role("link", name=onward_link_text).click() - popup = popup_info.value - expect(popup).to_have_title(expected_title) + link = page.get_by_role("link", name=onward_link_text) + + # Check if the link has target="_blank" attribute (opens in new tab) + target_attr = link.get_attribute("target") + assert target_attr == "_blank", f"Link '{onward_link_text}' does not have target='_blank'" From 4daa5e7c90dbdc2fcf119d0619b84aed732b2886 Mon Sep 17 00:00:00 2001 From: Ben Millar Date: Thu, 6 Mar 2025 10:31:05 +0000 Subject: [PATCH 2/2] Update link names --- tests/functional_tests/categories/test_out_of_scope.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/functional_tests/categories/test_out_of_scope.py b/tests/functional_tests/categories/test_out_of_scope.py index a5a4b4b80..c118a1922 100644 --- a/tests/functional_tests/categories/test_out_of_scope.py +++ b/tests/functional_tests/categories/test_out_of_scope.py @@ -55,8 +55,8 @@ def test_mental_capacity(page: Page): onward_links = [ "free or affordable legal help", - "Citizen's Advice", - "Advicelocal", + "Citizen’s Advice (opens new tab)", + "Advicelocal (opens new tab)", "exceptional case funding", "What did you think of this service?", ] @@ -73,4 +73,6 @@ def test_onward_links_open_in_new_tab(page: Page, onward_link_text): # Check if the link has target="_blank" attribute (opens in new tab) target_attr = link.get_attribute("target") - assert target_attr == "_blank", f"Link '{onward_link_text}' does not have target='_blank'" + assert target_attr == "_blank", ( + f"Link '{onward_link_text}' does not have target='_blank'" + )