我是Java测试自动化的新手。当我运行测试时,我收到下面的消息。怎么了?现在谢了。
信息: org.openqa.selenium.remote.DesiredCapabilities铬 信息:在端口33954上使用
new ChromeOptions()比DesiredCapabilities.chrome()启动ChromeDriver 2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90)更好,只允许本地连接。
Java File
import org.junit.Test;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class TestCase {
@Test
public void doTestCase(){
System.setProperty("webdriver.chrome.driver","D:\\Drivers\\Chrome Driver\\chromedriver\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
}
}
Maven File
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.alkan.testautomation</groupId>
<artifactId>JavaTestAutomaiton</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.44.0</version>
</dependency>
</dependencies>
</project>发布于 2020-03-06 05:33:06
您获取的信息是因为您可能使用了DesiredCapabilities。因为,如果您使用ChromeOptions,您不应该获得信息。查看DesiredCapabilities.class包含的内容:
public static DesiredCapabilities chrome() {
LOG.info("Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`");
return new DesiredCapabilities("chrome", "", Platform.ANY);
}DesiredCapabilities类的使用得到Python、Ruby等的支持。虽然它在Java中也是可用的,但它在Java中的使用是不可取的。
相反,我们可以使用ChromeOptions类。Java、Python等都支持这一点。
发布于 2019-01-30 10:35:14
你需要改变如下-
ChromeOptions cap = new ChromeOptions();
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,
UnexpectedAlertBehaviour.IGNORE);
driver = new RemoteWebDriver(new URL("http://hub:4444/wd/hub"),cap);它将修复此问题,并且在执行时不会遇到该日志。
https://stackoverflow.com/questions/53770036
复制相似问题