如何在启用源代码收集时通过PLAYWRIGHT_JAVA_SRC环境变量设置Playwright源代码根目录-如何为Linux设置

inkz8wg9  于 2023-01-07  发布在  Java
关注(0)|答案(1)|浏览(188)

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

final Browser.NewContextOptions browserContextOptions = new Browser.NewContextOptions().setIgnoreHTTPSErrors(true).setViewportSize(width,height);
        context = browser.newContext(browserContextOptions);
        //context = browser.newContext(new Browser.NewContextOptions().setViewportSize(width, height));

        // Start tracing before creating / navigating a page.
        context.tracing().start(new Tracing.StartOptions()
                .setScreenshots(true)
                .setSnapshots(true)
                .setSources(true));
        page = context.newPage();

I am getting the following error
[RemoteTestNG] detected TestNG version 7.4.0 FAILED CONFIGURATION: @BeforeMethod doLaunchBrowser 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:85) at com.microsoft.playwright.impl.LoggingSupport.withLogging(LoggingSupport.java:35) at com.microsoft.playwright.impl.TracingImpl.start(TracingImpl.java:68) at com.united_arab_bank.base.BasePage.doLaunchBrowser(BasePage.java:91) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133) at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62) at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385) at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321) at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:700) at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527) at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173) at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46) at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824) at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at org.testng.TestRunner.privateRun(TestRunner.java:794) at org.testng.TestRunner.run(TestRunner.java:596) at org.testng.SuiteRunner.runTest(SuiteRunner.java:377) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332) at org.testng.SuiteRunner.run(SuiteRunner.java:276) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212) at org.testng.TestNG.runSuitesLocally(TestNG.java:1134) at org.testng.TestNG.runSuites(TestNG.java:1063) at org.testng.TestNG.run(TestNG.java:1031) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

xyhw6mcr

xyhw6mcr1#

我在macOS上遇到了同样的问题。
仅适用于mac,将以下行添加到~/.zshrc文件。
export PLAYWRIGHT_JAVA_SRC=/usr/libexec/java_home
不要忘记关闭当前的终端并打开一个新的,以便读取更新的env变量。

相关问题