-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[Feature] expose @playwright/test runner API #7275
Comments
Is there an example of what this API would look like? I see that you'd like to pass "base URL", so this seems like somewhat deeper integration than just "run tests based on this configuration file". Maybe you could point to your existing integration with jest for us to take a look? |
Jest has quite a lot of extension points, our test integration provides a Jest actually has a configuration value called "testURL" they use in their jsdom test environment, we reused that one and pass it to jest here: https://github.com/bgotink/ngx-playwright/blob/main/packages/jest/src/builder/builder.ts#L54-L64 For If a watch-mode would be added to the test runner, being able to hook into that and rerun the tests when the angular app finishes rebuilding on a change would be nice to have. |
@bgotink Thank you, we'll take a look. |
The addition of the I still think an API would be better in the long run, as it would allow for more interesting integrations. For example, if a watch mode is implemented (#7035) an API could provide a hook to trigger a new run which we could use to re-run tests after every change to the application source. That would be impossible in the child_process approach, as we would have to restart playwright in its entirety and lose the context of the watcher (e.g. if the watcher supports things like jest's interactive UI the state the user selected would be lost) |
Hi, I'm currently trying to write a plugin to use playwright with the playwright runner in an nx monorepo, and having this would make it clean and easier to implement i'd think. I scoured the codebase for awhile but couldn't find anything until reaching this issue |
@ryanbas21 FYI that's my exact use case as well, you might want to take a look at https://github.com/bgotink/ngx-playwright/tree/main/packages/test, even if only as inspiration. |
@dgozman any chance you guys explored this? The playwright runner is just so much faster than using Jest. I'd also love to be able to utilize the |
@ryanbas21 This is on our radar. It opens a quite large API surface, so we are being careful with still working out the balance between the flexibility and long-term commitment. It seems like you'll be fine with I guess you'd like to pass something like |
Hey @dgozman! My use case is very similar to how this person wrote the jest playwright plugin for nx. Ideally, i would either use or write myself an nx plugin which executes my playwright tests in the given I think Right now, all i'd really be doing is spawning a child process and executing So - I want to use my config file on disk, but my configuration can provide some env overrides, like say CI settings may differ from local. Exposing the runner so that I can pass a cli argument to it like --project chromium for CI would also be great. I hope that brain soup helped a bit more. Edit: I understand this is probably not as much of a solution than the above though. |
Can anyone share an example as to how to run playwright test via process? |
@uavdrip you can use shelljs
const shell = require('shelljs')
function runPlayWright() {
shell.exec('npx playwright test')
} |
Thank you, I hope it would work on aws lambda. |
@uavdrip exports.lambdaHandler = async (event, context) => {
const child_process = require('child_process');
try {
const result = child_process.spawnSync('npx', ['playwright', 'test', '__tests__/', '--reporter', 'list', '--config', 'playwright.config.js'], { encoding: 'utf8' });
console.log('Execution Result: \n', result.stdout);
response = {
statusCode: 200,
body: JSON.stringify({ message: result.stdout }),
};
return response;
} catch(err) {
console.log(err);
return err;
}
}; |
Is it possible to run a child process with something like |
I'd like to +1 this as well, we're currently forced to do this via Sample: async function runPlaywright(options: PlaywrightRunOptions): Promise<void> {
// Note that rootDir is relative to location of this file
// It will need to be changed if this is moved elsewhere
const rootDir = path.join(__dirname, '..', '..', '..');
const binPath = path.join(rootDir, 'node_modules', '.bin');
// Append node_modules/.bin path to current path, so we can run `playwright xyz` without prefixing
process.env.PATH += path.delimiter + binPath;
// Append node to current path, playwright has /usr/bin/env node shebang so we need to override
process.env.PATH += path.delimiter + options.nodePath;
const cmd = buildCommand(options, rootDir);
console.log('Running command', cmd);
exec(cmd);
} Logically you could "just expose" the commander program directly and we could call it via |
We would also be very interested in this feature, but from a different perspective: We are dynamically generating test code, and if we could just do something like const playwrightTestGenerator = (input: OurInput) => {
return test.describe("generated", async () => {
const page = ...;
// Some other generated code that checks what we want
})
};
// ------------- This is what we would need
// |
const output = playwrightRunner.run([
playwrightTestGenerator("ourInput"),
playwrightTestGenerator("ourOtherInput")
]); it would solve the problem of having to generate the code for the tests as actual typescript code that we can dump to a file, because we could just dynamically build what we need from within the testcase and our input. Edit: How does the playwright vscode extension do this to run a specific test? |
Being able to run tests simply with something as simple as a |
Hallo. Would it be possible just to export some of the classes / functions. That would give me and my frens enough leeway to run Playwright programatically :) |
Is there any plans to actually expose cli like Jest does with runCli? looking for ways to spawn playwright through code, but it seems I will have to use any updates would be very welcome @dgozman |
I have created a runner , let me know if it will work
|
@dgozman Any news? |
@dgozman, I just came across this thread so thought I would share our use case for something like this. We want our backend developers to be able to run our playwright frontend tests against their backend, without requiring them to learn playwright or typescript or have direct access to our frontend codebase. So we package up all our playwright tests into a docker image and wrote a simple node express REST api that runs on the docker image and binds to some basic playwright functionality. This way the backend develops can, in a language agonstic way, run our tests against arbitrary backends with various configs (including in their CI/CD pipelines as containarized services) Currently the REST api uses child_process to call playwright, which works. But it would be nice to be able to do it programatically. |
We're currently using jest as a test runner for testing angular applications using playwright. In the angular ecosystem tools usually integrate with the
@angular/cli
by providing a builder, so our@ngx-playwright/jest
package is actually what powers theng e2e
command in our repositories.It would be great if we could write such an integration for the
@playwright/test
runner as well, but that'd require access to the runner APIs.While it would be possible to execute the playwright CLI in a new process, this would make certain integrations harder or hacky. For instance passing configuration from the angular.json into the test runner would require turning those into CLI arguments and passing the base URL the angular app is hosted at into the runner would require a workaround using the child process's environment to pass this along.
The text was updated successfully, but these errors were encountered: