Hello! 欢迎来到小浪资源网!

Playwright java 无法在隐身窗口中打开浏览器


Playwright java 无法在隐身窗口中打开浏览器

下面的代码有什么遗漏吗?

1)正在分享我使用的代码片段,能够打开 chrome 浏览器,但无法在隐身窗口中打开。
2)我的要求是测试中的应用程序url必须在隐身窗口中打开,完成身份验证并进行测试。但它并没有发生,它总是获取我的 windows sso 凭据并引发未经授权的访问。

注意:我无法共享测试下的应用程序网址,因为该网址将在公司网络内部工作,例如我已经共享了 google.com

launchbrowser.Java

package org.ex.pw;  import com.microsoft.playwright.*;  import java.nio.file.paths; import java.util.arraylist; import java.util.arrays; import java.util.list;  public class launchbrowser {      public static void main(string[] args) throws interruptedexception {         // create a playwright instance         playwright playwright = playwright.create();          // set the path to the chrome driver executable         string executablepath = "c:program filesgooglechromeapplicationchrome.exe";         list browserargs = new arraylist<>(arrays.aslist("--auth-server-allowlist='*'"));        //list browserargs = new arraylist<>(arrays.aslist("--incognito"));          browser browser = playwright.chromium().                 launch(new browsertype                         .launchoptions()                         .setexecutablepath(paths.get(executablepath))                         .setargs(browserargs)                         .setheadless(false));         browsercontext context = browser.newcontext();           // create a new page         page page = context.newpage();         // open a web page        page.navigate("https://www.google.com");         final string pagetitle = page.title();         system.out.println("pagetitle="+pagetitle);         thread.sleep(25000);         context.close();         // close the browser         browser.close();         // close the playwright instance         playwright.close();     } } 

build.gradle

plugins {   id 'java' }  group 'org.ex.pw' version '1.0-SNAPSHOT'  repositories {   mavenCentral() }  dependencies {   testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'   testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'   implementation 'com.microsoft.playwright:playwright:1.44.0' }  test {   useJUnitPlatform() } 

相关阅读