Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky new tabs tests #185

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'"
)
Loading