Search code examples
javacsvrest-assuredserenity-bddpath-parameter

How to send Multiple values in GET request using CSV in Serenity BDD framework


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);
    }
}

Solution

  • 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