如何通过playwright_java_src环境变量设置源根目录。

发布于 2025-02-04 17:56:37 字数 1397 浏览 3 评论 0原文

我正在尝试使用Java运行我的第一个剧作家跟踪,并且我要在下面进行错误,我不确定我错过了什么,并且我正在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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪菊怪哟 2025-02-11 17:56:37

为了使剧作家将您的测试源链接到所需的跟踪日志,它需要知道文档中所述的源文件夹的位置在这里

例如,在PowerShell中,您可以这样设置:

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

这将把源添加到跟踪和检查员中。

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

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

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));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文