Clear application data
Some scenarios require a clean state of the app to run tests. For example, suppose you want to run multiple test cases where each test case requires logging into the app. While the first test is signed into the app with the login data, running the second test within the same session causes it to fail since the app is already logged in.
For such scenarios, App Automate provides parameters that you can set to clear app data after test runs.
In this section, you’ll learn about:
- Supported Android versions
- How to clear app data
- How to clear app data for a build that uses the single runner invocation feature
Supported Android versions
- Android 5.0 – Lollipop and higher.
Clear app data
Set the clearPackageData
parameter to true
in a cURL command for clearing app data after test runs in a normal test flow.
The following sample cURL command shows the parameters used to clear app data on Samsung Galaxy S8 with Android OS v7.0:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{"clearPackageData": "true", "devices": ["Samsung Galaxy S8-7.0"], "app": "<app_id>", "testSuite": "<test_suite_id>"}' \
-H "Content-Type: app/json"
The following table lists the parameters used in a cURL request for clearing app data:
Parameter | Description | Values |
---|---|---|
clearPackageData |
Clear the app data after each test has completed running |
true , false Default: false
|
devices |
Name and OS version of the device to run the test on | For example, Samsung Galaxy S8-7.0 . Check out the list of devices available in App Automate. |
app |
ID of the application you receive when you upload your application on App Automate. | For example, bs://3205774d1560ee3f5acdf
|
testSuite |
ID of the test suite you receive when you upload your test suite on App Automate. | For example, bs://4205214d1560we3f5acdfe
|
Clear app data for build that uses single runner invocation
The single runner invocation feature runs all test cases together rather than running them in a separate process. To use this feature and clear app data after each test run, you need to enable Android test orchestrator.
Set the useOrchestrator
and clearPackageData
parameters to true
in the cURL request to enable Android test orchestrator and clear app data respectively.
clearPackageData
parameter works only when it is used along with the useOrchestrator
parameter for a single runner invocation build. Hence, ensure to set the useOrchestrator
parameer in the cURL request.
The following sample cURL command shows how to use Android Test Orchestrator and clear app data on Samsung Galaxy S8 with Android OS v7.0:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \
-d '{ “singleRunnerInvocation”:”true”, "useOrchestrator": "true", “clearPackageData”:”true”, "devices": ["Samsung Galaxy S8-7.0"], "app": "<app_id>", "testSuite": "<test_suite_id>"}' \
-H "Content-Type: app/json"
The following table lists the parameters used in a cURL request for clearing app data when using the single runner invocation feature:
Parameter | Description | Value |
---|---|---|
singleRunnerInvocation |
Run test cases together with a single test runner invocation. |
true , false Default: false
|
useOrchestrator |
Enable the Android test orchestrator feature on tests that uses the single runner invocation flow |
true , false Default: false
|
clearPackageData |
Clear the app data after each test has completed running |
true , false Default: false
|
devices |
Name and OS version of the device to run the test on | For example, Samsung Galaxy S8-7.0 . Check out the list of devices available in App Automate. |
app |
ID of the application you receive when you upload an application on App Automate. | For example, bs://3205774d1560ee3f5acdfe1e7
|
testSuite |
ID of the test suite you receive when you upload your test suite on App Automate. | For example, bs://4205214d1560we3f5acdfe1e28
|
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!