Rayrun
← Back to Discord Forum

How to determine which page it landed on?

So I have a test where if I click on a link, it will redirect a few times and then land on one of two pages. Depending on the page depends on a list of tests I should run.

I'm not sure how to implement this. Using the below code, it always seems to go to "else" even if it's "page1". Is there a better way to do this? I can also detect whats on the page but if it times out it just fails. I was also looking at waitforURL but I would need two and one will always fail. Thoughts?

await page.locator('#button').click(); await page.waitForTimeout(30000);

const url = await page.url(); if (if (url.indexOf('test.com/landing') == -1) ) { .... } else { .... }

This thread is trying to answer question "How to determine which page a test lands on after clicking a link that redirects a few times?"

5 replies

How to determine which page it landed on?

How about doing something like this:

const [one, two] = await Promise.all([
  page.waitForUrl("/one").then(() => true).catch(() => false),
  page.waitForUrl("/two").then(() => true).catch(() => false),
]);

So if it fails then it doesn't fail the test right? Just fails gracefully?

@Ryanrk: Yes it returns true or false but does not fail the test.

Yes it returns true or false but does not fail the test.

Thank you!! To bad this Promise.any doesn't seem to exist because I would be much better as I wouldn't have to timeout the other one.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].