cannot pass data from @DataProvider to JSON

459 views Asked by At

All my requests are failing due and seems to be I am unable to pass the data from dataprovider to the json field. Any thoughts and ideas ?

I am using @dataprovider to pass multiple values for my performance testing. I am getting status code 200 for each value in the dataprovider but cannot pass the dataprovider values into Json field "values". Values field takes each dataprovider values and requests the api to get the info.

package com.company.testing;
import static io.restassured.RestAssured.given;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import io.restassured.response.Response;

public class test1 {

    Response myResponse;
    String baseURL = "http://test.com/1.0/api";

    @DataProvider(name = "data")
    public Object[][] createTestData() {
        return new Object[][]{
            {"some1.com"},
            {"some2.net"},
            {"some3.com"},
            {"some4.com"}};
    }



  @Test(dataProvider = "data")
    public void potTest(String values){
        Response myResponse;
        String baseURL = "http://test.com/1.0/api";
        System.out.println(values);
        String Json = buildJson(values);
        myResponse = given().contentType("application/json").body(Json).when().post(baseURL);
        //Print Response
        //System.out.println("Request :" + Json);
        System.out.println("Response Body : "+myResponse.getBody().asString());
        System.out.println("Response Code : "+myResponse.getStatusCode());
        System.out.println("Response Time : "+myResponse.getTime());
    }

    String buildJson(String values){
        return "{\n" +
               " \"oemid\":\"company1\",\n" +
               " \"deviceid\":\"DeviceId\",\n" +
               " \"uid\":\"system1\", \n" +
               " \"values\":\n" +
               "    [\"values\"], \n" +
               " \"queries\":\n" +
               "    [\"gethistory\"], \n" +
               " \"starttime\" : \"2017-06-10T00:00:00\", \n" +
               " \"endtime\" : \"2017-08-25T00:00:00\", \n" +
               " \"xml\":0, \n" +
               " \"nocache\":1 \n" +
               "  }\n";
    }




}
1

There are 1 answers

1
niharika_neo On

Your buildJson method is not using the parameter at all. Replace the values part with

" \"values\":[" + values + "\"]" +