karate - 在空手道中匹配 html 响应
问题描述
我在将我的响应错误与 html 匹配时遇到问题。
我试过这样
- 匹配 $.errors == '#present'
- 匹配 $.errors == 响应
错误:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Error: Unexpected object!</pre>
</body>
</html>
我正在这样做,scnario 将被停止!
When method post
* if (responseStatus == 500 ) karate.abort()
Then status 200
* match $.errors == '#notpresent'
如何将响应匹配为 html 文本?
解决方案
抱歉,空手道仅适用于格式良好的 XML。您可以尝试替换 HTML 中的内容以进行清理。或者您可以只进行字符串contains
匹配等。或者您可以编写一些 JS 或 Java 代码进行自定义检查。
这将起作用(在删除<meta>
格式不正确的标签之后。
* def response =
"""
<!DOCTYPE html>
<html lang="en">
<head>
<title>Error</title>
</head>
<body>
<pre>Error: Unexpected object!</pre>
</body>
</html>
"""
* match //pre == 'Error: Unexpected object!'
推荐阅读
- sql - SQL GROUP BY、ORDER BY 查询返回语法错误
- python - 如何在 Pandas Dataframe 中断言单元格值
- laravel - 从存储移动和调整大小
- python - 修复大型 matplotlib 图中的重叠标签
- machine-learning - Quora Question Pairs challenge,使用二元交叉熵损失预测两个问题是否问同一个问题来评估预测
- html - 为 React + Nodejs / Express 更改 id="root" 的文件位置
- excel - 使用 Countifs 来计算不同的值和多个标准?
- git - Github 在我提交时使用不同的用户名发送电子邮件通知
- overflow - 拖出带有溢出的放置区时,Interact.js 可拖动项不可见:滚动
- spring-boot - 如何在 Spring Test Suite 中运行 JUnit 5 测试?