Match html response in karate

佐手、 提交于 2021-02-11 01:56:35

问题


I hava a problem in matching my response errors with html.

I tried like this

  • match $.errors == '#present'
  • match $.errors == response

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'

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


回答1:


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.

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


来源:https://stackoverflow.com/questions/60042629/match-html-response-in-karate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!