Rayrun
← Back to Discord Forum

BaseURL in fixture is not defined in CI

.milkncheeseposted in #help-playwright
Open in Discord
.milkncheese
.milkncheese

Hello! Im using the preserved authentication feature in a fixture as per the example https://playwright.dev/docs/auth#moderate-one-account-per-parallel-worker. However, when the logic goes to the login page, I have the baseURL set through a process.env.URL setting and its not being recognized when I use page.goto('/login'). I tried to set the baseURL when using browser.newPage and it was unable to resolve the process.env.URL as well. This issue only happens when the tests are ran in GitHub Actions. The baseURL is handled properly when the tests are run locally. Any ideas?

This thread is trying to answer question "Why is the baseURL not being recognized when using the preserved authentication feature in a fixture in GitHub Actions and how can this be resolved?"

4 replies

Sounds like your baseUrl isn't set at all in your pipeline?

Have you added URL as environment variable in you github workflow? Or are you loading it from an .env file? Have you pushed your .env file?

we are setting the URL in the command line args. we dont commit the .env file into the repo. i think the problem is that we are using

// Authenticate once per worker with a worker-scoped fixture. workerStorageState: [async ({ browser }, use) => { // Use parallelIndex as a unique identifier for each worker. const id = test.info().parallelIndex; const fileName = path.resolve(test.info().project.outputDir, .auth/${id}.json);

if (fs.existsSync(fileName)) {
  // Reuse existing authentication state if any.
  await use(fileName);
  return;
}

// Important: make sure we authenticate in a clean environment by unsetting storage state.
const page = await browser.newPage({ storageState: undefined });
const account = await acquireAccount(id);

// Perform authentication steps. Replace these actions with your own.
await page.goto('https://github.com/login');
await page.getByLabel('Username or email address').fill(account.username);
await page.getByLabel('Password').fill(account.password);
await page.getByRole('button', { name: 'Sign in' }).click();

await page.waitForURL('https://github.com/');
await expect(page.getByRole('button', { name: 'View profile and more' })).toBeVisible();

// End of authentication steps.

await page.context().storageState({ path: fileName });
await page.close();
await use(fileName);

}, { scope: 'worker' }],

this section of code doesnt have the baseURL available and i dont know how to pass it to this block

I would expect the new Page to use the baseUrl from config by default, but could you test setting it manually? https://playwright.dev/docs/api/class-browser#browser-new-page-option-base-url

Either by using the baseURL fixture or workerInfo.config

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].