My plugin in jmeter throws java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.setBinary

My plugin in jmeter throws java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.setBinary

我在 JMeter 中有插件,当我想 运行 插件时它会抛出 java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.setBinary。我很确定,ChromeOptions.set 二进制方法在我的类路径中,可能是一些库差异。 我的 build.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.dhl.dataplugin</groupId>
    <artifactId>dataplugin</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>



    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_core</artifactId>
            <version>5.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.26</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.5.3</version>
           <!-- <version>4.1.2</version> -->
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>1.28.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>30.0-jre</version>
        </dependency>
    </dependencies>

</project>

我的代码:

  public boolean upload(String url, String username, String password, String templateVersion, String filePath, String pathToDriver, String pathToChromeBinaries, String pathToChromeDriverLog) {
        System.setProperty("webdriver.chrome.driver", pathToDriver);
        System.setProperty("webdriver.chrome.logfile", pathToChromeDriverLog);

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setBinary(pathToChromeBinaries);
        chromeOptions.addArguments( "--headless");

        WebDriver driver = new ChromeDriver(chromeOptions);

        driver.navigate().to(url);

        System.out.println(driver.getCurrentUrl());

        WebElement userTextField = driver.findElement(By.id("username"));
        userTextField.sendKeys(username);

        WebElement passwordTextField = driver.findElement(By.id("password"));
        passwordTextField.sendKeys(password);

        WebElement okButton = driver.findElement(By.id("OKButton"));
        okButton.click();

        WebElement crdbTab = driver.findElement(By.linkText("CRDB"));
        crdbTab.click();


        (new WebDriverWait(driver, 5)).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("iframe_app4"));

        WebElement uploadTab = driver.findElement(By.linkText("Upload"));
        uploadTab.click();

        System.out.println(driver.getCurrentUrl());
        WebElement fileUploadButton = driver.findElement(By.id("id5f"));
        fileUploadButton.sendKeys(filePath);

        driver.findElement(By.id("idb")).click();

        WebDriverWait wait = new WebDriverWait(driver, 30);

        Select headerDataSelect = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id104"))));

        headerDataSelect.selectByIndex(1);

        Select fclHorizontal = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id110"))));
        fclHorizontal.selectByIndex(1);

        Select lcl = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id112"))));
        lcl.selectByIndex(1);

        Select templateVersionSelect = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id125"))));
        templateVersionSelect.selectByVisibleText(templateVersion);

        driver.findElement(By.id("idb")).click();

        WebElement statusMessage = new WebDriverWait(driver, 600).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[contains(text(), 'File was successfully uploaded and parsed') or contains(text(), 'Please see \"Load Errors\" sheet for information')]")));

        String statusMessageText = statusMessage.getAttribute("innerText");
        if (statusMessageText.contains("successfully")) {
            driver.close();
            return true;
        } else {
            driver.close();
            return false;
        }
    }

谁能告诉我如何解决这个问题?谢谢

您的“插件”取决于您所在 运行 这个插件的 JMeter 的 selenium-java 3.5.3, you need to make sure that exactly this library is present in the Classpath

如果您的插件编译代码与 JMeter Classpath 中可用的 API 不一致,您将收到您所报告的错误。

因此,要么将所有内容构建到 "uber jar" 中,包括您的插件代码和依赖项,要么确保为您的 JMeter 安装提供准确的依赖项。

顺便问一下,你知道JMeter WebDriver Sampler plugin吗?