0

I have imported all the required jars to run RestAssured program. But facing this error.

import io.restassured.RestAssured;

import static io.restassured.RestAssured.*; public class bascis {

public static void main(String[] args) {
    // TODO Auto-generated method stub
        RestAssured.baseURI="https://rahulshettyacademy.com";
        given().log().all().queryParam("key", "qaclick123").header("Content-Type","application/json")
        .body("{\r\n"
                + "  \"location\": {\r\n"
                + "    \"lat\": -38.383494,\r\n"
                + "    \"lng\": 33.427362\r\n"
                + "  },\r\n"
                + "  \"accuracy\": 50,\r\n"
                + "  \"name\": \"Frontline house\",\r\n"
                + "  \"phone_number\": \"(+91) 983 893 3937\",\r\n"
                + "  \"address\": \"29, side layout, cohen 09\",\r\n"
                + "  \"types\": [\r\n"
                + "    \"shoe park\",\r\n"
                + "    \"shop\"\r\n"
                + "  ],\r\n"
                + "  \"website\": \"http://google.com\",\r\n"
                + "  \"language\": \"French-IN\"\r\n"
                + "}\r\n"
                + "\r\n"
                + "").when().post("maps/api/place/add/json").then().assertThat().statusCode(200);
}

}

enter image description here

  • How do you manage your imports? Maven? Gradle? Imported .jar files into the project? This error indicates you are missing a dependency – Fenio Jan 04 '21 at 14:18

2 Answers2

0

Why not use maven to solve this dependency problem ?, if you want you can use the following steps, its fairly easy.

  1. Create a maven project
  2. Add pom.xml at the root folder
  3. Add the following in your pom.xml for the rest assured dependency
<dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>4.4.0</version>
      <scope>test</scope>
</dependency>
  1. After this run

mvn clean install

  1. Use the same program and run it.
Raulster24
  • 403
  • 3
  • 14
-1

The rest assured library was created to be used in the test scope. You shouldn't use it in main scope.

  • src
    • main
    • test <-- correct way

The rest assured library must be used in the test scope as explained here: The import io.restassured.RestAssured cannot be resolved

I recommend using gradle to manage dependencies. If you prefer, you can Download this project with the structure with main, test. In addition to gradle and JUnit support: https://github.com/developercancun/gradle-simple

git clone https://github.com/developercancun/gradle-simple.git

Run from the console in the project directory

./gradlew clean build

You can see that works here: https://i.stack.imgur.com/7XVrM.jpg

  • You can use Rest Assured in compile and test scope. Instead of `./gradlew clean build` you could simply run `test` phase. – Fenio Jan 04 '21 at 14:18