Skip to content

Latest commit

 

History

History
138 lines (108 loc) · 8.81 KB

README.md

File metadata and controls

138 lines (108 loc) · 8.81 KB

Quarkus Playwright


Version License Build

Playwright is an open-source automation library designed for browser testing and web scraping. This extension supports two primary use cases:

  1. Testing: Perform end-to-end tests for your Quarkus web application.
  2. Runtime: Leverage Playwright for screen scraping or other browser tasks in your runtime application, including support for GraalVM native compilation.

All the information you need to use Quarkus Playwright is in the user documentation.

Test Usage

The primary use case for Playwright is integration with @QuarkusTest for end-to-end testing of your application. You can easily create effective cross-browser end-to-end tests for your Quarkus web application using Playwright with frameworks such as Qute, Quinoa, Renarde, Web-Bundler, and MyFaces. Playwright Test was specifically designed to meet the requirements of end-to-end testing. It supports all modern rendering engines, including Chromium, WebKit, and Firefox. You can run tests on Windows, Linux, and macOS—either locally or in CI—both in headless and headed modes, with native mobile emulation for Google Chrome on Android and Mobile Safari.

Just add the dependency as <scope>test</scope> to pom.xml:

<dependency>
    <groupId>io.quarkiverse.playwright</groupId>
    <artifactId>quarkus-playwright</artifactId>
    <version>${playwright.version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-junit5</artifactId>
    <scope>test</scope>
</dependency>

Write your tests:

@QuarkusTest
@WithPlaywright
public class WithDefaultPlaywrightTest {

    @InjectPlaywright
    BrowserContext context;

    @TestHTTPResource("/")
    URL index;

    @Test
    public void testIndex() {
        final Page page = context.newPage();
        Response response = page.navigate(index.toString());
        Assertions.assertEquals("OK", response.statusText());

        page.waitForLoadState();

        String title = page.title();
        Assertions.assertEquals("My Awesome App", title);

        // Make sure the web app is loaded and hits the backend
        final ElementHandle quinoaEl = page.waitForSelector(".toast-body.received");
        String greeting = quinoaEl.innerText();
        Assertions.assertEquals("Hello from RESTEasy Reactive", greeting);
    }
}

Use the annotation @WithPlaywright() to change the browser (Chromium, Firefox, Webkit), headless, enable debug, logs and other options.

Debug your tests with the Playwright inspector @WithPlaywright(debug=true):

Debug

Runtime Usage

Leverage Playwright for screen scraping or other browser tasks in your runtime application, including support for GraalVM native compilation.

Just add the runtime dependency to pom.xml:

<dependency>
    <groupId>io.quarkiverse.playwright</groupId>
    <artifactId>quarkus-playwright</artifactId>
    <version>${playwright.version}</version>
</dependency>

Native

If you plan on running in a Docker image we highly recommend you use a pre-built image from Microsoft mcr.microsoft.com/playwright:v1.48.1 which is based on Ubuntu and already has all libraries and tools necessary for PlayWright.

FROM mcr.microsoft.com/playwright:v1.48.1-noble
WORKDIR /work/
RUN chown 1001:root /work \
    && chmod g+rwX /work \
    && chown 1001:root /work
COPY --chown=1001:root target/*.properties target/*.so /work/
COPY --chown=1001:root target/*-runner /work/application
# Make application executable for all users
RUN chmod ugo+x /work/application
EXPOSE 8080
USER 1001
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Andy Damevin
Andy Damevin

🚧 💻
Melloware
Melloware

🚧 💻
Tomasz Kucharzyk
Tomasz Kucharzyk

⚠️
Greg Stewart
Greg Stewart

🤔
thomaswiradikusuma
thomaswiradikusuma

🤔
Eric Deandrea
Eric Deandrea

🤔
Maxson Araújo
Maxson Araújo

🤔
Loïc Hermann
Loïc Hermann

⚠️
George Gastaldi
George Gastaldi

📖
Holly Cummins
Holly Cummins

📖

This project follows the all-contributors specification. Contributions of any kind welcome!