Skip to content
Advertisement

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

I have plugin in JMeter, which throws java.lang.NoSuchMethodError: org.openqa.selenium.chrome.ChromeOptions.setBinary when I want to run plugin. Im pretty sure, that ChromeOptions.set binary method is on my classpath, maybe some library discrepancy. My 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>

My code:

  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;
        }
    }

Can someone give me a point how to solve this issue? Thank you

Advertisement

Answer

Your “plugin” depends on selenium-java 3.5.3, you need to make sure that exactly this library is present in the Classpath of the JMeter where you’re running this plugin.

In case of inconsistencies between your plugin compiled code and the API available in JMeter Classpath you will get the errors like you’ve reported.

So either build everything into an “uber jar” including your plugin code and dependencies or make sure to supply the exact dependencies to your JMeter installation.

By the way, are you aware of JMeter WebDriver Sampler plugin?

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement