我有一个硒/仪表自动化项目,并使用Java进行代码。但是,在我的驾驶员工厂,我将它设置为无头。当我运行它时,出于某种原因将启动一个空的Chrome窗口。我该如何停止启动此窗口?
公共静态Webdriver getDriver(({
String browser = System.getenv("BROWSER");
if (browser == null) {
WebDriverManager.chromedriver().setup();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setJavascriptEnabled(true);
ChromeOptions options = new ChromeOptions();
options.addArguments("chrome.switches","disable-extensions", "ignore-certificate-errors", "no-sandbox");
options.addArguments("--disable-popup-blocking"); //Global driver.switchTo().alert().accept();
options.addArguments("start-maximized");
options.addArguments("headless");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return new ChromeDriver(capabilities);
}
公共类Pallauncher {
public static String APP_URL = System.getenv("APP_URL");
@Step("Launch Qualitrac")
public void launchQualitrac() {
webDriver.get(AppLauncherObjects.getMapPageNames().get("Qualitrac"));
assertEquals("Qualitrac", webDriver.getTitle());
}
}
公共类驱动程序{
// Holds the WebDriver instance
public static WebDriver webDriver;
public static HashMap globalStash;
// Initialize a webDriver instance of required browser
// Since this does not have a significance in the application's business domain, the BeforeSuite hook is used to instantiate the webDriver
@BeforeSuite
public void initializeDriver() {
webDriver = DriverFactory.getDriver();
webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
globalStash = new HashMap<String,String>();
}
// Close the webDriver instance
@AfterSuite
public void closeDriver(){
webDriver.quit();
}
}
您可以替换:
options.addArguments("headless");
with:
options.addArguments("--headless");