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?

Prome
1,01511 silver badges25 bronze badges
asked Jun 5, 2018 at 10:22
9
  • 1
    Show us how you describe dependency in your pom.xml and how exactly you're trying to run your code. Commented Jun 5, 2018 at 12:15
  • Alexey, I have described the dependencies in the question. I run it as a TestNG Test. Commented 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" Commented Jun 5, 2018 at 13:34
  • Doesn't work! Same errors. Commented Jun 5, 2018 at 17:48
  • Is your code under main folder or under test folder? Commented 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.

answered Jun 22, 2020 at 7:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.