NoSuchMethodError: org.openqa.selenium.os.CommandL

2019-03-02 17:40发布

I'm trying to launch the selenium scripts from SoapUI 5.2.1 tool with the following launching script:

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

I have kept the following selenium dependency file in SoapUI/bin/ext folder

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

But I'm getting the following error message while running the script.

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)

Anyone help me to solve this issue as I'm not able to find correct solution in Google.

Thanks
Karunagara Pandi

2条回答
爷的心禁止访问
2楼-- · 2019-03-02 17:56

This error message...

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;

...implies that a NoSuchMethodError was raised when the os command findExecutable() tried to locate the executable as per your System.setProperty() line.

Class NoSuchMethodError

NoSuchMethodError extends IncompatibleClassChangeError and as per the Java Docs it is thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method. Normally, this error is caught by the compiler and this error can only occur at run time if the definition of a class has incompatibly changed. Incompatible class change occurs due to change in definition of some class, on which the currently executing method depends.

What went wrong?

You have created the WebDriver instance i.e. driver and casted it through ChromeDriver(). But the SoapUI/bin/ext sub-directory contains multiple defination from selenium-server-standalone-3.4.0.jar and selenium-chrome-driver-2.3.1.jar.

Solution

Perform the following steps :

  • Remove selenium-chrome-driver-2.3.1.jar from SoapUI/bin/ext sub-directory.
  • Upgrade JDK to recent levels JDK 8u171.
  • Upgrade Selenium to current levels Version 3.11.0.
  • Upgrade ChromeDriver to current ChromeDriver v2.38 level.
  • Keep Chrome version at Chrome v66.x levels. (as per ChromeDriver v2.38 release notes)
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test.
查看更多
Anthone
3楼-- · 2019-03-02 18:00

Code to initialize the chromedriver is like the below code mentioned

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

        Webdriver driver = new ChromeDriver();

You need to set the correct dependency artifact id of selenium like

<!-- 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>

if you are using jar file then download the selenium jar file from here Authentic link

查看更多
登录 后发表回答