请考虑以下代码,
import org.junit.Test;
import org.omg.CORBA.Request;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;
import static com.jayway.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
public class App
{
@Test
public void loginAuthentication()
{
RestAssured.authentication = basic("username", "password");
Response resp = given().
contentType("application/x-www-form-urlencoded").
when().
post("https://unitrends.atlassian.net/login?username=Gayatri.londhe&password=GayatriA4");
System.out.println(resp.prettyPrint());
}
}
我收到了低于回应,
<div class="aui-message error">
<span class="aui-icon icon-error"/>
<span class="error" id="error-authentication_failure_invalid_credentials">
Sorry, we didn't recognize that username and password combination. Please double-check and try again.
</span>
</div>
如何在放心使用身份验证,我可以使用REST控制台(chrome插件)进行休息后请求。 我做错了什么?
我希望能得到一些帮助。我是新的保证测试。
答案 0 :(得分:0)
试试这个......
Response resp = given().
contentType("application/x-www-form-urlencoded").expect().response().statusCode(200).
when().
post("https://unitrends.atlassian.net/login?username=Gayatri.londhe&password=GayatriA4");
如果响应状态为200,它将获取响应。如果服务端点成功返回200以外,则会更改响应。
试试这个
@BeforeClass
public void setup() throws org.json.JSONException, IOException {
//Assigning base url
RestAssured.baseURI = "https://unitrends.atlassian.net/";
//Assigning default port
RestAssured.port = <port>
RestAssured.basePath = "login";
RestAssured.config = config().redirect(RedirectConfig.redirectConfig().followRedirects(true).and().allowCircularRedirects(true).maxRedirects(100));
}
@Test
public void testRestServiceAuthentication() {
//for a get method with basic authorization,its expecting response code 200
Response res = given().expect().response().statusCode(200).when().post("?username=Gayatri.londhe&password=GayatriA4");
System.out.println(res.getBody().asString());
}