为什么 browser.getRequest 无法获取数据?



我使用wdio拦截服务来测试网络接口,这是他的官方文件。我完全按照他的指示使用了它,但我没有得到预期的结果

这是我的测试.js

it("test a", async () => {
browser.url("https://www.amazon.in/")
let input = await $("#twotabsearchtextbox")
input.setValue("mobile")
await browser.pause(3000)
await browser.expectRequest("GET", "/api/2017/suggestions", "200")
let searchSuggestions = await browser.getRequest(
"GET",
"https://completion.amazon.in/api/2017/suggestions"
)
console.log("Response Headers", searchSuggestions)
expect(searchSuggestions).to.have.length.above(0)
})

当我运行它时,我得到了:

expected [] to have a length above +0 but got +0

这是我的回购测试:https://github.com/Ruobei/wdioTest.git

我查了很多资料,但没有找到原因,也没有找到其他调用方法如果有人知道如何解决,我们将不胜感激

您需要调用setup函数来评估调用的请求。请在browser.ull((命令之后添加browser.setupInterceptor((。

更多详细信息,请点击此处:https://webdriver.io/docs/wdio-intercept-service/#api

试用4.2.2版本:

npm install wdio-intercept-service@4.2.2

最新更新