java - 放心。HTML。Response.prettyPrint() 返回错误数据
问题描述
我发出一个 GET 请求,该请求返回一个带有 HTML 代码示例的响应:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<!-- SCROLL TOP BUTTON -->
<!--===================================================-->
<button id="scroll-top" class="btn"><i class="fa fa-chevron-up"></i>
</button>
<!--===================================================-->
</body>
</html>
如您所见,没有诸如“type='submit'”之类的属性。
1.然后如果你运行下一个代码:
given().body("{\"fileid\":\"FURRL6Q91QTN\"}")
.post("https://tryit.w3schools.com/code_datas.php")
.prettyPrint();
你会看到,响应正文有 type="submit" 的按钮:
<html lang="en">
<head/>
<body>
<button type="submit" class="btn" id="scroll-top">
<i class="fa fa-chevron-up"/>
</button>
</body>
</html>
2. 如果您尝试像这样验证放心的响应正文:
given().body("{\"fileid\":\"FURRL6Q91QTN\"}")
.post("https://tryit.w3schools.com/code_datas.php")
.then()
.body("**.findAll{it.@id == 'scroll-top' && it.@type =='submit'}.size()", Matchers.is(0));
你会看到断言失败消息:
java.lang.AssertionError: 1 期望失败。
XML 路径 **.findAll{it.@id == 'scroll-top' && it.@type == 'submit'}.size() 不匹配。
预期:是 <0>
实际:1
3. 但是如果之前只使用 asString() 方法打印正文响应:
String responseStr = given().body("{\"fileid\":\"FURRL6Q91QTN\"}")
.post("https://tryit.w3schools.com/code_datas.php")
.asString();
System.out.println(responseStr);
代码会很好,并且该按钮上不会有任何类型:
==================================
问题:在1-2个情况下会发生什么?
解决方案
推荐阅读
- c# - 是否可以在 VSTO-Add-In 中通过 C# 获取当前的 Office-Design
- javascript - 使用来自 HTML 文件的 WebPack 构建包时如何获得 WebStorm 代码完成?
- javascript - 从字符串中删除不是名字/姓氏字符的字符
- swiftui - SwiftUI - 如何调整 PickerView 的大小?
- datetime - 同一张表中的当年销售额和上一年销售额?
- firebase - 如何返回 Firebase 中更改的文档数量?
- php - Laravel Queue 处理 Supervisor 的问题
- jupyter - 从其他笔记本启动笔记本
- unix-timestamp - 如何将 Unix 时间戳记为 00:00:00
- php - MVC 查询不会从数据库中获取所有记录