How to change desired capabilities during executing the test suit on real android device

Hi @zanoon2010,

I think you can fake out the test to switch applications by setting the Desired Capabilities, using RunConfiguration.setMobileDriverPreferencesProperty:

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

// You will need a real .apk file here in order to launch successfully, even if you're not testing it
String appFile = "/fullpathtomyfile/mobile-beta.apk"

// The app info for the built-in app you really want to test
RunConfiguration.setMobileDriverPreferencesProperty("appPackage", 'com.android.vending')
RunConfiguration.setMobileDriverPreferencesProperty("appActivity", 'com.android.vending.AssetBrowserActivity')

// Start the application, but it will actually use the appPackage from above
Mobile.startApplication(appFile, false)

// When we're finished with the first application
Mobile.closeApplication()

// Set the desired capabilities for the built-in second application you want to test
RunConfiguration.setMobileDriverPreferencesProperty("appPackage", 'com.android.calculator2')
RunConfiguration.setMobileDriverPreferencesProperty("appActivity", 'com.android.calculator2.Calculator')

// Start the application again, but it will actually launch the appPackage from above
Mobile.startApplication(appFile, false)

Here’s a good article on how to get the appPackage and appActivity from any application on an Android device: http://www.automationtestinghub.com/apppackage-and-appactivity-name/

Hope this helps,

Chris

1 Like