Cannot get form submit to function in Webkit Playwright

I am currently in the process of testing a basic login page using Playwright for automation.

<form method="POST" name="login">
    <input type="hidden" name="captcha_response">
    <input type="hidden" name="_token" value="token">
    <div class="form-group">
        <label for="username">Username</label>
        <input id="username" value="" type="text" maxlength="100" name="username" class="form-control" autofocus autocapitalize="none" autocomplete="username" required />
    </div>
    <div class="form-group">
        <label for="password">Password</label>
        <input id="password" type="password" maxlength="100" name="password" class="form-control" autocomplete="current-password" required />
    </div>
    <div class="form-group flex flex-col-reverse md:flex-row flex-wrap justify-between items-center">
        <div>
            <p class="text-gray-600 text-sm">
                Forgot your <a href="http://localhost:7013/forgot-username" class="text-gray-600 text-sm">username</a> or <a href="http://localhost:7013/forgot-password" class="text-gray-600 text-sm">password</a>?
            </p>
        </div>
        <button name="loginButton"  type="submit" class="btn btn-primary w-full md:w-auto mb-3 md:mb-0">Login</button>
    </div>
</form>

I have created a simple test to fill out and submit the login form, which should direct you to the dashboard upon successful login.

import { test, expect } from '@playwright/test'

test("Automation Login Test", async ({ page }) => {
    await page.goto('/login', { waitUntil: 'networkidle' });
    console.log(page.url())
    // Wait for the page to load


    await page.click('input[id="username"]')
    await page.fill('#username', 'test')

    await page.click('input[id="password"]')
    await page.fill('#password', '12345')

    const submitButton = await page.locator('button[name="loginButton"]')
    console.log('button', await submitButton.innerText())
    await expect(submitButton).toHaveCount(1)
    await submitButton.click({force: true})

    await page.waitForLoadState('networkidle')
    console.log('url', page.url())
    await expect(page).toHaveURL('/dashboard')
    await expect(page.locator('h1#page_title')).toHaveText('Good afternoon Alan');
});

This script works seamlessly on Chromium and Firefox browsers but encounters issues on WebKit.
Post button click, the URL remains at the login page instead of redirecting to the dashboard.

The testing environment consists of Ubuntu (via 5.10.16.3-microsoft-standard-WSL2) using Node v16.16.0

Sample output:

Running 3 tests using 1 worker

  ✓  1 [chromium] › tests/auth.spec.ts:3:1 › Login page (12s)
http://localhost:7013/login
button Login
url http://localhost:7013/dashboard
  ✓  2 [firefox] › tests/auth.spec.ts:3:1 › Login page (15s)
http://localhost:7013/login
button Login
url http://localhost:7013/dashboard
  ✘  3 [webkit] › tests/auth.spec.ts:3:1 › Login page (8s)
http://localhost:7013/login
button Login
url http://localhost:7013/login


  1) [webkit] › tests/auth.spec.ts:3:1 › Login page ================================================

    Error: expect(received).toHaveURL(expected)

    Expected string: "http://localhost:7013/dashboard"
    Received string: "http://localhost:7013/login"
    Call log:
      - expect.toHaveURL with timeout 5000ms
      - waiting for selector ":root"
      -   selector resolved to <html lang="en">…</html>
      -   unexpected value "http://localhost:7013/login"
      -   selector resolved to <html lang="en">…</html>
      -   unexpected value "http://localhost:7013/login"
      -   selector resolved to <html lang="en">…</html>
      -   unexpected value "http://localhost:7013/login"
      -   selector resolved to <html lang="en">…</html>
      -   unexpected value "http://localhost:7013/login"
      -   selector resolved to <html lang="en"&... 

Answer №1

With the limited context provided, it's challenging to provide a definitive response. However, I suggest replacing the following code block:

await submitButton.click({force: true})
await page.waitForLoadState('networkidle')
await expect(page).toHaveURL('/dashboard')

with:

await submitButton.click({force: true})
await page.waitForUrl('/dashboard', {waitUntil: 'networkidle'})

The reason behind this suggestion is my concern that the waitForLoadState function may be called too early, before navigation has even started (especially with webkit being notoriously slow with playwright), rendering it redundant.

Please note that there is still a 5000ms timeout in place, which seems excessive for standard navigation times. Reviewing the video at npm playwright-report under test-results/tests-auth-Login-page-webkit/video.webm could shed light on any issues encountered during testing.

Answer №2

Consider this alternative approach:

Try using the following instead:

Instead of simply waiting for network idle, try explicitly looking for a specific selector on the page:

await page.goto('/login')
await page.waitForSelector('input[id="username"]')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Vue components within SweetAlert2 content

I have a couple of basic Sweetalert2 pop-up modals within a Vue project. My goal is to incorporate a custom component into one of the alerts. For instance: <template> <h1>Greetings {{name}}</h1> </template> <script> module. ...

Heroku - Launch your code in development or live environments

