I use wdio intercept service to test the network interface,This is his official document. I used it completely according to his instructions, but I didn't get the expected results
this is my test.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)
})
when I run it, I got:
expected [] to have a length above +0 but got +0
This is my repo for test: https://github.com/Ruobei/wdioTest.git
I checked a lot of materials, but I didn't find the reason, nor did I find any other calling methods。If anyone knows how to solve it, it will be appreciated。
You need to call the setup function in order to assess request called. Please add browser.setupInterceptor() after the browser.url() command.
More details can be found here: https://webdriver.io/docs/wdio-intercept-service/#api