Record Video in Playwright Java

Profile picture for user arilio666

This article will show how we can record videos using playwright java.

Using the setRecordVideoDir method, we can record videos. While creating the browser context, set the path and size format at that time.

    Playwright playwright = Playwright.create();
        Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
        BrowserContext newContext = browser.newContext(
                new Browser.NewContextOptions().setRecordVideoDir(Paths.get("Videos/")).setRecordVideoSize(1280, 720));
        Page page = newContext.newPage();

        page.navigate("https://www.programsbuzz.com/user/login");

        page.locator("#edit-name").type("Nauto");
        page.locator("#edit-pass").type("Madara");

        newContext.close();
        playwright.close();
  • So here we gave the path as "Videos" this will create the folder and save videos in it.
  • We need to close the context only then; the videos will be saved after recording.
  • We can see here the videos are present inside the Videos folder as we specified.