3

I am trying to run this code:

test('should login', async ({ page }) => {
await page.goto(localhost);
await page.fill('[name=username]', 'username');
await page.fill('[name=password]', 'password');
await page.click('[name=login]');
await page.waitForURL(`${localhost}/main`);
const currentUrl = await page.url();
expect(currentUrl).toBe(`${localhost}/main`);
});

When I run it with npx playwright test localy, the test passes; but, when run in CI/CD, it fails:

Timeout of 180000ms exceeded.
page.waitForURL: Navigation failed because page was closed!
=========================== logs ===========================
waiting for navigation to "http://localhost:3000/main" until "load"
============================================================

Any idea what causes this problem?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83

1 Answers1

1

I would try logging all network requests to see what's going on there:

// Log and continue all network requests
  page.route('**', (route, request) => {
    console.log(request.url());
    route.continue();
});

If it never gets beyond the goto(), perhaps try using the new playwright request fixture to see if it can even reach http://localhost:3000/main.

await page.request.get("http://localhost:3000/main", { ignoreHTTPSErrors: true });
Nico Mee
  • 869
  • 5
  • 6
  • 2
    So the problem was that when i ran the test localy, i was connected to the backend thanks to VPN. However CI/CD doesnt have any way to connect to BE and the page never gets from login to main page. – Tomáš Hrubý Dec 27 '21 at 11:22
  • @TomášHrubý did you solve this? i'm currently having this issue – Dids Apr 21 '23 at 07:12