Switching between apps

The testing of my app requires me to end each iteration of a testcase with opening the android’s “Settings” application, entering the bluetooth section and deleting a known connection to a device.

Here’s an example progression in my test:

#### Define applications to run
&{VPD_APPLICATION}=
...    package=vPD.Android.VPD.Android
...    activity=vpd.android.vpd.android.MainActivity
...    alias=VPD_
&{SETTINGS_APPLICATION}=
...    package=com.android.settings
...    activity=com.android.settings.Settings
...    alias=Settings_

#### Open my application (VPD)
${ID} =  Open Application    ${APPIUM_SERVER}
alias=${VPD_APPLICATION}[alias]
...    appium:automationName=uiautomator2
...    appium:platformName=Android
...    appium:deviceName=${DEVICE_NAME}
...    appium:autoGrantPermissions=true
...    appium:appPackage=${VPD_APPLICATION}[package]
...    appium:newCommandTimeout=600
...    appium:appActivity=${VPD_APPLICATION}[activity]
...    appium:noReset=${True}

#### Execute a batch script that flashes the device that we BT to
${PROG_RES} =    Run Process    ${BASH_PATH}    ProgramVPD.sh    
...    --option  ${VPD_SN}    shell=True    cwd=${BUILD_PATH}

#### Open Settings application and remove paired connection
${SETTINGS_AID} =  Activate Application    ${SETTINGS_APPLICATION} 
[package]
# entering Bluetooth section and removing saved device ...

#### Restart VPD application and terminate Settings application
Open Application    ${VPD_APPLICATION}[alias]
Sleep  2
Terminate Application    ${SETTINGS_APPLICATION}[package]

Restarting my app after this progression often leads to it either crashing, or being “deactivate” to the background. How should this be done the correct way?

First, if the app is crashing you may be looking at a bug. I don’t know your app or the reason that it’s crashing, but I would think that shouldn’t be happening.

Second, what happens if you manually walk though this scenario, running the batch script & all that? Do you get a crash there too?

What you are describing doesn’t sound like a terribly unusual scenario. I wonder if you could diagnose which step is causing the bad behavior? Like if there are 4 steps, what if you just did the first 3, do you see the same behavior? What if you did 1, 2, and 4? How about 1, 3, and 4? etc.

bluetooth is app in android. how about just clear it data using package name com.android.bluetooth ?

  • adb command
    or
  • appium command reset app using package name