Why such setup does not record anything for Trace Viewer Playwright? I'm trying to record files for Playwright Trace Viewer but after running:
mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="show-trace trace.zip"
trace is empty. Am I doing something wrong? This is an example test setup which I'm using:
public class TestSearchPage {
static Playwright playwright;
static Browser browser;
BrowserContext context;
@BeforeAll
static void launchBrowser() {
playwright = Playwright.create();
browser = playwright.chromium().launch(new BrowserType.LaunchOptions()
.setHeadless(false)
.setSlowMo(500));
}
@AfterAll
static void closeBrowser() {
playwright.close();
}
@BeforeEach
void createContextAndPage() {
context = browser.newContext();
context.tracing().start(new Tracing.StartOptions()
.setScreenshots(true)
.setSnapshots(true)
.setSources(true)
);
//page = context.newPage();
}
@AfterEach
void closeContext() {
context.tracing().stop(new Tracing.StopOptions()
.setPath(Paths.get("trace.zip")));
context.close();
}
@Test
void shouldSearch() throws InterruptedException {
Page page = browser.newPage();
SearchPage searchPage = new SearchPage(page);
searchPage.navigate();
...
}
}
I made a mistake: instead of browser.newPage() should be
Page page = context.newPage();
...