playwright java example

Solutions on MaxInterview for playwright java example by the best coders in the world

showing results for - "playwright java example"
Lucia
02 Jun 2018
1import com.microsoft.playwright.*;
2
3import java.nio.file.Paths;
4import java.util.Arrays;
5import java.util.List;
6
7public class PageScreenshot {
8  public static void main(String[] args) {
9    try (Playwright playwright = Playwright.create()) {
10      List<BrowserType> browserTypes = Arrays.asList(
11        playwright.chromium(),
12        playwright.webkit(),
13        playwright.firefox()
14      );
15      for (BrowserType browserType : browserTypes) {
16        try (Browser browser = browserType.launch()) {
17          BrowserContext context = browser.newContext();
18          Page page = context.newPage();
19          page.navigate("http://whatsmyuseragent.org/");
20          page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png")));
21        }
22      }
23    }
24  }
25}
26