Hi Jon, I just started doing this for my project! I’m sharing the same test file across iOS and Android. I am dynamically switching the app file based on the deviceOS. I also created a set of Test Objects for each platform with the same names, in separate Object Repositories
First, for the appFile, I created a reusable function (ended up making it a Custom Keyword later):
def startApp(String iOSFile, String androidFile, boolean resetSimulator = false) { def deviceOS = RunConfiguration.getExecutionProperties().drivers.system.Mobile.deviceOS def appFile = deviceOS == 'iOS' ? iOSFile : androidFile Mobile.startApplication(appFile, resetSimulator)}
I’ll pass both the iOS and Android file locations to this function when I start up my test, and let the deviceOS determine which to load.
In my test, when I’m looking for an object, I created a reusable findObject function which will pull from the correct Object Repository (“iOS Test” or “Android Test”). I also broke down the test objects into “Tabs”, “Buttons”, “Labels”, “Text Fields” types.
TestObject findObject(String type, String name) { def deviceOS = RunConfiguration.getExecutionProperties().drivers.system.Mobile.deviceOS String objectRepo = deviceOS + ' Test' type = type ? type + '/' : '' String object = objectRepo + '/' + type + name return findTestObject(object)}
Finally, because the functionality of my iOS and Android apps aren’t exactly the same, I have some branching logic that I can use to determine which code to run. I did this as a Custom Keyword:
package com.my.keywordsimport com.kms.katalon.core.annotation.Keywordimport com.kms.katalon.core.configuration.RunConfigurationimport com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobilepublic class system { @Keyword boolean isIOS() { return 'ios' == RunConfiguration.getExecutionProperties().drivers.system.Mobile.deviceOS.toLowerCase() } @Keyword boolean isAndroid() { return 'android' == RunConfiguration.getExecutionProperties().drivers.system.Mobile.deviceOS.toLowerCase() } }
Then in my test, I can check:
if (CustomKeywords.'com.my.keywords.system.isIOS'()) {
// Do iOS things
} else {
// Do Android things
}
Hope this helps!