我已经使用chromedriver在硒webdriver中运行自动化测试,并且我正在使用
MacOS,Chrome版本83,硒版本3.141.59和TestNG 7.1.0。如果我缺少什么,请告诉我。
〜
公共类ChromeDrive扩展了Base实现DriverLoader {
@Override
public WebDriver load() {
try {
ChromeOptions options = new ChromeOptions();
setArguments(options);
driver.set(new ChromeDriver(options));
Dimension targetSize = new Dimension(1500, 1000); //your screen resolution here
driver.get().manage().window().setSize(targetSize);
} catch (Exception e) {
throw new RuntimeException("Please check Browser is exist Browser Unable to start");
}
return driver.get();
}
@Override
public WebDriver loadParallel() {
try {
ChromeOptions options = new ChromeOptions();
DesiredCapabilities capabilities = new DesiredCapabilities();
setArguments(options);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");
capabilities.setCapability("name", currentTestName);
if (ReadData("isRemote").equalsIgnoreCase("true")) {
String hubUrl = "http://192.168.3.2:4444/wd/hub";
driver.set(new RemoteWebDriver(new URL(hubUrl), capabilities));
} else {
driver.set(new ChromeDriver(options));
}
} catch (Exception e) {
throw new RuntimeException("Please check Browser is exist Browser Unable to start" + e);
}
Dimension targetSize = new Dimension(1500, 1000); //your screen resolution here
driver.get().manage().window().setSize(targetSize);
return driver.get();
}
private void setArguments(ChromeOptions options) {
boolean isUnix = setChromeBrowser(OsValidator.getDeviceOs());
isUnix(options, isUnix);
Map<String, Object> prefs = new HashMap<>();
prefs.put("profile.default_content_setting_values.notifications", 2);
options.setPageLoadStrategy(PageLoadStrategy.NONE);
options.addArguments("--no-sandbox");
options.addArguments("--start-maximized");
//options.addArguments("--always-authorize-plugins");
//options.addArguments("enable-automation");
options.addArguments("--disable-web-security");
options.addArguments("-incognito");
options.setExperimentalOption("prefs", prefs);
options.addArguments("--allow-running-insecure-content");
}
private void isUnix(ChromeOptions options, boolean isUnix) {
if (isUnix) {
options.addArguments("--headless");
}
}
最佳答案
你没有告诉他网址
driver.get("https://stackoverflow.com/");