进行 mvn clean 测试时出现 java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.setExperimentalOption 错误

问题描述 投票:0回答:0

我在运行项目时遇到了一个奇怪的问题,因为我遇到了 org.openqa.selenium.chrome.ChromeOptions.setExperimentalOption 问题。事实上,我首先坚持使用 NoClassDefError。为了解决这个问题,我已将 httpclient5 依赖项显式放入 pom.xml 中。一旦我把它写出来,我就开始得到 java.lang.NoSuchMethodError:org.openqa.selenium.chrome.ChromeOptions.setExperimentalOption

下面是我的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>

    <artifactId>corporate-action-tests-ui</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <parent>
        <artifactId>corporate-action-parent</artifactId>
        <groupId>com.mst.indexes</groupId>
        <version>0.5.1-SNAPSHOT</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <suitefile>SmokeSuite_stg.xml</suitefile>
        <env>stg</env>
        <browser>localChrome</browser>
        <suite>Smoke</suite>
        <test_region>us-west-2</test_region>
        <updateBugInJira>false</updateBugInJira>
        <updateTestRail>true</updateTestRail>
        <updateReportPortal>false</updateReportPortal>
        <quitBrowserAfterExecution>true</quitBrowserAfterExecution>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <version>5.2.1</version>
        </dependency>

        <dependency>
            <groupId>com.mst.indexes</groupId>
            <artifactId>ui-automation-base</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>tech.grasshopper</groupId>
            <artifactId>extentreports-cucumber6-adapter</artifactId>
            <version>2.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.mst.indexes</groupId>
            <artifactId>corporate-action-dto</artifactId>
            <version>0.5.1-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/cisuite/${suitefile}</suiteXmlFile>
                    </suiteXmlFiles>
                    <systemPropertyVariables>
                        <env>${env}</env>
                        <browser>${browser}</browser>
                        <suitefile>${suitefile}</suitefile>
                        <suite>${suite}</suite>
                        <test_region>${test_region}</test_region>
                        <updateBugInJira>${updateBugInJira}</updateBugInJira>
                        <updateTestRail>${updateTestRail}</updateTestRail>
                        <rp.enable>${updateReportPortal}</rp.enable>
                        <quitBrowserAfterExecution>${quitBrowserAfterExecution}</quitBrowserAfterExecution>
                        <webdriver.chrome.driver.cachePath>C:/Users/ppathar/.cache/selenium/chromedriver/win64/126.0.6478.126
                        </webdriver.chrome.driver.cachePath>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我们使用通用框架 ui 自动化基础,并定义了 selenium 和 webdrivermanager 依赖项

<dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.6.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>

<dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

我尝试对 webdriver.chrome.driver.cachePath 进行硬编码,如图所示,让 webdriver 使用我的缓存路径中的 chromedriver,但这也不起作用。甚至尝试使用 setbrowserversion("") 方法对 browserversion 进行硬编码,但我也遇到了相同的错误。还尝试从每个依赖项中排除 httpclient5 依赖项。即使我更新了 selenium 版本和 webdrivermanager 版本。仍然没有成功。然后也遇到同样的错误。我可以为此提供一些解决方案吗?似乎没有什么对我们有用。

下面是错误堆栈跟踪

2024-07-10 07:50:22,622 level="INFO" class="i.g.bonigarcia.wdm.WebDriverManager" env="stg" description="使用 chromedriver 126.0.6478.126(Chrome 126 的已解析驱动程序)" 2024-07-10 07:50:22,667 level="INFO" class="i.g.bonigarcia.wdm.WebDriverManager" env="stg" description="将 webdriver.chrome.driver 导出为 C:\Users\ppathar.cache\seleniu

maven selenium-webdriver webdriver-manager
© www.soinside.com 2019 - 2024. All rights reserved.