-
Notifications
You must be signed in to change notification settings - Fork 210
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]: Add Gradle examples to documentation #571
Comments
It'd be nice to have one! If anyone who uses Gradle is willing to contribute such an example we'd appreciate that. |
I am using gradle so I could try to reproduce all the examples, and then contribute them. |
It turns out that Gradle doesn't have a direct equivalent of Maven's Because that requires a bit more description instead of just a "run this line" instruction, how would you like to integrate the gradle instructions into the doc? Example of a task that needs to be added to task runPlaywrightCli(type: JavaExec) {
mainClass = 'com.microsoft.playwright.CLI'
classpath sourceSets.main.runtimeClasspath
args 'open'
} Which can then be run with Also, gradle files can be written in Groovy (the original way) or in Kotlin (newer way which is pretty popular for new projects I think). How do you want to deal with this? I have only a Groovy setup, so couldn't easily test the Kotlin code. |
|
I thought you were originally talking about just gradle config for adding playwright deps but now I see that you are talking about all the cli examples. In that case I believe we'll need something like TypeScript/JavaScript tabs (see e.g. this page) but for the two build systems Maven/Gradle. As for the task definition I'd like the command line to be as close as possible to the node.js one. For example if it's
in nodejs it'd be nice to map it to something as concise as
in a Gradle project. Would that be possible? As for the syntax preference we could provide the snippet in both Groovy and Kotlin similar to how Gradle docs do it. If not, I'd stay with more conservative option of Groovy as I'd expect clients that write their scripts in Kotlin to know how to translate Groovy to Kotlin. You probably know this already but just in case, our docs live in the upstream repo and then we roll it periodically to playwright.dev to update it so these changes would need to go the playwright repo. |
There are some neat setups on Gradle website that toggle between Groovy and Kotlin formats. Could that be implemented? |
I think maybe you can get away with including the plugins {
application
kotlin("jvm") version "1.5.0"
}
application {
mainClass.set("com.microsoft.playwright.CLI")
} ...and then running this, but I could be wrong:
update: |
Should be possible and I think this is the way to go.
I like how concise the command line is in that case, but I'm concerned that it may get in conflict with the actual "application" in the project. Perhaps it's not an issue (I'm not familiar enough with Gradle)? |
@yury-s I am able to run tests locally using Playwright with a similar gradle setup. What would be the best way to test this? |
Yeah I would not use the The best that I could come up with would be called something like this example command:
and this is the setup:
|
The application is actually the framework the user is wrapping around Playwright, and as I mentioned, this does not conflict. I was able to use exactly what I said locally in my own project. So I don't see the issue, but whatever is the best for the general user is going to be the right one, and that may not be mine 😆 |
Not sure if we are maybe misunderstanding each other. I thought (but haven't actually checked) that if a project already uses the application plugin for its own purpose, you can't add another application for playwright. If your project doesn't use the application, then sure it will work. |
This approach is working well! |
Glad it is working for you. @yury-s @jhyot would it be worth it to add this approach as an alternative much like the suggestion at the end of the linked #864 ? @jhyot I am not sure what you mean. Basically your local framwork is an application that is leveraging the playwright CLI is what is happening if I am not mistaken. |
@ddaypunk For that reason, I don't recommend documenting the I don't mind if the But also, I would guess that because of the types of applications that are most interested in using Playwright (web apps), by far the majority of apps don't use the |
@jhyot If I can get to it, I would love to. Some interesting developments at work today, so I may not get to it for a bit. |
So i was looking to add this to the documentation, but the given example in the comment seems to only work with single-word commands?
|
Actually, as I found out, the So this should work:
And run like this: That should also fix the multiple-args problem as noticed by @eneller. |
Hey @ddaypunk , this works. Can you share an example on how it can be converted to a Gradle kotlin DSL task so that we can run the codegen when we do say ./gradlew codegen --args="open google.com" ? Essentially say we do not want to modify the main application run cli option , as We want the application to execute when We do gradlew run ,We would instead like to add a new task for trigger codegen. |
FYI Kotlin is now the default for Gradle build files. https://blog.gradle.org/kotlin-dsl-is-now-the-default-for-new-gradle-builds |
If I am not mistaken, they are trying to avoid using the application plugin? A few previous comments shows using a task which is already in Kotlin DSL. |
@parthasarma87 check my comment: #571 (comment) It is in Groovy, but I think you can find out what the syntax in Kotlin is (I don't know). The key is to create the new task as type |
First things first. I've made a branch with the changes suggested on the intro page for install Shall we add Kotlin ? Kotlin only ? Next step will be to add the alternatives to Playwright commands. For example : |
Thanks for getting this started @jfgreffier. I would support adding Kotlin as well, Groovy is so common that I think having both would be useful. Here is the Kotlin code I have used for a project. Feel free to include it in your commit, or I can add one later if you choose not to add it.
|
Thanks @ardetrick I've updated my branch accordingly and created a PR. I only documented CLI usage with Gradle in the installation page; I feel it's very redondant to add it next to each Maven example. I'm opened to suggestions or co-authoring the PR |
I don't have much context on the rest of the example, but the gradle kotlin task looks good to me. thanks for adding it! |
Docs update to install Playwright as a dependency with Gradle, also introduce how to run Playwright CLI ```bash ./gradlew playwright --args="help" ``` Fixes [#571](microsoft/playwright-java#571)
Docs update to install Playwright as a dependency with Gradle, also introduce how to run Playwright CLI ```bash ./gradlew playwright --args="help" ``` Fixes [microsoft#571](microsoft/playwright-java#571)
Feature request
Is it possible to add Gradle examples to the Playwright documentation along the current Maven ones?
The text was updated successfully, but these errors were encountered: