`new ChromeOptions()`比`DesiredCapabilities.chrome()`更受欢迎。

5

我是Java测试自动化的新手。当我运行我的测试时,收到下面的消息。

请问这是怎么回事?谢谢。

消息:org.openqa.selenium.remote.DesiredCapabilities chrome

INFO:使用new ChromeOptions()优于DesiredCapabilities.chrome()

启动ChromeDriver 2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),端口33954。只允许本地连接。

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>

这只是一条警告而已吗?你的测试受到影响了吗?如果你正在寻找解决方案,请参考以下链接:https://dev59.com/KKfja4cB1Zd3GeqPyJnl, https://dev59.com/WlYN5IYBdhLWcg3w27Yv, https://dev59.com/WlYN5IYBdhLWcg3w27Yv. - Mate Mrše
2个回答

3
你获取的信息是因为你可能使用了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等语言中均得到支持。

参考资料: https://chromedriver.chromium.org/capabilities


0

您需要进行以下更改 -

ChromeOptions cap = new ChromeOptions(); 
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,
                  UnexpectedAlertBehaviour.IGNORE);

driver = new RemoteWebDriver(new URL("http://hub:4444/wd/hub"),cap);

这将修复问题,您在执行过程中将不会遇到该日志


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接