rest-assured - 如何使用放心获取初始 URL 的 Http 状态码?
问题描述
假设我们有一个 URL http://example1.com并且我们有 301 URL 重定向设置,它重定向到http://example2.com。
到达http://example2.com后,返回代码 200。
我正在使用以下放心代码来获取 HTTP 状态:
public int httpResponseCodeViaGet(String url) {
System.out.println("Checking Status code for URL : "+ url);
int code = RestAssured.get(url).statusCode();
System.out.println("Status code is : "+ code);
return code;
}
这是从 URL http://example2.com返回 200 ,我想检查我的初始 URL http://example1.com的重定向状态
如何使用放心获取初始 URL 的 Http 状态码。
谢谢你,贾吉特
解决方案
你可以这样尝试
@Test
public void followsRedirectsByDefault() throws Exception {
given().
param("url1", "/hello").
expect().statusCode(302).
when().
get("url2");
}
我还建议参考包含不同场景的类似案例的放心测试的官方文档。
推荐阅读
- r - 如何更优雅地分组我的数据框
- swift - Swift P.Protocol vs P.Type
- angular - Angular 6 模板没有看到变化
- javascript - Angular TypeError:无法读取未定义的属性“名称”
- c# - 将 nvarchar 值转换为数据类型 int 和其他 SQL Server 错误时失败
- flutter - 为什么android studio没有在dart中显示对象细节?
- python - 如何通过连接曲面在 Python 中创建 3D 图像?
- django - 带有ajax的Django过滤器功能不起作用
- javascript - 使用 react native expo 为具有相同分数的用户分配相同的排名
- webgl - 如何使我的 WebGL 坐标系面向“左上”?