question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Tests pass when running one file at a time but when all files are run, random ones start failing?

See original GitHub issue

Hi, so I’m testing mostly links/buttons on the lucidmotors.com website, and some tests are really giving me a hard time - specifically the main nav, side nav and footer. When I run a minimal amount of tests at a time (like a handful or even just 1 file) on gitlab, everything passes. However, when I run all the tests at the same time tests start failing mostly because of timeouts while waiting for selectors or navigations and I know it’s not a bug on the website’s end because each time it’s random ones that are failing (a certain test will pass one time and then fail the next) and I’ll also go and try to reproduce the bug and nothing breaks. I’ve tried upping the workers and timeouts but that doesn’t fix the problem. It’s really hard trying to figure out what the problem is because I haven’t found much when googling this issue.

All my tests follow the same type of layout:

test.describe.parallel('Footer on home page', () => {

  test.beforeEach(async ({ page }) => {
    await page.goto('https://www.lucidmotors.com');
    await page.locator('text=Accept Cookies').click();
  });

  test.afterEach(async ({ page }) => {
    await page.close();
  });

  test('Discover Air', async ({ page }) => {
    await page.locator('footer >> text=Discover Air').click();
    await expect(page).toHaveURL('https://www.lucidmotors.com/air')
  });

  test('Design Yours', async ({ page }) => {
     await page.locator('footer >> text=Design Yours').click();
     await expect(page).toHaveURL('https://www.lucidmotors.com/air/configure')
  });

obviously with more links, and then I thought it might be a network issue so I refactored to have them look like this:

test.describe.parallel('Footer on home page', () => {

  test.beforeEach(async ({ page }) => {
    await page.goto('https://www.lucidmotors.com');
    await page.locator('text=Accept Cookies').click();
  });

  test.afterEach(async ({ page }) => {
    await page.close();
  });

  test('Discover Air', async ({ page }) => {
       await expect(page.locator('footer >> a[href="/air"]')).toContainText("Discover Air");
  });

  test('Design Yours', async ({ page }) => {
       await expect(page.locator('footer >> a[href="/air/configure"]')).toContainText("Design Yours");
  });

I’m wondering if these are the correct way to be setting up the tests or if I’m missing something. Or if it’s really due to some slow backend/network issues.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
haramchangcommented, Mar 28, 2022

Hi thanks for the response! Yeah I wasn’t sure if the after hooks were truly necessary but it didn’t seem to have an adverse effect on the tests and it also seemed like the pages for each test weren’t closing until the whole test run was finished (?) so I thought it’d be best to leave it in there to avoid saturation. And weird!! I’ll try seeing if I can get a Trace for a failed test case and I’ll post it here! Thank you 😃

0reactions
jakebankscommented, Nov 10, 2022

@haramchang thanks for raising this issue, it sounds like what I’m seeing - were you able to work out the root cause? I am yet to work toward a CI environment that supports artifacts so haven’t been able to investigate properly yet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do my tests fail when run together, but pass individually?
Such a situation normally occurs when the unit tests are using shared resources/data in some way. It can also happen if your system...
Read more >
Automated tests pass every time when run individually, but ...
When I clump any number of tests together into a suite, running the suite will yield random results to my tests. Some will...
Read more >
Why Do My Tests Pass Locally but Fail on CircleCI?
If the machine does not have a set timezone, some tests may fail. ... This means that all files are read in the...
Read more >
How to run failed test cases in TestNG & Selenium
Test cases usually fail due to server and network issues, an unresponsive application or validation failure, or even due to scripting issues.
Read more >
Testing - Spring
This chapter covers Spring's support for integration testing and best practices for unit testing. The Spring team advocates test-driven ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found