为什么Selenium网络驱动程序不能在远程机器上最大化chrome



当我在本地机器上运行测试时,它正在工作,但远程机器没有最大化chrome。由于这个驱动程序在屏幕上找不到元素,所有测试都失败了。我已经尝试了所有推荐的解决方案。这是我的密码。

公共类BrowserFactory扩展BaseTest{

public WebDriver prepareDriver() {
WebDriver driver;
if (getAveaConfiguration().isRemote().booleanValue()) {
driver = getRemoteDriver();
//driver.manage().window().maximize();
Dimension d = new Dimension(1936,1056);
driver.manage().window().setSize(d);
System.out.println("PageSize:" + driver.manage().window().getSize());
} else {
driver = getLocalDriver();
driver.manage().window().maximize();
System.out.println(driver.manage().window().getSize());
}
return driver;
}
private WebDriver getRemoteDriver() {
WebDriver webDriver;
DesiredCapabilities cap = getRemoteCapabilities();
try {
System.out.println(getAveaConfiguration().getGridURL());
webDriver = new RemoteWebDriver(new URL(getAveaConfiguration().getGridURL()), cap);
((RemoteWebDriver) webDriver).setFileDetector(new LocalFileDetector());
} catch (MalformedURLException mue) {
throw new TestException(mue);
}
return webDriver;
}
private DesiredCapabilities getRemoteCapabilities() {
DesiredCapabilities capabilities;
if ("firefox".equals(getAveaConfiguration().getBrowser())) {
capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
profile.setPreference("browser.privatebrowsing.autostart", true);
profile.setPreference("network.proxy.type", 0);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
return capabilities;
} else if ("ie".equals(getAveaConfiguration().getBrowser())) {
return DesiredCapabilities.internetExplorer();
} else {
capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
options.addArguments("enable-automation");
options.addArguments("--headless");
options.addArguments("--window-size=1920,1080");
options.addArguments("--no-sandbox");
options.addArguments("--disable-extensions");
options.addArguments("--dns-prefetch-disable");
options.addArguments("--disable-infobars");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-browser-side-navigation");
options.addArguments("enable-features=NetworkServiceInProcess");
options.addArguments("--disable-gpu");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
return capabilities;
}
}
private WebDriver getLocalDriver() {
switch (getAveaConfiguration().getBrowser()) {
case "chrome":
return new ChromeDriver();

//case";即"://返回新的InternetExplorerDriver(getCapabilitiesForIe(((;默认值:返回new ChromeDriver((;}}

我解决了我的问题,但忘记结束我的问题。问题是有人将谷歌chrome文件移到了另一个路径。重新安装镀铬,问题得到解决。

相关内容

  • 没有找到相关文章

最新更新