2017-06-04 93 views
1

出于某种原因,当我尝试使用打印语句为响应主体打印响应时,系统不打印。请帮忙。无法在控制台上打印API响应

在下面的API文章中,我使用了Java,rest-assured,EclipseNonon 3上的TestNG。使用@DataProvider注解,我在Post请求中传递多个参数以查看调用的响应。任何帮助将被真正赞赏。

package com.auto.restassured; 

import io.restassured.RestAssured; 
import static io.restassured.RestAssured.basic; 
import static io.restassured.RestAssured.given; 
import org.testng.annotations.DataProvider; 
import org.testng.annotations.Test; 
import io.restassured.response.Response; 
import org.apache.log4j.Logger; 
import org.apache.log4j.BasicConfigurator; 


public class FilePostToVirusTotal { 


static String baseURL = "https://www.virustotal.com/vtapi/v2/file/report"; 
Response myResponse; 


@DataProvider(name = "md5hashes") 
public String[][] createMd5Hashes() { 

    return new String[][] { 

     {"md51", "c1105fb75bc00b5e487f7b26a5be7088"}, 
     {"md52", "213f3287c81d09b095334c9f3151cff8"}, 
     {"md53", "b00c2c458b4cf1eb172e354f54f0fe12"}, 
     {"md54", "32ac9b6b6b7cdbfce179acc5edae98c3"}, 
     {"md55", "510b0b81b85c025d538ed4bad78dc64f"}, 

    }; 

} 

@Test(dataProvider = "md5hashes") 
public void md5JsonTest(String apikey, String resource) 
{ 

    //Catch API response 
    myResponse = given().param("text", resource).param("text", "34b937e6e2d28ee6f93a70392d958de8ac4a8dd842e08bbca9bcb0d22f9b9960").when().post(baseURL); 
    //Print Response 
    System.out.println(myResponse.getBody().asString()); 

} 

}

+2

它根本不打印,或它不打印你的期望?该方法是否正在运行?你在调试器中确认了吗? – shmosel

+0

我在打印语句之后和之后设置了调试器。它什么都不做。但是,该方法发布请求,但没有在响应中打印。当我用Postman手动进行操作时,它会回应。 – user1911509

+1

什么是回应?使用myResponse.getStatus()检查 - 只有当您的响应人员为空时才会发生这种情况.. –

回答

1

您可以使用内置的日志方法例如given().log().all()的请求和then().log().all()的回应