Trouble with Playwright test loading local URL

I'm encountering difficulties with the homepage loading in my application, despite having what I believe to be correct configurations. The test and playwright config are as follows:

example.spec.ts

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

test('Visit Pages', async ({ page }) => {

  await page.goto('https://playwright.dev/'); //this works
  await page.goto('http://localhost:3000/'); //this does not work

  //this also doesn't work
  await page.goto('http://localhost:3000/', {
    waitUntil: 'domcontentloaded',
    timeout: 60000,
  });
  ...
}

playwright.config.ts

import { defineConfig, devices } from '@playwright/test'

export default defineConfig {
  testDir: 'tests',
  headless: false,
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: 'html',
  use: {
    baseURL: 'http://localhost:3000',
    storageState: './state.json'
    trace: 'on-first-retry',
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
    {
      name: 'Google Chrome',
      use: { ...devices['Desktop Chrome'], channel: 'chrome' },
    },
  ],
  webServer: {
    command: 'yarn dev',
    url: 'http://localhost:3000',
    reuseExistingServer: true,
  },
}

The webserver is operational, so I am puzzled as to why it's failing to load properly.

Prior to running the command yarn playwright test --ui, I ensure that the app is up and the webServer/front-end is running. I've confirmed that I can access the home page normally on Google Chrome and the backend endpoints using Postman... both of which work fine in another playwright test. However, the issue persists with the page displaying nothing but a blank screen and a loading circle. It needs to load for me to start interacting with elements such as text fields.

I'm still navigating TypeScript and although experienced with Cypress, grappling with this Playwright setup for the basics has been challenging.

Answer №1

One useful technique is to confirm the visibility of elements that become visible after the page has loaded, such as a common welcome message on the home page.

This issue arises because Playwright completes tasks quickly and may fail tests before the page finishes loading.

await page.goto('http://localhost:3000/')

await expect(page.getByText('Welcome')).toBeVisible()

Utilizing a web assertion like toBeVisible ensures that the test waits until the element is visible, addressing this problem effectively.

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

Ionic 2 [InAppBrowser] disallowed due to user agent error

Encountering an issue when trying to load a webpage using the InAppBrowser cordova plugin. The error message "disallowed user agent" is being displayed. See below : Error disallowed user agent Here is the code snippet for opening the page : let browserR ...

Retrieving Vue component properties as a data type

I'm facing a dilemma with my Vue components. I want to extract the props from one component and use them as a type instead of a value in another component. Specifically, I have a component where I need to take in an array of props from a different com ...

Guide to creating a unit test for canActivate guard in Angular routing

Seeking guidance on writing a unit test for angular routing with the canActivate guard. Encountering an error when using the guard on routes, but no error is thrown without it. Would appreciate a suitable example along with an explanation. app-routing.mod ...

How to retrieve the parent activated route in Angular 2

My route structure includes parent and child routes as shown below: { path: 'dashboard', children: [{ path: '', canActivate: [CanActivateAuthGuard], component: DashboardComponent }, { path: & ...

Tips for implementing the handleChange event with CalendarComponent from the PrimeReact library

Hey there! I'm currently working with the CalendarComponent from the PrimeReact library in my app. I want to update the type of event being typed in the handleChange function instead of leaving it as :any. Can anyone provide some suggestions on what s ...

I'm sorry, but I couldn't generate a unique rewrite for this text as it is an error message. If you have any other text

After attempting to import react-dnd, I encountered the following error: The module 'react-dnd' does not have a declaration file and is implicitly assigned an 'any' type. To resolve this issue, try running `npm install @types/react-dnd` ...

Tips on duplicating objects in TypeScript with type annotations

My goal is to inherit properties from another object: interface IAlice { foo: string; bar: string; }; interface IBob extends IAlice { aFunction(): number; anotherValue: number; }; let alice: IAlice = { foo: 'hi', bar: 'bye&apo ...

Is there a way to reverse the distributive property of a union in TypeScript?

Looking at the following code snippet, what type should SomeMagic be in order to reverse the distributiveness of Y? type X<A> = { value: A }; type Y = X<number> | X<string>; type Z = SomeMagic<Y>; // <-- What type should Some ...

Is it possible to close a tab while the chrome extension popup is still active?

I am currently developing a Chrome extension that reads the content of the current tab and performs a heavy task on the backend. If I were to close the tab while the process is ongoing, how can I allow the user to do so without waiting for the task to fi ...

Utilize only the necessary components from firebase-admin in Cloud Functions with Typescript

When I looked at my transpiled code from cloud functions, I noticed the following TypeScript import: import { auth, firestore } from 'firebase-admin'; It gets transpiled to: const firebase_admin_1 = require("firebase-admin"); Upon further exa ...

Ways to receive a reply from EventEmitter

From the child component, I made a call to a certain method. Here is the code in the child component: @Output() parentEvent = new EventEmitter<any>(); click1() { //calling the specified method from the child this.parentEvent.emit(myObj1); ...

There was a TypeError encountered when trying to access the property 'Symbol(Symbol.iterator)' of an undefined variable

Whenever a web service request fails, this exception is thrown: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined Specifically, the HTTP GET request returns a 400 Bad Request error. Below is the component involved in this ...

Unable to verify Angular 5 identity

After authentication, the application should redirect to another page. However, despite successful authentication according to the logs, the redirection does not occur. What could be causing this issue? auth.guard.ts: import { Injectable } from &apos ...

The 'bind' property is not found within the 'void' data type

Here's the code snippet I'm working with: setInterval(this.CheckIfCameraIsAvailable(false).bind(this), 2 * 60 * 1000); private CheckIfCameraIsAvailable(forceCheck: boolean) { } I encountered the following error message: Property 'bin ...

Using Visual Studio Code, the next app created with nx now supports relative imports

I am encountering a problem with a Next.js project set up using nx and VS Code: When trying to automatically import a component in VS Code, it generates an absolute import which then triggers the @nrwl/nx/enforce-module-boundaries eslint rule, rendering t ...

Error: Unable to use import statement outside of a module when deploying Firebase with TypeScript

Every time I try to run firebase deploy, an error pops up while parsing my function triggers. It specifically points to this line of code: import * as functions from 'firebase-functions'; at the beginning of my file. This is a new problem for me ...

Ensure that an input control consistently displays the value it is linked to

Here is the code snippet of the component: @Component({ template: ` <form> <label>Enter your name:</label> <input #name name="name" [ngModel]="firstName" (change)="onNameChange(name.value)"> </form> <p>Y ...

Configuring Typescript target and library to utilize Promise.allSettled on outdated web browsers

I am currently using TypeScript version 4.3.5 and Node.js version 14.18.1 in my project. The code I am working on is compiled to target both old and new browsers by setting target=es5 in the tsconfig file. I make use of both Promise.all and Promise.allSett ...

Having trouble with implementing a custom hook in React using Typescript?

Having difficulty with typing in the following Hook: import { SetStateAction, useCallback, useEffect, useRef, useState } from 'react'; type Callback<T> = (value?: T) => void; type DispatchWithCallback<T> = (value: T, callback?: Ca ...

Assigning a value to an angular object

In my current project with Angular 16, I am executing a query on the database and assigning the returned number to a document number. Data Model export class Document { doc_data: string =""; doc_for: string=""; doc_number: number = 0; doc_ ...