Forum Discussion

chiragverma123's avatar
chiragverma123
Contributor
8 years ago

Unable to run selenium code from grrovy script(SOAPUI)

I am trying to run this code from selenium code from groovy script(SOAPUI) but getting the error - java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.conn.ssl.SSLConnectionSocketFactory error

 

import org.openqa.selenium.*
import org.openqa.selenium.chrome.ChromeDriver
import java.util.concurrent.TimeUnit
import org.openqa.selenium.OutputType
import org.apache.commons.io.FileUtils

//Initiate WebDriver
System.setProperty("webdriver.chrome.driver", "C:/chromedriver/chromedriver.exe");
log.info(System.getProperty("webdriver.chrome.driver"));

WebDriver driver=new ChromeDriver()


//Setup Environment
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS)
driver.get("http://www.google.com");

//Your Code
Thread.sleep(10000)
driver.quit()

 

Any idea why this might be happening? 

 

This is what I have tried:

1) I have placed the selenium jar 3.0.1 placed in the lib and bin folder of soap folder.

2) I have tried downgrading my selenium to 2.3.9

3) I have tried with all three browsers(i.e, firefox and chrome)

4) Tried adding the driver in the path

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    I haven't been able to prove it, but I think it might be to do with the version of org.apache.httpcomponents.httpclient that SoapUI is using? That classSSLConnectionSocketFactory isn't in httpclient-4.1.1.jar (that SoapUI ships with), but is in the latest httpclient-4.5.2.jar.

     

    You might get away with replacing httpclient and httpcore with the later versions in the SoapUI /lib folder, but like I say, I cannot prove this yet. 

     

    I was trying to recreate the error by running your script, having added selenium-chrome-driver-2.53.1.jar and selenium-java-2.53.1.jar to /bin/ext/, but I get NoClassDefFound error on [org/openqa/selenium/html5/LocationContext] instead - Have you added any other dependencies? Which SoapUI version are you using?

     

    It would be good to hear how you get on, because I have been considering updating those Apache http jars in the source code for other reasons, but it might also create some issues / testing effort for me. 

     

    Thanks,

    Rupert

    • chiragverma123's avatar
      chiragverma123
      Contributor

      I am using SOAP - 5.2.1 and I did not add any other dependencies. By replacing the HTTP client and HTTP core the ssl problem is gone. Now it is showing this new error:

       

       

      org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700' System info: host: 'DTP-DEV017', ip: '10.50.6.185', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_101' Driver info: driver.version: ChromeDriver error at line: 8

    • chiragverma123's avatar
      chiragverma123
      Contributor

      Also, someone posted a workaround on - https://github.com/seleniumhq/selenium/issues/388

       

       


      ProxySelector proxy = ProxySelector.getDefault();
      WsdlProject wsdlProject = new WsdlProject("");
      ProxySelector.setDefault(proxy);
      WebDriver driver = new FirefoxDriver();

       

      Which does not seem to work either. Possible bug in SOAPUI? Does SOAPUI supports selenium?

      • rupert_anderson's avatar
        rupert_anderson
        Valued Contributor

        Hi,

         

        SoapUI is not designed to run Selenium as part of its standard product suite, so it cannot really be considered a bug.

         

        However, I think I've got your script to run by adding the following list of jars:

         

        commons-exec-1.3.jar

        gson-2.8.0.jar

        selenium-api-2.53.1.jar

        selenium-chrome-driver-2.53.1.jar

        selenium-java-2.53.1.jar

        selenium-remote-driver-2.53.1.jar

        selenium-server-2.53.1.jar

         

        I also needed to update my Chrome driver to this one:

         

        http://chromedriver.storage.googleapis.com/index.html?path=2.25/

         

        The script now runs, I can see chrome start, and it completes without error or output.

         

        Can you give it a shot please?

         

        regards,

        Rupert