匹配空手道中的html响应 [英] Match html response in karate

查看:72
本文介绍了匹配空手道中的html响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将响应错误与html匹配时遇到问题.

I hava a problem in matching my response errors with 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>

我正在这样做,并且程序将停止!

I'm doing it like this and the scnario will be stoped!

When method post
* if (responseStatus == 500 ) karate.abort()
  Then status 200
* match $.errors == '#notpresent'

我该怎么做才能将响应匹配为html文本?

How can I do to get the response match as html text?

推荐答案

对不起,空手道仅适用于格式正确的XML.您可以尝试替换HTML中的内容以进行清理.或者,您可以只进行字符串contains匹配等.或者,您可以编写一些JS或Java代码进行自定义检查.

Sorry Karate only works with well-formed XML. You can try to replace content in the HTML to clean it up. Or you can just do string contains matches etc. Or you can write some JS or Java code for custom checks.

这将起作用(在删除格式不正确的<meta>标记之后.

This will work (after removing the <meta> tag which is not well-formed.

* 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!'

这篇关于匹配空手道中的html响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