Use mock servers
You can use a mock web server in your espresso tests to mock your API responses. A mock web server mocks the behavior of an actual remote server. It takes your API request as input & returns the response which you have set instead of making calls to the actual server.
This makes it easy to test different scenarios without depending on your remote server and without having to make changes to your remote server.
If you are using a mock server in your espresso tests, you will need to specify an additional parameter allowDeviceMockServer
and set it to true
while executing your espresso tests
Here is an example cURL request to execute your Espresso tests with mock server enabled:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{"devices": ["Samsung Galaxy S8-7.0"], "app": "bs://f7c874f21852ba57957a3fdc33f47514288c4ba4", "testSuite": "bs://e994db8333e32a5863938666c3c3491e778352ff", "allowDeviceMockServer": "true"}' \
-H "Content-Type: application/json"
In the above example, the allowDeviceMockServer
parameter is set to true
to specify that app under tests is using a mock server.
Your tests might show a 503 error if you are using a mock server and not using allowDeviceMockServer
parameter.
A sample response to the above API request is shown below :
{
"message": "Success",
"build_id": "741c219db523cb51d4cdf35723ce3bfc592fb74a"
}
allowDeviceMockServer
is enabled.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!