Giter VIP home page Giter VIP logo

Comments (4)

yury-s avatar yury-s commented on May 18, 2024 3

The biggest downside with this is when running single tests with 'Show browser' enabled, it'll flash a white page in a new window before opening the actual test.

You can call test.skip based on a condition outside the tests:

setup.skip(fs.existsSync(storageFilePath) && !fileOlderThan(storageFilePath, "4h"));
setup("Authenticate into CMS", async ({ page }) => {
  ...
});

Or wrap relevant tests into test.describe and skip only it if you still want to run the rest.

from playwright.

yury-s avatar yury-s commented on May 18, 2024

I'd expect the dependency to run once and generate the storage state file. And then in subsequent runs, the dependency should not be run since the storage state file already exists.

You can easily achieve that by having you setup code check if the storage state file already exists and skip expensive setup steps in that case. Playwright does not do this automatically.

const authFile = 'playwright/.auth/user.json';

setup('authenticate', async ({ request }) => {
  if (fs.existsSync(authFile))
    return;
  // Send authentication request. Replace with your own.
  await request.post('https://github.com/login', { ... });
  await request.storageState({ path: authFile });
});

If I play all the tests, eg. using the Screenshot 2024-04-18 at 8 16 41 AM button, then the expected behavior occurs, eg. the setup only runs once before all the tests.

Playwright will run setup dependencies on every run. It will run each dependency exactly once, regardless of how many tests are in the dependent project.

from playwright.

alectrocute avatar alectrocute commented on May 18, 2024

You can easily achieve that by having you setup code check if the storage state file already exists and skip expensive setup steps in that case. Playwright does not do this automatically.

Yeah, that's what I'm doing currently.

setup("Authenticate into CMS", async ({ page }) => {
  if (fs.existsSync(storageFilePath) && !fileOlderThan(storageFilePath, "4h")) {
    return;
  }
  ...
});

It would be nice if it did this automatically somehow, but I get it. The biggest downside with this is when running single tests with 'Show browser' enabled, it'll flash a white page in a new window before opening the actual test.

from playwright.

alectrocute avatar alectrocute commented on May 18, 2024
setup.skip(fs.existsSync(storageFilePath) && !fileOlderThan(storageFilePath, "4h"));

@yury-s, that's... brilliant. This needs to be in the docs on the Authentication page.

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.