我有一个硒/量具自动化项目,并使用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);
}
公共类AppLauncher {
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();
}
}
答案 0 :(得分:0)
您可以替换:
options.addArguments("headless");
使用:
options.addArguments("--headless");