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
Setting up an environment with persistentContext #188
Comments
I'm pretty sure there's a more DRY way to do this, but I've opened #192 to kickstart a discussion. Note that the browser global will be Additionally, it looks like there's a playwright bug that needs to be addressed around this behaviour. I've opened an issue to track it here: microsoft/playwright#2828 |
@mmarkelov - I'm not sure that your PR actually solves the issue. I'm running into the same issue as the one I described on microsoft/playwright#2828 when there are two test files. I'm running the latest beta with the following config: module.exports = {
launchOptions: {
headless: false,
args: [
`--disable-extensions-except=${extensionDistDir}`,
`--load-extension=${extensionDistDir}`,
],
},
launchType: "PERSISTENT",
userDataDir: extensionDataDir,
} The path of least resistance to solve this (per comment here) would be to add a random nonce to the userDataDir. |
@karthikiyengar I can add |
@mmarkelov - I'm running it with The only way to spawn a new context per test suite in our case would be to have a different folder AFAIK, since |
@karthikiyengar I just don't have any experience with |
@mmarkelov - Yes, that will get the job done. I will add that I'm not entirely sure whether the approach we're taking with this is correct though, and sadly I lack the time to dig deeper. I've moved to puppeteer for now. For the record, Also, another difference in behaviour I've noticed is that |
@karthikiyengar, I have the exact same scenario than @mmarkelov where I need to test an extension and it looks like it has to be done from a persistent context. I am hitting the error your mentioned where the global |
Just adding another use case where we have a similar issue with persistent context and multiple test files failing with Outside of manually handing playwright setup and jest integration, are there other workarounds people have found for this? |
@karthikiyengar I don't have much experience with MFA testing. Could you please provide some test examples? I tried to look through and help you if I can |
@mmarkelov We are not testing the MFA itself so much as we need to get though the authentication in order to test the rest of our app. Since MFA requires a separate passcode sent through a phone on each login, we cannot practically automate the login itself. Instead, before running the automated tests, we launch the browser with a persistent context and login manually. The login state is saved in the persistent data of the browser. We then launch the automated tests pointing to this same persistent data. Since the login is already saved, this allows us to bypass the need to login again when the automated tests are running. The problem is every browser context needs to point to this same persistent profile or at least a copy of it in order to bypass the login. When running the tests in series with I've come up with two work arounds if I am not using I haven't been able to figure out a way to replicate either of the above methods using I don't know the best approach but I'd love to switch to |
@karthikiyengar I just not sure about nice way of implementing this kind of tests. So I just build some small examples. // jest-playwright.config.js
module.exports = {
launchType: "PERSISTENT",
userDataDir: "test",
}
// tests
beforeAll(async () => {
await page.goto('https://jsfiddle.net/')
const sign = await page.$eval('#actions > ul > li:nth-child(2) > a', (el) => el.innerHTML)
if (sign === 'Sign in') {
await page.goto('https://jsfiddle.net/user/login/')
await page.fill('#id_username', 'username');
await page.fill('#id_password', 'password');
await page.click('.buttonCont');
}
})
test('title', async () => {
const title = await page.title()
expect(title).toBe('JSFiddle - Code Playground')
})
test('should display nick', async () => {
await page.goto('https://jsfiddle.net/user/fiddles/all/')
const nick = await page.$eval('#user-top-bar strong', (el) => el.innerHTML)
expect(nick).toContain('username')
})
afterAll(async () => {
await context.close();
}) |
Closed because of inactivity. Feel free to reopen if its still an issue or create a new one. |
Is your feature request related to a problem? Please describe.
In order to test Chrome Extensions (and other persistent use cases), it would be nice if chrome can be launched in persistent mode. Explicitly passing a
userDataDir
to launch results inuserDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead
Describe the solution you'd like
Some way or flag to override https://github.com/playwright-community/jest-playwright/blob/master/src/PlaywrightEnvironment.ts#L32 and use
launchPersistentContext
instead oflaunch
. It can be as simple as the following, although it must be noted that we will no longer comply with playwright's launch options.An alternative would be to create a new option along the lines of
persistentDataDir
.This would allow us to setup a custom environment for extensions like so:
The text was updated successfully, but these errors were encountered: