【问题标题】:Selenium chrome driver error java.lang.AbstractMethodError: Receiver class org.openqa.selenium.chrome.ChromeDriverService$Builder does not defineSelenium chrome 驱动程序错误 java.lang.AbstractMethodError: Receiver class org.openqa.selenium.chrome.ChromeDriverService$Builder 未定义
【发布时间】:2022-01-03 11:54:14
【问题描述】:

在弄乱某些东西之前,我运行它没有问题。

任何帮助都会被应用。

在使用 chrome 驱动程序运行任何测试类时,我收到此错误 chrome 驱动程序。

我尝试放置 chrome 驱动程序选项,但仍然无法正常工作。 我升级了chrome驱动版本和其他一些框架,但还是同样的错误。

@RunWith(Cucumber.class)
@CucumberOptions(features="src/test/Features", glue= {"StepDefinitions"},
monochrome = true,

plugin = {"pretty", "junit:target/junit/report.xml",
        "html:target/html/HtmlReports",
        "json:target/JSONReports/report.json"},
tags="@Sorting_HL"
    

> java.lang.AbstractMethodError: Receiver class
> org.openqa.selenium.chrome.ChromeDriverService$Builder does not define
> or inherit an implementation of the resolved method 'abstract
> java.util.List createArgs()' of abstract class
> org.openqa.selenium.remote.service.DriverService$Builder.     at
> org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:441)
>   at
> org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
>   at
> org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
>   at
> StepDefinitions.COB_sorting_2.sorting_tab_is_seen(COB_sorting_2.java:57)
>   at ✽.Sorting tab is seen.(file:///folder/src/test/Features/sorting.feature:50)

类

@Given("Sorting tab is seen.")
    public void sorting_tab_is_seen() throws IOException {

        System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
        String url = "url address";
        ChromeOptions chromeOptions = new ChromeOptions();
        
//      chromeOptions.addArguments("--headless"); 
    //  chromeOptions.addArguments("no-sandbox");
        driver= new ChromeDriver(chromeOptions);

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.get(url);
    }

如果我在选项上添加无头,他们会说

java.lang.NoSuchMethodError: 'org.openqa.selenium.chromium.ChromiumOptions org.openqa.selenium.chrome.ChromeOptions.addArguments(java.lang.String[])'
at StepDefinitions.COB_sorting_2.sorting_tab_is_seen(COB_sorting_2.java:55)
at ✽.Sorting tab is seen.(file:///folder/src/test/Features/sorting.feature:50)

pom xml

<?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.eCommerce</groupId>
    <artifactId>mavenProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <name>mavenProject</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <properties>

        <suiteXmlFile>src/main/testng.xml</suiteXmlFile>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <scope>compile</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.4.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>7.0.0</version>
            <scope>compile</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>7.0.0</version>
            <scope>compile</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>6.11.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/net.masterthought/maven-cucumber-reporting -->
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>maven-cucumber-reporting</artifactId>
            <version>5.3.0</version>
        </dependency>
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>8.0.0-beta</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>7.1.0</version>
        </dependency>
        
    </dependencies>

    <build>
        <!-- <pluginManagement> lock down plugins versions to avoid using Maven 
                defaults (may be moved to parent pom)
                </pluginManagement>
                 -->
            <plugins>
                <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.0</version>
                    <configuration>
                        <!-- 
                        <suiteXmlFiles>
                            <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
                        </suiteXmlFiles>
                         -->
                        <testFailureIgnore>true</testFailureIgnore>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
                <plugin>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.7.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                <!-- 
                <plugin>
                    <groupId>net.masterthought</groupId>
                    <artifactId>maven-cucumber-reporting</artifactId>
                    <version>2.8.0</version>
                    <executions>
                        <execution>
                            <id>execution</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
                                <projectName>mavenProject</projectName>
                                <outputDirectory>${project.build.directory}/cucumber-report-html</outputDirectory>
                                <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                 -->
            </plugins>


    </build>
</project>

您的帮助将不胜感激。谢谢,

【问题讨论】:

    标签: java selenium junit selenium-chromedriver cucumber


    【解决方案1】:

    您需要通过System.setProperty() 行传递ChromeDriver 可执行文件的绝对路径,如下所示:

    System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
    

    【讨论】:

    • 感谢您的回答。驱动程序文件位于项目中,但我通过定位该路径进行了尝试,但仍然出现相同的消息错误。我应该做一个新项目吗?
    • @Workhard 是的,尝试一个新项目并让我更新
    • @Debanjan8 是的,chrome 驱动程序在一个新项目中工作。 (我必须将文件/代码移动到新项目啊啊啊啊..)我认为上面的项目有问题或与某些东西不兼容。我从github搞砸了。这是无法修复的吗?谢谢,
    猜你喜欢
    • 2022-01-28
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多