【问题标题】:Match html response in karate [duplicate]匹配空手道中的html响应[重复]
【发布时间】:2020-02-04 01:10:58
【问题描述】:

我在将我的响应错误与 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 文本?

【问题讨论】:

    标签: karate


    【解决方案1】:

    抱歉,空手道仅适用于格式良好的 XML。您可以尝试替换 HTML 中的内容以进行清理。或者你可以只做字符串contains匹配等。或者你可以编写一些JS或Java代码进行自定义检查。

    这将起作用(在删除格式不正确的&lt;meta&gt; 标记之后。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 2019-08-20
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      • 1970-01-01
      相关资源
      最近更新 更多