Rayrun
โ† Back to Discord Forum

Trouble getting baseUrl to work: Error: page.goto: Protocol error (Page.navigate): Cannot navigate t

I am new to playwright and am having trouble getting things. I am following the tutorials and trying to get a baseURL configured. I used the config example in the docs, and placed this into my playwright.config.ts (with other settings)

const config: PlaywrightTestConfig = {
  use: {
    baseURL: 'http://localhost:5173/tatsu',
  },
}

but when my test runs, it says I'm navigating to an invalid URL which tells me it's not picking up the baseURL.

Error: page.goto: Protocol error (Page.navigate): Cannot navigate to invalid URL
=========================== logs ===========================
navigating to "/", waiting until "load"
============================================================

   at ..\..\playwright\fixtures.ts:29

  27 |       const page = await browser.newPage({ storageState: undefined })
  28 |
> 29 |       await page.goto('/')

I am also using a fixture mostly copied from the authentication example here https://playwright.dev/docs/auth

This thread is trying to answer question "Why is the baseURL not working in Playwright despite following the tutorials and using the config example from the documentation?"

17 replies

Are you exporting your config within your config file?

yes, the config itself works fine - for example the webserver block works as expected and boots up our app

I've confirmed I do export the config object

export default config

ok I fixed this... the config docs have defineConfig(config) now, but I started this work months ago and either copied the code and it didn't have it then, or I somehow lost it

still weird that the other configs work... but oh well it's all fine now

Glad to hear ๐Ÿ˜†

oh interesting... the fixture still doesn't use it

but my tests do

when I removed my hard-coded url from the fixture's goto, it gives me the same "invalid url" error

It seems like the baseURL is not being applied in the context of the custom fixture. This could happen if the custom fixture is creating a new browser context or page without inheriting the configuration.

In Playwright, the configuration specified in the playwright.config.ts file applies to the default fixtures provided by Playwright, like page. If you define a custom fixture that creates a new browser context or page, you may need to manually apply the baseURL.

ah ok

ya it does call const page = await browser.newPage({ storageState: undefined })

That will probs explain the issue. When you call browser.newPage() within the custom fixture, it creates a new page without the configuration that was set in the playwright.config.ts file.

ok well I guess I'll do import config from '../../playwright.config' and use the baseUrl in the goto

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 [email protected].