Skip to content

Commit

Permalink
Fix flaky new tabs tests (#185)
Browse files Browse the repository at this point in the history
* Test links have target = _blank

* Update link names
  • Loading branch information
BenMillar-MOJ authored Mar 6, 2025
1 parent 19622dd commit fec3c70
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions tests/functional_tests/categories/test_out_of_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,25 @@ 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 (opens new tab)",
"Advicelocal (opens new tab)",
"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'"
)

0 comments on commit fec3c70

Please sign in to comment.