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

hello there ,

i am making test suit including first test case for running google play store and downloading face book
and the second test case to login into face book
my question is how i change apppackage and app activity desired capability from the values of google play store to values of face book
thanks in advance
@Chris_Trevarthen i hope your help

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

@Chris_Trevarthen it worked like magic but i had new issue
java.lang.securityexception permission denial starting intent
for snap chat and viber
i tried to decompile snap chat and search for the true main activity in the mainfist xml file
appium.log (29.2 KB)


so what do u think , sorry for continuous disturb

Hi @zanoon2010,

I think you’re running into an issue where the original app isn’t set up to allow it to be started from another app. You can check out this StackOverflow answer for some more info:

If you have access to the manifest file, you might be able to add android:exported=”true” to the activity, as mentioned here: In case anyone gets an Android error like the following: | by Kevin H. Eaton | Medium

– Chris

No i don’t have access as the apps are viber and snap chat so u hope if there work around or what should i read about @Chris_Trevarthen

Hi @zanoon2010,

From what I’ve read, unless you have access to the AndroidManifest.xml file and can rebuild the app, you won’t be able to get around this issue. It seems like it’s an intentional security setting.

– Chris

Thank you @Chris_Trevarthen for your post but how I can get them back ? (example : RunConfiguration.getCapabilities())