Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 已覆盖重新启动的响应_Java_Rest_Automation_Rest Assured - Fatal编程技术网

Java 已覆盖重新启动的响应

Java 已覆盖重新启动的响应,java,rest,automation,rest-assured,Java,Rest,Automation,Rest Assured,我正在尝试使用RestAPI编程获取多个URI。 所有GET请求都需要基本授权 我使用了一个基类,其中定义了如下所示的RequestSpecification(以避免每次运行测试时都使用授权代码) BaseClass.java: RequestSpecification basicAuth=RestAssured.given().accept("text/html").auth().preemptive().basic("username","password"); 继承了上面的类,

我正在尝试使用RestAPI编程获取多个URI。 所有GET请求都需要基本授权

我使用了一个基类,其中定义了如下所示的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参数并发送请求。
是否有一种方法可以清除前面的GET响应并使用basicAuth参数再次发送请求

您需要将通话分为两个通话: 1.添加一个beforeMethod()函数调用,在该函数中,您应该调用BaseClass.java中的auth函数,这将返回一个对象(客户机),稍后您可以在测试类中使用该对象。 2.在每个测试类中,使用客户机对象并调用特定的URL。因为每次调用before方法时,都会创建一个新的客户机对象。 因此,理想情况下,第二次调用将使用auth客户端进行调用,并将URL对象作为参数传递