0

I have just set up rest assured framework and implemented it as a maven project. My pom.xml has the below mentioned dependencies

  <dependencies>
  <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.2</version>
    <scope>test</scope>
</dependency>
  
  
  <!-- To parse json Document -->
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>json-path</artifactId>
    <version>3.0.2</version>
</dependency>


<!-- To validate that a json response conforms to a json schema -->
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>json-schema-validator</artifactId>
    <version>3.0.2</version>
</dependency>


<!-- To parse xml document -->
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>xml-path</artifactId>
    <version>3.0.2</version>
</dependency>


<!-- Testing framework -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.10</version>
    <scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.hamcrest/java-hamcrest Used for Regex -->
<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>java-hamcrest</artifactId>
    <version>2.0.0.0</version>
    <scope>test</scope>
</dependency>
  
</dependencies>  
</project>

And my code looks like

import static io.restassured.RestAssured.*;

import org.testng.annotations.Test;

public class LrnAsServiceApis {
    

    @Test
    public void trackvialrnumber() {
        
        given().get("lt-api.delta.com/v1/fulltrack/ABCD").then().log().all();
    }

But when I run it as TestNg I get error: java.lang.NoClassDefFoundError: groovy/lang/GroovyObject

And when I try to fix this by adding groovy all dependency I get another error:

java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase

And when I add another dependency, I get another error and this becomes never ending and frustrating. Is it that cumbersome? How do I fix once and for all?

9
  • 1
    Show us how you describe dependency in your pom.xml and how exactly you're trying to run your code.
    – Alexey R.
    Jun 5, 2018 at 12:15
  • Alexey, I have described the dependencies in the question. I run it as a TestNG Test. Jun 5, 2018 at 12:34
  • Try to leave only "io.rest-assured rest-assured 3.0.2 test" and "org.testng testng 6.10 test"
    – Alexey R.
    Jun 5, 2018 at 13:34
  • Doesn't work! Same errors. Jun 5, 2018 at 17:48
  • Is your code under main folder or under test folder?
    – Alexey R.
    Jun 5, 2018 at 18:27

1 Answer 1

1

The Problem is with scope of the Rest Assured dependency in the pom.xml file

If your running your Rest Assured test from src/main/java the scope should be compile and your dependency will be as shown below

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.2</version>
    <scope>compile</scope>
</dependency>

and if your running your Rest Assured test from src/test/java the scope should be test and your dependency will be as shown below

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.2</version>
    <scope>test</scope>
</dependency>

Solution is to change the scope to compile for rest assured dependency in pom.xml file

Reference: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

compile:This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

test:This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases. This scope is not transitive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.