簡體   English   中英

我在 jmeter 中的插件拋出 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 二進制方法在我的類路徑中,可能是一些庫差異。 我的構建.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;
        }
    }

有人可以告訴我如何解決這個問題嗎? 謝謝

您的“插件”依賴於selenium-java 3.5.3 ,您需要確保該庫恰好存在於您運行該插件的 JMeter 的類路徑中。

如果您的插件編譯代碼與 JMeter 類路徑中可用的 API 不一致,您將收到與您報告的一樣的錯誤。

因此,要么將所有內容構建到一個“uber jar”中,包括您的插件代碼和依賴項,要么確保為您的 JMeter 安裝提供准確的依賴項。

順便問一下,你知道JMeter WebDriver Sampler 插件嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 獲取“線程“main”中的異常java.lang.NoSuchMethodError:org.openqa.selenium.WebElement.setSelected()V”錯誤 Selenium 4: 獲取 java.lang.NoSuchMethodError: org.openqa.selenium.WebElement.getDomAttribute/String; Selenium Phantomjs 驅動程序 - java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String; java.lang.NoSuchMethodError: 'void org.openqa.selenium.support.PageFactory.initElements(org.openqa.selenium.SearchContext, java.lang.Object)' 線程“main”中的異常 java.lang.AbstractMethodError:接收器類 org.openqa.selenium.chrome.ChromeOptions 未使用 Selenium 定義錯誤 java.lang.NoSuchMethodError: org.openqa.selenium.firefox.FirefoxOptions.merge(Capabilities) 嘗試使用 Selenium 合並 DesiredCapabilities 時 java.lang.NoSuchMethodError:org.openqa.selenium.support.ui.FluentWait.until(Lcom / google / common / base / Function;)Ljava / lang / Object; 線程“主”中的異常java.lang.NoSuchMethodError:org.openqa.selenium.io.FileHandler.unzip(Ljava / io / InputStream;)Ljava / io / File; java.lang.NoSuchMethodError: com.google.common.util.concurrent.SimpleTimeLimiter.create at org.openqa.Z8E00596AD8DE2213FF8F8D8478D5DriverService.remo 使用Chrome驅動程序java.lang.NoSuchMethodError運行Selenium時出錯:
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM