我想要使用RestAPI編程來獲取多個URI。 所有GET請求需要基本授權RestAssured響應被覆蓋
我使用了一個BaseClass的,我定義RequestSpecification如下(爲避免授權代碼每次運行測試時)
BaseClass.java:
RequestSpecification basicAuth=RestAssured.given().accept("text/html").auth().preemptive().basic("username","password");
繼承上面的Class並在我的Test方法中使用類中的「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 Response並使用basicAuth參數再次發送請求。
Thankyou :)它的工作 –
@PravallikaEsarla很高興!做出投票答案。 –