Search code examples
appiumwebdriver-io

How can I make API calls from within an Appium and WDIO test?


I am using Appium and Webdriver IO (WDIO).

I need to make API calls to the backend to setup and data and retrieve data during the test.

I can do some of this if I use the before function, but the test fails if I use it in the actual test.

Is it possible to make backend calls during these tests?

FYI, I am using async await and axios.


Solution

  • Without a code sample, it is hard to say what is wrong, but definetly there is a way to make it work.

    The first thing to question: are you running wdio in sync mode (default)?

    If so, you may have an issue trying to make an API call with async/await (e.g. node-fetch library) in the same test.

    Have you tried using browser.call? Check the docs, it basically the way to do what you want with wdio wrapper.

    Still failing? Try to increase test suite timeout (e.g. mocha timeout in case of Mocha)