我正在使用 Webdriver 管理器来实例化我的驱动程序。我正在安装在以 Windows 作为主机的 VirtualBox 中的 Ubuntu 操作系统中的 Chrome 上启动测试用例。但是,最近,当我启动我的测试用例时,它会在 chrome 中打开 url,卡住并给我以下错误:
org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown
error' (500 expected)
org.openqa.selenium.json.JsonException: Expected to read a START_MAP but
instead have: END. Last 0 characters read:
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-
02T20:19:58.91Z'
System info: host: 'DESKTOP-EVVMB8E', ip: 'myIP', os.name:
'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version:
'1.8.0_221'
Driver info: driver.version: RemoteWebDriver
我的测试能够启动浏览器,将其最大化并打开 url。但是它无法发送密钥或与元素进行任何形式的交互。我尝试使用最新版本的 Selenium Webdriver,即 4.0.0 alpha 2,但效果不佳。
//我的POM.xml依赖如下
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.7.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.7.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apiguardian/apiguardian-api -->
<dependency>
<groupId>org.apiguardian</groupId>
<artifactId>apiguardian-api</artifactId>
<version>1.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.7.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.7.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.13.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish/javax.json -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.github.mkolisnyk</groupId>
<artifactId>cucumber-runner</artifactId>
<version>1.3.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
以下是我处理远程 Chrome 驱动程序的方式:
public void handleRemoteWebdriver() throws MalformedURLException {
DesiredCapabilities browser = DesiredCapabilities.chrome();
browser.setCapability("enableVideo", false);
browser.setCapability("enableLog", true);
browser.setCapability("enableVNC", true);
browser.setCapability("version","77.0");
//WebDriverManager.chromedriver().clearPreferences();
//WebDriverManager.chromedriver().setup();
driver = new RemoteWebDriver(new URL("http://domain:4444/wd/hub"), browser);
}
当我在 Windows 本地计算机上的 Chrome 中启动时,测试工作得非常好。因为,我在java自动化方面没有太多经验,请耐心等待我的问题。我只是不明白,我到底错过了什么!