最近想了解下无界面模式下 UI 自动化,试了下 ChromeDriverHeadless,用 testng 启动 chrome 居然用了一分多钟~~ 不知道是什么情况;
源码
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class TestChromeHeadless {
private WebDriver driver;
@Test
public void f() {
driver.get("http://www.baidu.com");
System.out.print(driver.getTitle());
driver.quit();
}
@BeforeClass
public void setupTest() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
//options.addArguments("--disable-gpu");
driver = new ChromeDriver(options);
}
}