【发布时间】:2021-05-14 10:05:35
【问题描述】:
我有一个用例,我需要调用外部 API、解析返回的 JSON 并在网页中填充表单字段,所有这些都在使用 Node JS 编写的 Selenium 脚本中。
类似这样的:
// in Selenium script get the form field
let inputElement = await getElementById(driver, "my-id");
// then call an API including callback function
// in the callback function with the JSON response from the API
const myText = response.data.text;
await inputElement.sendKeys(myText,Key.ENTER);
实际上我什至不知道从哪里开始 - 因为我将向作为 Selenium 脚本的一部分运行的现有异步代码添加异步代码(API 调用并等待回调中的响应)。而且我不需要丢失对 Web 驱动程序和输入元素的引用。
一些让我前进的建议和建议会非常有帮助。
【问题讨论】:
-
我不确定node.js,但如果这是在Java中,我会使用Maven作为构建工具和用于api回调的restAssured库和用于json解析的JSONObject。
-
我可以假设您熟悉 nodejs
https包吗?这可以很好地用于发出您想要的任何请求,将数据包含为回调等。 -
@cruisepandey 有一种伪
restassurednpm package,但我没有使用过自己,所以我不能保证。
标签: node.js api selenium testing automation