Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Equivalent of the Cypress Clock function #10939

Closed
Phonesis opened this issue Dec 15, 2021 · 2 comments
Closed

Request: Equivalent of the Cypress Clock function #10939

Phonesis opened this issue Dec 15, 2021 · 2 comments

Comments

@Phonesis
Copy link

With Cypress, you can manipulate the browser time in a test via the clock() function. This is very useful for testing time based logic such as idle logout messages etc.

For example, you can speed up time by calling it like so:

cy.clock(new Date());
cy.tick(600*1000);
//assert some logic for when browser session is idle for 10 mins

I just wondered if there were any plans to add something like this to Playwright? Right now, it feels like one of the killer features of Cypress Playwright currently lacks.

@Kremliovskyi
Copy link

Kremliovskyi commented Dec 15, 2021

I asked the same question they answered me here is a feature request #6347
This is working for me

async function fakeTime(context: BrowserContext) {
    await context.addInitScript({
        path: path.join(__dirname, "../node_modules/sinon/pkg/sinon.js"),
    });
    await context.addInitScript(() => {
        // @ts-expect-error __clock does not exist
        window.__clock = sinon.useFakeTimers({
            now: new Date(2021, 10, 1).getTime(),
        });
    });
}

https://sinonjs.org/releases/latest/fake-timers/

@mxschmitt
Copy link
Member

mxschmitt commented Dec 15, 2021

Closing and folding into #6347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants