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:
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?"
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.
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
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.
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.
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 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.
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
.
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].