Coder Social home page Coder Social logo

Comments (9)

dgozman avatar dgozman commented on June 25, 2024

@joshmgrant Could you please share a full repro with us? I suspect this is related to cwd when you run your tests. The robust solution is to provide an absolute path, for example:

import path from 'path';

test.use({ storageState: path.resolve(__dirname, '../../playwright/.auth/gmail.json') })

from playwright.

joshmgrant avatar joshmgrant commented on June 25, 2024

Here is my auth.setup.ts file

import * as fs from 'node:fs';
import { test as setup } from '@playwright/test';
import { LoginPage } from './pages/login-page';

// TODO: replace with env vars
const gmailUser = 'some_user"
const outlookUser = 'some_other_user'
const password = process.env.E2E_USER_PASSWORD || ''

// following this approach for multiple user authenications
// https://playwright.dev/docs/auth#multiple-signed-in-roles
const outlookAuthFile = 'playwright/.auth/outlook.json';

setup.skip(fs.existsSync(outlookAuthFile)); // added this based on another ticket to fix the issue
setup('authenticate as Outlook user', async ({ page }) => {
  // Perform authentication steps. Replace these actions with your own.
  const loginPage = new LoginPage(page);
  loginPage.loginAs(outlookUser, password);

  await page.context().storageState({ path: outlookAuthFile });
});

const gmailAuthFile = 'playwright/.auth/gmail.json';

setup.skip(fs.existsSync(gmailAuthFile));
setup('authenticate as GMail user', async ({ page }) => {
  const loginPage = new LoginPage(page);
  loginPage.loginAs(gmailUser, password);

  await page.context().storageState({ path: gmailAuthFile });
});

from playwright.

dgozman avatar dgozman commented on June 25, 2024

@joshmgrant Unfortunately, we cannot repro with just a single file. We need to run the whole example, so need the whole project.

Did you have a chance to try the absolute path suggestion?

from playwright.

joshmgrant avatar joshmgrant commented on June 25, 2024

Let me try the absolute path suggestion. I can see if I can get a repo but it might take some work.

from playwright.

joshmgrant avatar joshmgrant commented on June 25, 2024

Hello again. I tried an absolute file path and it doesn't seem to work. I'm also unable to share more than the config file above.

from playwright.

dgozman avatar dgozman commented on June 25, 2024

Hello again. I tried an absolute file path and it doesn't seem to work. I'm also unable to share more than the config file above.

In this case we won't be able to help, unfortunately. I'll leave this issue open for a few days, just in case you'd come up with a reproduction.


Looking at the snippet above, it seems like you'd skip both setups, for outlook and gmail, whenever any of the storage state files is present. I'd recommend to read about test.skip in the documentation.

from playwright.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.