如何在水豚中断言字符串?
我正在使用 Cucumber + Capybara 和 Selenium WebDriver 测试对服务器的 API 调用。 我设法获得了响应 obj,但是如何断言响应正文包含 某些字符串?例如,如果响应正文包含“Hello World”,我想断言 此响应正文(这是字符串)包含模式“World”
例如。像这样的东西:
响应 = http.request(请求)
响应.body.should have_text(“世界”)
或者有没有办法从响应中获取“application/json”并使用断言内容 水豚?
谢谢!
I am testing an API call to the server using Cucumber + Capybara with Selenium WebDriver.
I managed to get the response obj, but how do you assert that the response body contains
certain String? For example if the response body contains "Hello World" I want to assert that
this response body (Which is string) contains a pattern "World"
ex. Something like:
response = http.request(request)
response.body.should
have_text("World")
Alternatively is there a way to get "application/json" from the response and assert the contents using
Capybara?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找的是
have_content
。有关更多信息,请查看自述文件:查看文档:https://github.com/jnicklas/capybara
I think what your looking for is
have_content
.For more info, check out the README: Check out the documentation: https://github.com/jnicklas/capybara