【问题标题】:NoSuchMethodError: org.openqa.selenium.os.CommandLine.findExecutable(Ljava/lang/String;)Ljava/lang/String; while launching Chrome using SoapUINoSuchMethodError: org.openqa.selenium.os.CommandLine.findExecutable(Ljava/lang/String;)Ljava/lang/String;使用 SoapUI 启动 Chrome 时
【发布时间】:2018-05-22 10:34:47
【问题描述】:

我正在尝试使用以下启动脚本从 SoapUI 5.2.1 工具启动 selenium 脚本:

System.setProperty("webdriver.chrome.driver","D:\\SoapUI-5.2.1\\bin\\ext\\chromedriver.exe")
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.MyUrl.com")
driver.manage().timeouts().implicitlyWait(120,TimeUnit.SECONDS);

我在 SoapUI/bin/ext 文件夹中保留了以下 selenium 依赖文件

- chromedriver 2.36
- selenium-server-standalone-3.4.0.jar
- selenium-chrome-driver-2.3.1.jar

但我在运行脚本时收到以下错误消息。

Tue May 22 15:51:47 IST 2018:ERROR:java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.findExecutable(Ljava/lang/String;)Ljava/lang/String;
   java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.findExecutable(Ljava/lang/String;)Ljava/lang/String;
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:84)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:87)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:186)
    at Script1.launchURL(Script1.groovy:49)
    at Script1.run(Script1.groovy:20)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

任何人都可以帮助我解决这个问题,因为我无法在 Google 中找到正确的解决方案。

谢谢
卡鲁纳加拉潘迪

【问题讨论】:

    标签: google-chrome selenium groovy selenium-chromedriver soapui


    【解决方案1】:

    此错误消息...

    java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.findExecutable(Ljava/lang/String;)Ljava/lang/String;
       java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.findExecutable(Ljava/lang/String;)Ljava/lang/String;
    

    ...暗示当 os 命令findExecutable() 尝试根据您的System.setProperty() line 定位可执行文件时引发了 NoSuchMethodError

    NoSuchMethodError

    NoSuchMethodError extends IncompatibleClassChangeError 并且根据 Java Docs 如果应用程序尝试调用类的指定方法(静态或实例)并且该类不再有该方法的定义。通常,编译器会捕获此错误,并且如果类的定义发生了不兼容的更改,则此错误只会在运行时发生。 不兼容的类更改是由于当前执行的方法所依赖的某个类的定义发生了变化。

    出了什么问题?

    您已经创建了 WebDriver 实例,即 driver 并通过 ChromeDriver() 进行了转换。但是 SoapUI/bin/ext 子目录包含来自 selenium-server-standalone-3.4.0.jarselenium-chrome-driver-2.3 的多个定义.1.jar.

    解决方案

    执行以下步骤:

    • SoapUI/bin/ext 子目录中删除 selenium-chrome-driver-2.3.1.jar
    • JDK升级到最新级别JDK 8u171
    • Selenium升级到当前级别Version 3.11.0
    • ChromeDriver 升级到当前的ChromeDriver v2.38 级别。
    • Chrome 版本保持在 Chrome v66.x 级别。 (as per ChromeDriver v2.38 release notes)
    • 清理你的项目工作区通过你的IDE重建你的项目只需要依赖。
    • 使用CCleaner 工具在执行测试套件之前和之后清除所有操作系统杂务。
    • 如果您的基础 Web Client 版本太旧,请通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Web Client
    • 进行系统重启
    • 执行您的@Test

    【讨论】:

    • 嗨 Debanjan,谢谢您的回复。我会尝试这些步骤... :)
    【解决方案2】:

    初始化chromedriver的代码就像下面提到的代码

    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");
    
            Webdriver driver = new ChromeDriver();
    

    您需要设置正确的 selenium 依赖工件 id,如

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.12.0</version>
        </dependency>
    

    如果您使用的是 jar 文件,请从这里下载 selenium jar 文件 Authentic link

    【讨论】:

      猜你喜欢
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 2016-02-07
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多