I am currently hosting my express API on Heroku with two separate projects set up: one for my Master Branch (Prod) and the other for my Development branch (Dev). Inside my package.json file, I have defined two scripts: "scripts": { "d ...

What could be the reason a normalMap fails to render accurately while utilizing THREE.SubdivisionModifier?

When attempting to render a 'soft' cube with a normal map, I encountered an issue. Despite not receiving any errors or warnings while running the code, adding the normal map parameter resulted in a black object when refreshing the browser. Removi ...

How can I display the most recent offcanvas opening at the top of the page?

The issue I'm facing is related to the offcanvas3 opening behind offcanvas2. It appears like this: $("#open-offcanvas2").on("click", function(){ $("#offcanvas2").offcanvas("show") }) $("#open-offcanvas1").on("click", function(){ $("#offcanvas1" ...

Obtaining the source code from a different domain website with the help of jQuery

Is there a way to extract part of the source code from a YouTube page without using server-side programming? I've tried cross-domain AJAX techniques like Yahoo YQL and JsonP. While Yahoo YQL allows me to grab part of the source code, I'm facing ...

Using method as a filter in AngularJS: A guide to implementing custom filters

I've created a custom data type called Message: function Message(body, author, date) { this.body = body; this.author = author; this.date = date; this.stars = []; } Message.prototype.hasStars = function() { return this.stars.lengt ...

What is your approach to managing routing within a Node and Ember application?

In my application, I am working with both Node and Ember. I have encountered a problem specifically related to routes. Both Node and Ember handle routes, but I want Node to handle certain routes and Ember to handle others. When the page initially loads, No ...

creating a JSON object

Exploring JSON for the first time and I have a couple of questions: Is it possible to create a JSON object using the 'data-id' attribute and have it contain a single array of numbers? Even though I have the code to do this, I am facing difficul ...

The dot notation in JSON syntax allows for easy access

Recently, I've been struggling with referencing a variable in JSON dot notation within my meteor application. It seems that when trying to access respJson.userlower.name, userlower is not being recognized as a valid variable. Is there a workaround for ...

Looping through an array in Vue using v-for and checking for a specific key-value pair

As I dive into my first Vue app, I've encountered a minor setback. Here's my query: How can I iterate through a list of dictionaries in Vue, specifically looping through one dictionary only if it contains a certain value for a given key? Provi ...

Differences Between APP_INITIALIZER and platformBrowserDynamic with provide

I've discovered two different approaches for delaying an Angular bootstrap until a Promise or Observable is resolved. One method involves using APP_INITIALIZER: { provide: APP_INITIALIZER, useFactory: (configService: ConfigurationService) => ( ...

The Toggle Switch effectively removes the CSS class when set to false, but fails to reapply the class when set to true

Implementing a toggle switch using Bootstrap5 to control the visibility of grid lines. The setup includes adding a class to display grid lines when the toggle is true, and removing the class to hide the lines when the toggle is false. However, the issue ar ...

Turn off the Google Search Snackbar feature on your PWA for Android devices

Whenever I select text on my Progressive Web App that is installed and not running directly through Chrome, a snackbar pops up at the bottom of the screen displaying Google search results (at least on Android): https://i.sstatic.net/IbxfT.png Is there a ...

Maintain the initial worth even when making alterations

I've been working with Ag-grid and facing an issue. Initially, I load the original data into the grid using this.rowData. I have a function called addRow that successfully adds a row to the top of the existing rows. However, when the reset function ...

TS6059 found in excluded folder

I'm facing an issue with my tsconfig.json file that looks like this: {"compilerOptions": { "module": "commonjs", ...

Error in Bootstrap Auto-complete: Property " " cannot be read because it is undefined

I am attempting to implement Bootstrap autocomplete with Django. I have tested the calls and the ajax request successfully sends to my views, but I am not receiving a response in my form. An error appears in the console stating: Uncaught TypeError: Cannot ...

Utilizing PHP with WordPress: Execute the specified .js file if the link includes the ID "124"

I am currently using WordPress on my local server and I want to set up a redirect after a user submits the contact form through the Contact Form 7 Plugin. I am looking to redirect them to a specific page, but so far, the plugins I have tried have caused th ...

The declaration '() => string' cannot be assigned to type 'string' in a Typescript React program

There have been many questions similar to mine, but none of the answers seem to solve my issue. The closest answer I found was here, however, it also doesn't work for me. I have a Tsx code snippet like this: <img src={getLogo} alt="Airline Lo ...

I am looking to consolidate my array of objects into a single object with distinct keys

Hey there! I'm looking to showcase the expenses for each category throughout the months of the year. Here's an example: {Month: "January", Food: 610, foodColor: "#063951", Others: 121, othersColor: "#C13018", …} Fo ...

Starting the selection process using AngularJS and ng-repeat

My challenge is to have a pre-filled option in a select-box using ng-repeat with AngularJS 1.1.5. However, the select box always starts off with nothing selected and an empty option, which I don't want. It seems to be a side effect of not having anyth ...