Rayrun
← Back to Discord Forum

Test passes while debugging but fails during normal execution

andre_at_performant_labsposted in #help-playwright
Open in Discord
andre_at_performant_labs

I've got a test written in Javascript that performs a standard operation in Drupal with a mostly vanilla installation of Drupal. I'm using VS Code 1.81.1 (latest version) on macOS. Playwright is version 1.37.1 (latest version). The steps of the test are:

  1. Create a new page with specific text and save it. Confirm the text.
  2. Change the text and save it. Confirm the changed text.
  3. Delete the page. This works perfectly fine while debugging but fails when I run it at full speed in VS Code or via the command line. When I look at the record, the update didn't work. It worked fine while stepping through.

You can see this in the a video I made: https://drive.google.com/file/d/1Mf_fkiYSlF7t1WyjClIWnzK5FIgaonh2/view?usp=sharing

Here is my question: what could possibly be causing the second save operation to fail when running at full speed? I've even placed this after the save, but it doesn't help: await page.waitForLoadState('domcontentloaded');

This thread is trying to answer question "What could possibly be causing the second save operation to fail when running at full speed?"

20 replies

maybe adding await page.pause(); in between your test instructions can help ?

I believe Debug mode is different. First it has no timeout. Secondly, it will wait until an element is presented, while actual execution might not

andre_at_performant_labs
@fran_trazit: I could do that...see what's happening right before the button is pushed.

I could do that...see what's happening right before the button is pushed.

andre_at_performant_labs
@jimmy7997: that's what I was thinking (that the runner may not be waiting). But what's weird is that the save *just looks* like it is occurring. I even get a message saying the record has been updated. But the database doesn't change. It's baffling.

that's what I was thinking (that the runner may not be waiting). But what's weird is that the save just looks like it is occurring. I even get a message saying the record has been updated. But the database doesn't change. It's baffling.

For mine one, I use traceview to see where it fail, and add page timeout to do a quick test to see if it's the issue:

in config file use: { trace: 'retain-on-failure', },

@andre_at_performant_labs: Sometimes too the save from frontend, takes a while to finish. We click 'Save'/'Create' button, but the request is still firing. Then the test end close the browser and interrupt the creation process. I have had to wait for specific UI element like the spinner to appear and dissapear

Sometimes too the save from frontend, takes a while to finish. We click 'Save'/'Create' button, but the request is still firing. Then the test end close the browser and interrupt the creation process. I have had to wait for specific UI element like the spinner to appear and dissapear

andre_at_performant_labs
@jimmy7997: ok, I'll give this a whirl tomorrow. Thank you.

ok, I'll give this a whirl tomorrow. Thank you.

andre_at_performant_labs

I've examined the trace carefully, found one more layer of cache that I had thought was already off and turned it off and still the data was not being saved.

The only thing that worked was to add a sloMo of 1000. With that, the test runs just fine outside of debug mode.

Unfortunately, it doesn't seem to be possible to slow down just a section of code. There are a few issues asking for it but it doesn't seem to have been implemented yet.

Not sure what to try next.

@andre_at_performant_labs I know it’s not ideal to add timeouts but if you don’t want to slow down all tests you can try adding time outs only for that test.

andre_at_performant_labs

Yes, that's a good idea, even if it's suboptimal. Better than adding a sloMo of 1000.

@andre_at_performant_labs: Hey André, have you found a better solution for this? I got the same problem, that the tests are passing in UI and debug mode, but not during normal execution.

Hey André, have you found a better solution for this? I got the same problem, that the tests are passing in UI and debug mode, but not during normal execution.

andre_at_performant_labs

Unfortunately I did not. I had to add timeouts.

sad :/

but thanks!

@andre_at_performant_labs: I've fixed my problem. I put the "await" keyword at the wrong position. Maybe it will help you as well. Wrong: `expect( await page.getByText(testEntryInternaText)).not.toBeVisible()` Right: `await expect( page.getByText(testEntryInternaText)).not.toBeVisible()`

I've fixed my problem. I put the "await" keyword at the wrong position. Maybe it will help you as well. Wrong: expect( await page.getByText(testEntryInternaText)).not.toBeVisible()

Right: await expect( page.getByText(testEntryInternaText)).not.toBeVisible()

.aleksandaraleksandrov
.aleksandaraleksandrov

I little tip - the await word has to be where the used method is:

example 1: await expect(page.locator('')).toBeVIsible() - here the await is next to be expect because it is waiting for the toBeVisible()

example 2: expect(await page.locator('').textContent()).toBe("something") - here the await is with textContent() because it is waiting for the locator and the textContent().

This is how I use the awaits, might be wrong and sorry if I misslead somebody.

andre_at_performant_labs

Oh, good.

When I look at your video, one things come out: toContain is not a web assertion and will assert immediately instead of awaiting for it to reach the desired state. Would explain your debug mode passing but not when you execute normally

So I highly recommend you to leverage web assertions as they work best for this kind of flakiness you're experiencing (will wait for the desired state a certain amount of time). Try toContainText or toHaveText instead, with the await. VS code actually pointed this out as underlining the unnecessary await with toContain.

@phiill: There's `toBeHidden` as well, FYI 🙂

There's toBeHidden as well, FYI 🙂

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.