Htmlunitdriver conflicting with Restored Assurance API

I am trying to use Htmlunitdriver, but it seems to conflict with the Rest Assured API.

If I delete the saved library from pom.xml, the code below works fine HtmlUnitDriver driver = new HtmlUnitDriver ();

If I add the saved library to pom.xml, the exception will look like this:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/cookie/CookieSpecProvider
at com.gargoylesoftware.htmlunit.WebClient.createWebConnection(WebClient.java:1907)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:134)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.newWebClient(HtmlUnitDriver.java:303)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:277)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(  HtmlUnitDriver.java:148)
at dfbhdfbhdfbh.htmlunittest.main(htmlunittest.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.http.cookie.CookieSpecProvider
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more

Below is a list of dependencies

<dependencies>
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.8.1</version>
 </dependency>        
       <dependency>
    <groupId>com.jayway.restassured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>2.3.1</version>
 </dependency>              
 <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>2.48.2</version>
    <exclusions>
        <exclusion>
            <artifactId>commons-codec</artifactId>
            <groupId>commons-codec</groupId>
        </exclusion>
    </exclusions>
</dependency> 
<dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-java</artifactId>
   <version>2.48.2</version>
</dependency>  
</dependencies>

Not sure how to get around this. I tried using a different version of Selenium (2.24.1) and resolved the exception. But this creates problems with the webpage I'm trying to access. Also, if I create a Java project and add selenium and maintain confidence in the jars, I do not see any problems.

I believe this is due to the Maven dependency.

+4
1

- pom -

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
    </dependencies>
  </dependencyManagement>

Selenium HTML Unit , .

+3

Source: https://habr.com/ru/post/1622370/


All Articles