5

I have included rest assured jars in my POM as below.

    <dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.0</version>
    </dependency>

But still the import statements are showing "The import io cannot be resolved". If i download the rest assured jars and add them manually as external jars the error disappears.

import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

I tried removing the

<scope>test</test> 

tag also as suggested in some sites. This doesn't solve the issue.

import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.restassured.RestAssured;

public class OpenURL {

    @BeforeClass
    public void initPath() {

        RestAssured.baseURI = "http://localhost:9876";
    }

    /*******************************************************
     * Send a GET request to /api/f1/2016/drivers.json
     * and check that the answer has HTTP status code 200 
     ******************************************************/

    @Test
    public void checkResponseCodeForCorrectRequest() {

        given().
        when().
            get("/api/f1/2016/drivers.json").
        then().
            assertThat().
            statusCode(200);
    }
}

My complete POM is here. I am not finding any issues here.

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>REST</groupId>
  <artifactId>REST</artifactId>
  <version>0.0.1-SNAPSHOT</version>
   <dependencyManagement>
    <dependencies>
        <dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.9.10</version>
 </dependency>

                <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>2.4.5</version>
        </dependency>
        </dependencies>
          </dependencyManagement>
</project>
hongsy
  • 1,498
  • 1
  • 27
  • 39
Sugan
  • 447
  • 1
  • 4
  • 16

4 Answers4

6

I doubt the "dependencyManagement" tag, can you try with the below

  <version>0.0.1-SNAPSHOT</version>
          <dependencies>
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>rest-assured</artifactId>
                <version>3.0.0</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.testng/testng -->
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.9.10</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
                <version>2.4.5</version>
            </dependency>
        </dependencies>
</project>
Wilfred Clement
  • 2,674
  • 2
  • 14
  • 29
1

Here is the complete POM.XML with latest dependencies.

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.student.app</groupId>
<artifactId>PaypalExmaples</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>PaypalExmaples</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

    <!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>4.1.2</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.1.0</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy -->
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy</artifactId>
        <version>2.5.9</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.11</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.3.1</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.9</version>
    </dependency>

    <dependency>
        <groupId>io.rest-assured</groupId>
        <artifactId>rest-assured-all</artifactId>
        <version>4.0.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.10.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>2.5.9</version>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>org.skyscreamer</groupId>
        <artifactId>jsonassert</artifactId>
        <version>1.5.0</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.10.0.pr2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.scribe/scribe -->
    <dependency>
        <groupId>org.scribe</groupId>
        <artifactId>scribe</artifactId>
        <version>1.3.7</version>
    </dependency>


</dependencies>

user1053540
  • 39
  • 1
  • 1
  • 5
0
<dependencies>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>
    
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>test</scope>
        </dependency>

<dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>spring-mock-mvc</artifactId>
            <version>4.3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>4.3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-path</artifactId>
            <version>4.3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>xml-path</artifactId>
            <version>4.3.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.6</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.6</version>
        </dependency>

        <dependency>
            <groupId>io.github.json-snapshot</groupId>
            <artifactId>json-snapshot</artifactId>
            <version>1.0.17</version>
        </dependency>

        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>5.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.juneau</groupId>
            <artifactId>juneau-marshall</artifactId>
            <version>8.2.0</version>
        </dependency>
    

  </dependencies>
  
  <build>
    <plugins>
  <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>3.5.1</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Export-Package>
                            !io.restassured.path.xml.*,
                            !io.restassured.path.json.*,
                            !io.restassured.common.*,
                            !io.restassured.internal.path.xml.*,
                            !io.restassured.internal.path.json.*,
                            !io.restassured.internal.common.*,
                            io.restassured.*
                        </Export-Package>
                        <Import-Package>
                            groovy.*;version="${groovy.range}",
                            org.codehaus.groovy.*;version="${groovy.range}",
                            *
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
             </plugins>
  </build>
</project>

I red several articles, and I got solution after 3-4 hours of work. Please use these dependencies after version tag in pom.xml.

Manually download these 2 jars and add them.

Download file bundle, run your program, and see the results.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
-1
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

worked for me. Here I am not using POM file

David Buck
  • 3,752
  • 35
  • 31
  • 35
  • Please [edit] your answer to ensure that it improves upon other answers already present in this question. – hongsy Jan 18 '20 at 10:28