1
我的所有請求都失敗,似乎是我無法將數據從數據提供者傳遞到json字段。任何想法和想法?無法將數據從@DataProvider傳遞到JSON
我正在使用@dataprovider爲我的性能測試傳遞多個值。我得到的數據提供者的每個值的狀態代碼爲200,但無法將數據提供者值傳遞到Json字段的「值」中。 Values字段取每個數據提供者值並請求api獲取信息。
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";
}
}
大替換值部分,非常感謝你 - 我已經改變了它,它工作正常。感謝你的幫助。 – 9009