【发布时间】:2017-06-06 16:47:40
【问题描述】:
我正在尝试使用 RestAPI 编程获取多个 URI。 所有的 GET 请求都需要基本授权
我使用了一个 BaseClass,我在其中定义了 RequestSpecification,如下所示(为了避免每次运行测试时都使用授权代码)
BaseClass.java:
RequestSpecification basicAuth=RestAssured.given().accept("text/html").auth().preemptive().basic("username","password");
继承了上面的类,并在我的测试方法中使用了类中的“basicAuth”参数。
public class Tests extends BaseClass
{
@Test(priority=1)
public void test01() throws IOException
{
response=basicAuth.when().get("URL1");
Assert.assertEquals(200,response.getStatusCode());
}
@Test(priority=2)
public void test02() throws IOException
{
response=basicAuth.when().get("URL2");
Assert.assertEquals(200,response.getStatusCode());
}}
这里的问题是两个测试都返回相同的响应(test01 的响应),尽管 URI 不同。 单独运行 test02 跳过 test01 会给出预期响应。
解决方法是定义两个RequestSpecification 参数和Send 请求。 有没有办法可以清除以前的 GET 响应并使用 basicAuth 参数再次发送请求。
【问题讨论】:
标签: java rest automation rest-assured