【问题标题】:How to set source root directory via PLAYWRIGHT_JAVA_SRC environment variable when source collection is enabled启用源收集时如何通过 PLAYWRIGHT_JAVA_SRC 环境变量设置源根目录
【发布时间】:2022-06-13 21:22:09
【问题描述】:

我正在尝试使用 java 运行我的第一个 Playwright 跟踪,但我遇到了错误,我不确定我错过了什么,我正在 Intlij 中运行 mu 代码

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/");

我遇到了错误

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)

【问题讨论】:

    标签: playwright playwright-test playwright-java


    【解决方案1】:

    为了让 Playwright 将您的测试源链接到跟踪日志,它需要知道源文件夹的位置,如文档 here 中所述。

    例如在 Powershell 中你可以这样设置:

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

    这会将源添加到跟踪和检查器中。

    如果您不需要源,您可以在创建上下文实例时禁用它:

    context.tracing().start(new Tracing.StartOptions()
           .setScreenshots(true)
           .setSnapshots(true)
           .setSources(false));
    

    【讨论】:

      猜你喜欢
      • 2023-01-05
      • 1970-01-01
      • 2014-01-26
      • 1970-01-01
      • 2016-04-10
      • 2018-02-08
      • 2015-10-21
      • 1970-01-01
      • 2014-10-09
      相关资源
      最近更新 更多