问题
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