playwright-java icon indicating copy to clipboard operation
playwright-java copied to clipboard

Not able to set PLAYWRIGHT_JAVA_SRC environment variable through Playwright.CreateOptions().setEnv(env);

Open Rabindra184 opened this issue 4 years ago • 1 comments

Context:

  • Playwright Version: 1.23
  • Operating System: Mac
  • Browser: [e.g. All, Chromium, Firefox, WebKit]
  • Extra: [any specific details about your environment]

Code Snippet

package org;

import com.microsoft.playwright.*; import java.nio.file.Paths; import java.util.Map; import static org.Util.mapOf;

public class TraceGenerator {

private static final String SRC_DIRS = System.getenv("PLAYWRIGHT_JAVA_SRC") == null ? "src/test/java" : System.getenv("PLAYWRIGHT_JAVA_SRC"); public static void main(String[] args) {

    Map<String, String> env = mapOf("PLAYWRIGHT_JAVA_SRC", SRC_DIRS);
    Playwright.CreateOptions options =new Playwright.CreateOptions().setEnv(env);
    Playwright playwright = Playwright.create(options);
    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 = browserContext.newPage();
    page.navigate("https://playwright.dev/java/docs/api/class-playwright#playwright-create");
    
    // Stop tracing and export it into a zip archive.
    browserContext.tracing().stop(new Tracing.StopOptions()
            .setPath(Paths.get("trace.zip")));
    playwright.close();
}

}

Describe the bug

Here I am getting the below exception. 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:94) at com.microsoft.playwright.impl.TracingImpl.lambda$start$0(TracingImpl.java:68) 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:68) at org.TraceGenerator.main(TraceGenerator.java:22)

Add any other details about the problem here.

Rabindra184 avatar Jul 19 '22 04:07 Rabindra184

It's the same request as https://github.com/microsoft/playwright-java/issues/965 which was fixed in https://github.com/microsoft/playwright-java/pull/980 and will be available in v1.24 in the next few days.

yury-s avatar Jul 25 '22 20:07 yury-s