-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Easier debugging / test-specific configurations #216
Comments
@jhildenbiddle thank you for your suggestion. Seems like that it can be very helpful. I'll take it |
Excellent! Thanks for considering the change, @mmarkelov. |
@jhildenbiddle just look through this issue and made #233 test('test1', async () => {
await jestPlaywright.config({
browser: 'chromium',
launchType: "LAUNCH",
launchOptions: {
headless: false,
devtools: true,
}
}, async ({page}) => {
// page is coming from function params
await page.goto('https://github.com/')
const title = await page.title()
expect(title).toBe('Google')
})
}) So you can config playwright only inside the specific test. Personally I don't think that it's perfect decision, I just tried some another opportunities, like using Also I don't know how we should config it, should we merge passing options with existing? |
@jhildenbiddle also we just discussed some another ways to implement this feature with @mxschmitt // tests:
describe('Simple tests', () => {
beforeAll(async () => {
await page.goto('https://google.com/')
})
test('passed', async () => {
const title = await page.title()
await expect(title).toBe('Google')
})
test('failed', async () => {
const title = await page.title()
await expect(title).toBe('')
})
afterAll(async () => {
await page.close()
});
}) So you got one failed test for After it you can run only failed test with
So launchOptions: {
headless: false,
devtools: true,
} So you will be able to also run tests for failed describe block for example. But you couldn't pass another playwright options with your CLI, I suppose it won't be critical |
First, thank you @mmarkelov for your efforts. They are very much appreciated. Whatever we end up with, having the ability to modify configurations for describe and test blocks will be extremely helpful. Both of the proposed implementations (new method & CLI option) are interesting because they serve different purposes: the Implementation 1 test('test1', async () => {
await jestPlaywright.config({
// ...
}, async ({page}) => {
// ...
})
}); This is essentially what I was hoping for. While it may be limited to single test blocks only, I still think this is approach has value because it allows me to run my tests in watch+headless mode, have a test fail, wrap the failed test in the code described above, then have access to a browser with dev tools ready for debugging. I didn't have to stop my watch task or deal with browser windows for every test after changing my main configuration. After I fix the test I just remove the As stated in the first comment though, I'd want to reuse a debug configuration automatically and simplify the code I need to wrap my tests with using a separate method. Passing a config is still useful in other scenarios though (like trying a different screen size or specifying a browser), so I can see value in both // Default debug configuration (stored in jest-playwright settings)
test('test1', async () => {
await jestPlaywright.debug(async ({page}) => {
// ...
})
});
// Debug configuration with `browser` override
test('test2', async () => {
await jestPlaywright.config({ browser: 'webkit' }, async ({page}) => {
// ...
})
});
// Regular configuration with `browser` override
test('test2', async () => {
await jestPlaywright.config({ browser: 'chromium' }, async ({page}) => {
// ...
})
}); Other thoughts:
Implementation 2 DEBUG=true BROWSER=chromium jest -t 'failed' I would use this functionality to create VSCode debug scripts which already contain both the file context and (when selected) the describe/test name context, allowing me to click a button in VSCode to debug the current file or describe/test block without touching the CLI: // .vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug current test file",
"env": {
"DEBUG": "true",
"BROWSER": "chromium"
},
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"test:jest"
],
"args": [
"--",
"-i",
"${relativeFile}",
],
"console": "integratedTerminal"
},
{
"type": "node",
"request": "launch",
"name": "Debug selected test name",
"env": {
"DEBUG": "true",
"BROWSER": "chromium"
},
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"test:jest"
],
"args": [
"--",
"-i",
"${relativeFile}",
"-t",
"${selectedText}"
],
"console": "integratedTerminal"
}
]
} Obviously this hasn't been tested, but I don't see why it wouldn't work. A few additional thoughts:
Apologies for the lengthy post. Hope some of this is helpful. :) |
Because if it shared the same My guess is that may not be possible without some OS-specific hacking beyond the current capabilities. The easy solution is to make a new non-headless browser instance, and give you that
An API like that would be much more ergonomic! I'd say make it just |
@jhildenbiddle thank you for your comment. I think that we can start from the first implementation. It's almost done. // Default debug configuration
test('test1', async () => {
await jestPlaywright.debug(async ({page}) => {
// ...
})
});
// Configuration will be used from the first argument
test('test2', async () => {
await jestPlaywright.config({ ...options }, async ({page}) => {
// ...
})
});
Yeah, I agree that it will be much cleaner. But I'm not sure that it's possible to override If we are talking about CLI implementation is about your playwright configuration. So you will be able to use just custom debug options. But I think that it will be possible to use // jest-playwright.config.js
module.exports = {
...,
debugOptions: { ... }
}
Yeah, sure! So to sum up, I will work on the first implementation. It will have two helper functions config and debug. For now you should use them inside |
Excellent! I'm happy to test an in-progress branch before release if you'd like. Thank you for all the hard work. Much appreciated. |
@jhildenbiddle I just find out the way to extend global // Defaults debug configuration
test.jestPlaywrightDebug('test1', async () => {
// ...
});
// Modified standard configuration
test.jestPlaywrightConfig({ /* ... */ }, 'test2', async () => {
// ...
}); I hope that we can merge the first version of it soon. But it will be a bit unstable - I need to implement some checks on these helpers and also I should check if |
@jhildenbiddle And also I need to find out the way to run these kind of test only once if the // jest-playwright.config.js
module.exports = {
...,
browsers: ['chromium', 'firefox'],
}
// test
// This test should run only once
test.jestPlaywrightConfig({ browser: 'chromium' }, 'test2', async () => {
// ...
}); |
@jhildenbiddle just published new pre-release version. You can try jest-playwright-preset@next to use this helper functions. Also I suppose that we can simplify this two functions in one. Like this: // Will use some custom debug options
test.jestPlaywrightDebug('test2', async () => {
// ...
});
// Will use custom debug options and passed options
test.jestPlaywrightDebug({ ...options }, 'test2', async () => {
// ...
}); |
@mmarkelov -- That's great. I'll check out the prerelease as soon as possible and post feedback here. In the meantime, a few thoughts...
I'm not sure which two functions your referring to, but if you're referring to // DEBUG without configuration object uses `debugOptions` config
test.jestPlaywrightDebug('test1', async () => {
// ...
});
// DEBUG with configuration object merges (overrides) options with `debugOptions` config
test.jestPlaywrightDebug({ /* ... */ }, 'test2', async () => {
// ...
});
// CONFIG must pass a configuration object and merges (overrides) options with primary config
test.jestPlaywrightConfig({ /* ... */ }, 'test3', async () => {
// ...
}); Another thing to consider when extending // Run specific test(s) only
test.jestPlaywrightDebug.only('test1', async () => {
// ...
});
// Skip specific test(s)
test.jestPlaywrightConfig.skip({ /* ... */ }, 'test2', async () => {
// ...
}); If these methods cannot be added to the // Run specific test(s) only
test.jestPlaywrightDebug({ only: true }, 'test1', async () => {
// ...
});
// Skip specific test(s)
test.jestPlaywrightConfig({ skip: true }, 'test2', async () => {
// ...
}); This is less than ideal because it presents a new method of isolating and skipping tests. Better to offer |
@jhildenbiddle thank for getting back.
I also will take it in, and try to implement it in next PRs |
@jhildenbiddle I'm not sure that I can understand what we need to do for this cases |
@mmarkelov -- Consider how devs are able to run or skip selected tests using As stated above, ideally both the // Run specific test(s) only
test.jestPlaywrightDebug.only('test1', async () => {
// ...
});
// Skip specific test(s)
test.jestPlaywrightConfig.skip({ /* ... */ }, 'test2', async () => {
// ...
}); This would require adding custom Hope that helps explain a bit better. |
@jhildenbiddle just added this ability in next release |
@mmarkelov. Amazing. Looking forward to checking it out. I've been busy setting up and configuring As always, thanks for your efforts and the quick turnaround! |
@mmarkelov -- Just gave
|
@jhildenbiddle thank you for your feedback!
There is some problems with it right now. test.jestPlaywrightConfig(
{
browsers: ['chromium'],
launchType: 'LAUNCH',
launchOptions: { headless: false },
},
'test name',
async () => {
/* ... */
}
);
This should work. I added it in rc9 test.jestPlaywrightConfig.skip({
/* your options here */
}, 'failed', async ({page}) => {
await page.goto('https://github.com/')
const title = await page.title()
await expect(title).toBe('Google')
})
It's using this config: const DEBUG_OPTIONS = {
launchType: 'LAUNCH',
launchOptions: {
headless: false,
devtools: true,
},
}
You should use test.jestPlaywrightDebug('failed', async ({page}) => {
await page.goto('https://github.com/')
const title = await page.title()
await expect(title).toBe('Google')
})
I'll check it
Yeah! There is no implementation to support
This is expected behavior. Is it wrong?
I will take a look |
@mmarkelov, @jhildenbiddle Saying that, implementing most of the API presented here is a bit overkill to me. Let me explain how could one address the actual issue in the OP. Instead of keeping all of your test run parameters in {
"APP_PROTOCOL": "http:",
"APP_HOST": "app.in.test",
"APP_PATH": "app/client",
"SLOW_MO": 0,
"VIEWPORT": "1920x1080",
"HEADLESS": true,
"SCREEN_FAILED_TESTS": true,
"DEFAULT_TIMEOUT": 600,
"RETRY_TIMES": 3,
"TYPING_DELAY": 0,
"BROWSERS": "chromium,firefox,webkit",
"DEVICES": "",
"TEST_NAME_PATTERN": ""
} And you can read that JSON in your const defaults = require('./tests.config.json');
// push config variables to env
Object.keys(defaults).forEach(key => {
if (!process.env[key]) {
process.env[key] = defaults[key];
}
});
// here you consume your env vars, something like
const [width, height] = (process.env.VIEWPORT || '1920x1080').split('x').map(v => +v);
module.exports = {
launchOptions: {
headless: process.env.HEADLESS === 'true',
slowMo: +process.env.SLOW_MO
},
contextOptions: {
ignoreHTTPSErrors: true,
bypassCSP: true,
viewport: {
width,
height
}
},
browsers: process.env.BROWSERS ? process.env.BROWSERS.split(',') : ['chromium'],
devices: process.env.DEVICES ? process.env.DEVICES.split(',') : []
}; This approach gives you an ability to set env vars for you particular test run, and run your tests with no code modification.
So far I made zero changes to run my particular test with particular parameters. And you can parametrize your setup up to your needs. Again, if you want to skip a test - can't you use Jest's And in order to inject a breakpoint, since you mentioned VSCode - it has super nice JavaScript Debug Terminal, which attaches to any Node code/process, and you can place your breakpoints directly in your test sources. No need for explicit What do you think? |
Is your feature request related to a problem? Please describe.
I typically run all tests headless, but I often have failing tests that that require visually inspecting the page. Currently, this involves the following:
jest-playwright.config.js
filebrowsers
to include only one browser (since I generally don't need to visually inspect in multiple browsers)launchOptions
to setheadless:false
and occasionallydevtools:true
Once the test passes, I then have to undo all of the changes made above.
What would greatly speed up this process is a way to launch a single test in non-headless mode, possibly with devtools enabled, for one-or-more browsers and/or devices. Ideally, this would be as quick as adding
.only
or.skip
to a test, although this would obviously take some pre-configuration.Describe the solution you'd like
The verbose-but-flexible way would be to allow passing configuration options with each test. Using the existing
jestPlaywright.skip
implementation as inspiration, perhaps something like this could work:This could be made less obnoxious by storing the non-headless/debug configuration separately and passing it to the
.config()
method:Better yet, the non-headless/debug configuration could be set in
jest-playwright.config.js
, allowing a much simpler.debug()
method to be used without passing additional parameters:The text was updated successfully, but these errors were encountered: