1

I'm trying to run my first Playwright trace using java and i'm getting below error, I'm not sure what i'm missing out and I'm running mu code in Intlij

Playwright playwright = Playwright.create();
        Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false));
        BrowserContext browserContext = browser.newContext();
        browserContext.tracing().start(new Tracing.StartOptions().setScreenshots(true).setSnapshots(true).setSources(true));
        Page page = browser.newPage();
        page.navigate("https://www.saucedemo.com/");

I'm getting below error

Exception in thread "main" com.microsoft.playwright.PlaywrightException: Source root directory must be specified via PLAYWRIGHT_JAVA_SRC environment variable when source collection is enabled
    at com.microsoft.playwright.impl.TracingImpl.startImpl(TracingImpl.java:95)
    at com.microsoft.playwright.impl.TracingImpl.lambda$start$0(TracingImpl.java:69)
    at com.microsoft.playwright.impl.LoggingSupport.lambda$withLogging$0(LoggingSupport.java:36)
    at com.microsoft.playwright.impl.LoggingSupport.withLogging(LoggingSupport.java:47)
    at com.microsoft.playwright.impl.ChannelOwner.withLogging(ChannelOwner.java:79)
    at com.microsoft.playwright.impl.LoggingSupport.withLogging(LoggingSupport.java:35)
    at com.microsoft.playwright.impl.TracingImpl.start(TracingImpl.java:69)
    at Sample.main(Sample.java:12)
Deepak_Mahalingam
  • 454
  • 1
  • 9
  • 21

1 Answers1

2

For Playwright to link your test sources to the trace log it needs to know the location of the source folder as described in the documentation here.

For example in Powershell you can set it like this:

$env:PLAYWRIGHT_JAVA_SRC="src/test/java"

This will add the sources to the trace and to the Inspector.

If you do not need the sources, you can just disable it when you create the context instance:

context.tracing().start(new Tracing.StartOptions()
       .setScreenshots(true)
       .setSnapshots(true)
       .setSources(false));
Itai Agmon
  • 1,417
  • 13
  • 12