Skip to content

Instantly share code, notes, and snippets.

@arjunattam
Last active April 5, 2024 21:22
Show Gist options
  • Save arjunattam/c08f16959d0d825717a2205583a40e44 to your computer and use it in GitHub Desktop.
Save arjunattam/c08f16959d0d825717a2205583a40e44 to your computer and use it in GitHub Desktop.
Redux store testing with Playwright
const pw = require('playwright');
(async () => {
const browser = await pw.chromium.launch();
const context = await browser.newContext();
// set addInitScript to run this on every page load in this context
// in the app, use window.IS_PLAYWRIGHT to set window.store = store;
await context.addInitScript('window.IS_PLAYWRIGHT = true;')
const page = await context.newPage();
await page.goto('http://localhost:3000');
// evaluate in page context to get window.store, and
// then assert values in nodejs
console.log(await page.evaluate(() => window.store.getState()));
// dispatching actions to modify redux store
await page.evaluate(() => {
window.store.dispatch({ type: 'ADD_TODO', text: 'Test dispatch' });
});
console.log(await page.evaluate(() => window.store.getState()));
await browser.close();
})();
@filepi
Copy link

filepi commented Apr 5, 2024

That's awesome, Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment