【发布时间】:2017-01-25 18:51:56
【问题描述】:
我有一个网络应用程序,我想使用 Selenium 进行测试,该应用程序使用 REST API 与后端通信。
据我了解,Selenium 主要用于测试通过应用程序的流程以及每个状态下小部件的外观/存在。这向我表明,在编写 Selenium 测试来模拟后端时,这很有意义。 Python 是我选择的语言,但我也熟悉 node.js、javascript 和 JAVA。关于模拟 REST API,您会推荐什么方法。我正在考虑使用 Python 编写服务器。我可以在我的测试环境中创建这个服务器,并配置它如何在逐个测试的基础上响应来自前端的请求。有什么工具、库可以推荐给我吗?
我还应该补充一点,我正在使用 raml 来定义我的 api。
所以在我对后端的模拟中,测试看起来像这样:
def test_no_table_for_one_user():
# configure reply for api request
rest_sim.get_users_response = (200, [{name: "Foo Bar", address: "West side"}])
navigate_to_users_page()
# test that this users details are presented without the use of a table
...
def test_table_for_multiple_users():
# configure reply for api request
rest_sim.get_users_response = (200, [{name: "Foo Bar", address: "West side"}, {name: "Foo Baz", address: "East side"}])
navigate_to_users_page()
# test that the two users are presented in the form of a table
...
【问题讨论】:
-
不确定我是否理解您想要做什么,但您可以使用swagger.io 创建简单的
REST API并使用docs.python-requests.org/en/master 将HTTP-requests 发送到REST API -
不懂问题。 SOAP UI - soapui.org 怎么样?
-
@Baz 我更新了我的回复,以解释 Python 中使用 requests 模块的可能性。 (处理休息消息的非常简单的方法)。祝你有美好的一天。
标签: java python node.js rest selenium