Appium and RestAssured breaks the app functionality


I am writing a mobile test case using Appium. I reach a state in the app where I am forced to call APIs to continue testing the full cycle. Therefore, I have decided to use RestAssured library to call those APIs and assert between each API call. However, when I call the APIs, the Mobile App almost always doesn’t not respond in the front-end to those call, but the APIs affect the back-end correctly. When the process is done without the automation, it works perfectly fine. For example,

I have 3 stages in the mobile app “Preparing” “Ready” and “Done”, and each stage is reached through the backend API call. I simulate this call using the RestAssured calls. I call Preparing, Ready and Done APIs. When the automation function is finalised, the front-end is not affected by it. And when I go back to the home screen, it shows that the stages are “Done” without being able to assert the changes in the Stages screen.

I hope I made this clear in my example. Might this issue be from the automation side or could it be from the App’s code itself? If anyone has faced any issue related to mine please feel free to share your thoughts and suggestions on it.

Thank you

After some investigation, when I call the APIs through the test case it fails. However, when I call the APIs manually after the automation is done, it works properly.

What’s the failure? Without knowing this, can only guess. Maybe you are running automation under a different user and don’t have access to the same Environment Variables? Maybe authentication issue? Maybe not enough time for app to update in automation? How long does it take for the app to update during manual testing (time it) and do you give automation the same amount of time to update?

Might want to share some code too if you really think it’s an integration issue, but I would doubt it is.

Hi @wreed,
Sorry if I wasn’t clear about the issue.

return RestAssured.
header(“Authorization”,“Bearer " + admin_token).

This is the code used for one of the functions. To answer your other questions, usually the app instantly updates the status after those APIs are called. They work instantly when the automation is not running. The issue is that while the automation test is running and the APIs are called, the status does not change at all on the mobile device. I’ll have to go back to a different screen, then back to the stages screen to see the change of status.

Your code is very straight forward. I would doubt there is any conflict code wise. When you say this:

How long have you waited? For example, if you added an explicit wait of 5 minutes (something like sleep(300)), it would never update?

If you haven’t tried this, could you test it?

The only other thing I can think of is that you could try running the API call in another thread. Here is a tutorial on thread management. It should work fine if you don’t need any return value from the other thread:

Hi @wreed , yes I have tried to implement an explicit wait but not that long. The value would never change as I wait in the screen. However, when I change the screens it would update since the Database values were changing.

I have thought of implementing Parallel Threads too, haven’t implemented it yet. But I do need some value from the APIs response to use in the next API call. I will see how I can implement that and update this post with the results.

Thank you

@wreed , I just tried to use a different Thread to call the APIs and it still didn’t work. What is strange is that when I call the APIs through code but not through the Automation, it works perfectly fine. However, when I call them throughout the run of the automation, the app does not respond to the changes unless we navigate through the screens (the stages screen is refreshed manually).

Thank you for your suggestion. I will continue trying to find a solution for it and keep the post updated.

Best Regards,

I’m sorry this did not work for you. I will continue to think about it and reply if I have anything. Not sure what’s going on here.

1 Like

After trying many suggestions, nothing worked. I ended up using a work around, where with each API call I navigate back to a different screen then open the screen where the stages change accordingly. And with each navigation I do my assertions of the new API status change call.