1

How to pass CSV with multiple values in GET Request. When I am tried to pass the values as below its not giving the response properly.please help here to get the response.

For Eg: My CSV file contains ID's: 15,16,20

How can I pass this ID's in GET request.

EmployeeID.csv

EmployeeID
15
16
20
@BeforeClass
    public static void init() {

        RestAssured.baseURI = "https://dummy.restapiexample.com/api/v1";
    }
    @Test
    public void getAllRequests() {
        ArrayList<String> employeeIDs = new ArrayList<>();
        employeeIDs.add(employeeID);
        SerenityRest.given().log().all().when().get("/employees/employeeID").then().log().all().statusCode(200);
        System.out.println(employeeID);
    }
}
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
  • which serenity's version you are working on? – lucas-nguyen-17 May 16 '22 at 02:05
  • This serenity version uses JUnit4, then you can follow this tutorial to do data-driven testing https://serenity-bdd.github.io/theserenitybook/latest/junit-data-driven.html – lucas-nguyen-17 May 16 '22 at 03:48
  • Hi, I followed your code and used it. My CSV has 3 different Customer ID's. I used your code and see that it ran for 3 times because I have 3 different Customer ID's. But I see that that my customer ID's are not getting populated in this code of line - SerenityRest.given().log().all().when().get("/employees/employeeID").then().log().all().statusCode(200); I am writing my code like this - – Charlotte Ryerr May 16 '22 at 04:10
  • is this correct ? @Test public void getAllRequests() { ArrayList employeeIDs = new ArrayList<>(); employeeIDs.add(employeeID); SerenityRest.given().log().all().when().get("/employees/15").then().log().all().statusCode(200); System.out.println(employeeID); } – Charlotte Ryerr May 16 '22 at 04:10

1 Answers1

0

This code would work for you

import io.restassured.RestAssured;
import net.serenitybdd.junit.runners.SerenityParameterizedRunner;
import net.serenitybdd.rest.SerenityRest;
import net.thucydides.junit.annotations.UseTestDataFrom;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(SerenityParameterizedRunner.class)
@UseTestDataFrom(value = "EmployeeID.csv")
public class DemoTest {

    private int EmployeeID;

    public void setEmployeeID(int EmployeeID) {
        this.EmployeeID = EmployeeID;
    }

    @BeforeClass
    public static void init() {
        RestAssured.baseURI = "https://dummy.restapiexample.com/api/v1";
    }

    @Test
    public void getAllRequests() {
        SerenityRest.given().log().all().when()
                .get("/employees/" + EmployeeID)
                .then().log().all()
                .statusCode(200);
    }
}

File csv at: src/test/resources/EmployeeID.csv

lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20