Rayrun
← Back to Discord Forum

Trying to loop thru lots of links

tennis6164
tennis6164

Hi, I have an AWS Amplify app that has lots of pages with collections of Amplify Cards. What I am trying to do is find each card on a page, visit the card's link, return to the original page, and repeat the process with the next card, and so forth.

So far, I've been unable to get it to work. Here is my test code:

test('dzr pages', async ({page}) => {
  await login(page);
  await page.goto('http://localhost:3000/DanzanRyu/Home');
  await page.on('domcontentloaded', data => {});
  const elements = await page.locator('.amplify-card').all()
  for (let i = 0; i < elements.length; i++) {
    await elements[i].click()
    await page.goto('http://localhost:3000/DanzanRyu/Home');
  }
});

Attached is also some snapshots of the page info.

TIA, -T

image.png
image.png

This thread is trying to answer question "How can I loop through multiple links on an AWS Amplify app to check for broken links?"

6 replies

Is their any information what you want to extract or just loop I would suggest adding a waitForLoadState in the loop

tennis6164
tennis6164

@pregot Thanks for the response. Good question. I'm just looking for broken links. I'll try your suggestion.

@tennis6164 I can help you with that my the code should like this ` test('dzr pages', async ({page}) => { await login(page); await page.goto('http://localhost:3000/DanzanRyu/Home');

const elements = await page.locator('.amplify-card').all()

for (let i = 0; i < elements.length; i++) { await elements[i].click();

// Wait for navigation to complete.
await page.waitForLoadState('networkidle');

// Check that a valid response was received.
page.on('response', response => {
  expect(response.status()).toBe(200);
});

// Go back to the home page for the next iteration.
await page.goto('http://localhost:3000/DanzanRyu/Home');

} });

`

tennis6164
tennis6164

@pregot Thanks~

tennis6164
tennis6164

!

Be aware networkidle may work, may not, plenty of pages in the app i test networkidle only would produce flakey tests, your use may vary...

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 luc@ray.run.