In this blog, you will gain knowledge on how to launch various browsers such as Chromium, Mozilla Firefox, Webkit, Chrome, and Microsoft Edge using Playwright-Java.
Topics that we will cover:
- Launch chromium browser (in header mode) using playwright
- Launch firefox browser using playwright
- Launch webkit browser using playwright
- Launch chrome browser using playwright
- Launch Microsoft Edge browser using playwright
- Source code (chromium, firefox, webkit)
- Source code (chrome, edge)
Launch chromium browser (in header mode) using playwright
By default, the playwright test runs in headless mode. In our previous blog, we executed a playwright test and the snapshot of the results is provided below. It is worth mentioning that the chromium browser was NOT launched during the execution of the test

To launch the browser, the test needs to be executed in header mode.
To activate the header mode, simply include the highlighted argument in the launch() method, as depicted below:
launch(new BrowserType.LaunchOptions().setHeadless(false))

Launch firefox browser using playwright
In order to launch firefox browser, simply comment line#14 and add line#15

Launch webkit browser using playwright
To launch webkit browser, see line#16

Launch chrome browser using playwright
In order to start the Chrome browser, all we need to do is instantiate an object of the 'LaunchOptions' class, specify the channel as 'chrome', and ensure that the headless mode is set to false (see lines#15-17).
Also, let us uncomment line#19 and comment line#21

Execute the code, notice that the chrome browser launches

Execute the code, notice that the edge browser gets launched

So this is how we can launch various browser types.
Source code (chromium, firefox, webkit)
package com.rsa.playwrightjava;
import org.junit.jupiter.api.Test;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
public class Blog3_launchChromiumFFWebkit {
@Test
public void PlaywrightJTest() {
Playwright pt = Playwright.create();
//BrowserType btype = pt.chromium();
//BrowserType btype = pt.firefox();
BrowserType btype = pt.webkit();
Browser b = btype.launch((new BrowserType.LaunchOptions().setHeadless(false)));
//Page pg = pt.chromium().launch().newPage();
Page pg = b.newPage();
pg.navigate("https://www.google.com/");
System.out.println(pg.title());
}
}
Source code (chrome, edge)
package com.rsa.playwrightjava;
import org.junit.jupiter.api.Test;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.BrowserType.LaunchOptions;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
public class Blog3_launchChromiumFFWebkit {
@Test
public void PlaywrightJTest() {
Playwright pt = Playwright.create();
LaunchOptions lo = new LaunchOptions();
//lo.setChannel("chrome");
lo.setChannel("msedge");
lo.setHeadless(false);
BrowserType btype = pt.chromium();
//BrowserType btype = pt.firefox();
//BrowserType btype = pt.webkit();
Browser b = btype.launch((new BrowserType.LaunchOptions().setHeadless(false)));
//Page pg = pt.chromium().launch().newPage();
Page pg = b.newPage();
pg.navigate("https://www.google.com/");
System.out.println(pg.title());
}
}
Thanks!