Home > front end >  Playwright: page.goto: url: expected string, got undefined
Playwright: page.goto: url: expected string, got undefined

Time:11-07

Hi guys: I'm facing the next issue in Playwright when I try to run it.

 page.goto: url: expected string, got undefined

This is my config.cjs file:

const timeout = 3000
const waitTime = 6000
const baseUrl = 'http://XX.XXX.XXX.51/'

This is the login.page.cjs file:

const {baseUrl} = require("../config.cjs");
const {expect} = require("@playwright/test");

const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
const pageTitle = async () => await page.$('//h2[contains(text(),\'My Profile\')]')
const homeIcon =  async () => await page.$('//html[1]/body[1]/div[1]/div[1]/div[1]/div[2]/ul[1]/li[1]/span[1]')
const onStarHomeTitle = async () => await page.$('//h2[contains(text(),\'Pre-Owned Activation\')]')

class LoginPage {

    async navigateToHomePage() {
        await page.goto(baseUrl)
        //    await page.waitForNavigation()
        await delay(3000)
    }

    async verifyHeaderIconHome() {
        await expect.soft(homeIcon).toBeTruthy()
    }

    async verifyOnStarTitle() {
        await expect.soft(onStarHomeTitle).toBeTruthy()
    }
}

module.exports = { LoginPage };

In this section of code system fails: await page.goto(baseUrl)

Browser launchs, but closes. Could you please help me with this?

CodePudding user response:

You need to export baseUrl from you config when you want to import it

// config.cjs
const timeout = 3000
const waitTime = 6000
const baseUrl = 'http://XX.XXX.XXX.51/'

module.exports = {baseUrl};
  • Related