Common code for Android and IOS

Can we write common code for Android and IOS as mostly the test cases will be the same as mostly the element we fetch by selector will be different.


Yes, you can. You need to ensure that the element locators and test flow exactly the same between Android and iOS versions.

Hi @ganeshjogam,

On my projects, we’re using the same Test Cases to run iOS and Android tests. Like Brian mentions, this works well if both platforms’ apps have the same general flow. There will probably be some differences, e.g. Android using a sidebar for navigation and iOS using a bottom tab bar. These cases will need to be handled with a little bit of if/then logic checking in your tests.

As for the test objects, the nice thing about Katalon Studio is that the tests themselves operate on object names, not xpaths or identifiers. So, you can save an Android Test Object for a button and an iOS Test Object for a button, name them the same and you won’t have to change the logic in your test to use them. In our projects, we use a structure like this:

Where you can see the Allow location alert is the same name across Android and iOS, but the underlying definition of those objects is specific per platform.

For some help with switching between Android and iOS in the same test, I’ve published an open source library that you can include in your Katalon tests. It has some convenience functions for device/platform detection:

katalon-mobile-util Devices class

You can check the “Installation” section on how to include the library in your project:

katalon-mobile-util Installation

Hope this helps,



@Chris_Trevarthen, Can you please share some demo project or katalon project link for more understanding.

I also need to implement same test case for both Andriod and iOS paltform.

he already includes them in previous reply, Github link describles everything well (from mine perspective), if you find something unclear, you can quote that part and ask here.

Hi @bhalodia.bhavdip,

Here are some snippets from a cross-platform test. These assume you have the katalon-mobile-util library installed.

To initialize the test:

The test will look at the current device and use the appropriate platform’s .app/.apk file to run.

NOTE: This assumes that you will be putting your .app or .apk file in a /build directory within your Katalon test directory. If not, you can change the paths below. You should create a new GlobalVariable called workspace to set the full path to your Katalon test directory.

import com.detroitlabs.katalonmobileutil.device.App
import com.detroitlabs.katalonmobileutil.device.Device
import internal.GlobalVariable

// Set up for running on CI, where absolute paths are required
String currentWorkingDirectory = System.getenv("WORKSPACE") ? System.getenv("WORKSPACE") : GlobalVariable.workspace
String buildDirectory = System.getenv("BUILD_DIRECTORY") ? System.getenv("BUILD_DIRECTORY") : currentWorkingDirectory + "/build"
App android = new App(buildDirectory + '/myapp.apk', 'com.myapp.debug')
App iOS = new App(buildDirectory + '/', 'com.myapp')
// Set this to true if you want to wipe out the app each time your test runs
boolean removeAppBeforeTest = false
Device.startApp([android, iOS], removeAppBeforeTest)

When running a test, finding Test Objects:

NOTE: This assumes you have a separate Test Objects folder for “iOS Objects” and “Android Objects”. Both of these folders will need to have the same subfolders; “Alerts”, “Buttons”, “Checkboxes”, “Labels”, “Links”, “Segmented Controls”, “Switches”, “Tabs”, “Text Fields”. All of the Test Objects should be named the same between platforms, i.e. a checkout button should be located at “iOS Objects/Buttons/Checkout button” and “Android Objects/Buttons/Checkout button”.

import com.detroitlabs.katalonmobileutil.testobject.Finder

TestObject alert = Finder.findAlert('My Alert')
TestObject button = Finder.findButton('My Button')
TestObject checkbox = Finder.findCheckbox('My Checkbox')
TestObject image = Finder.findImage('My Image')
TestObject label = Finder.findLabel('My Label')
TestObject link = Finder.findLink('My Link')
TestObject segmentedControl = Finder.findSegmentedControl('My Segmented Control')
TestObject switch = Finder.findSwitch('My Switch')
TestObject tab = Finder.findTab('My Tab')
TestObject textField = Finder.findTextField('My Text Field')

These Finder functions will automatically find the correct type of object in the correct platform.

Handling different logic between platforms

Sometimes, you might need to do something different between iOS and Android.

import com.detroitlabs.katalonmobileutil.device.Device

if (Device.isIOS()) {
	println("This is an iOS device.")
if (Device.isAndroid()) {
	println("This is an Android device.")

There is a whole lot more convenience functionality available in the docs for katalon-mobile-util.

Hope this helps,


Thanks you @Chris,
I have implemented katalon-mobile-util. but the issue is I am not able to spy/record any object in iOS.

It is working with android (*.apk) but getting nullPointerException while start recording or spying object.

let me know solution if you know.

Hope you will be get me out of this.

Thank you again
Bhavdip Bhalodia

@Chris_Trevarthen hello Chris, thank you for the library, however I wonder if we use your library then Katalon does not do refactor if we update locator.

Is there anyway to overcome that ?

Hi @bhalodia.bhavdip,

Can you confirm that you’re using Appium Server 1.8.1 (or Appium Desktop 1.6.3)? For maximum compatibility, those are recommended.

Note that you can you Appium Server 1.8.2-beta for iOS 12 and Xcode 10 if necessary, but there’s not corresponding version of Appium Desktop that I’m aware of.

Here’s some more information on troubleshooting some common errors:

If you continue to get errors, could you please share a screenshot and/or log file?

Hope this helps,


Hi @Tam1,

I assume you’re talking about renaming a Test Object and having it update in the test itself or vice versa?

I don’t know if there is a way to do that using my library’s Finder functions, unfortunately. It’s something I can look into, but it probably requires knowledge of the inner workings of Katalon Studio that I don’t have.

– Chris

Thanks @Chris_Trevarthen for your fast response and sorry for bothering you (I thought you are a member of development team because I see you everywhere in forum :slight_smile:)

No worries, @Tam1! I am happy to help as much as I can - it helps me learn, too!

– Chris


Thanks Chris :relaxed:

1 Like

When I install my app directly from Android studio it works perfectly. If I create an APK and install on a device from the APK the application stops working whenever it is opened.
9apps VidMate 9apps

HI chris, i wantto keep my apk file in project structure…Can you help me to do?

You want to develop One code base application and that
Running everywhere.

A Cross platform app development is quite simply the utilization of various technologies in order to develop a single mobile application that can run on multiple platforms like ios, windows and linux. shareit apk

There are many hybrid platform that made multiple platform mobile application like Ionic Framework,PhoneGap, Cordova etc…

I develop an app for both iOS and Android, and I’m loon’ing for the best way to share code between this two platforms.

What I would like to do is creating all the View (UI part) in native but share the code for the logic (controller + model).

With all I found, 3 things seems to be quite good :

  1. C++ --> Build library file Using c++ For the logic so I’ll be able To use the .dll files in the 2 platforms

  2. Azure mobile apps services. Is it possible to habe all the logic in a webservice? The issue is that if I dont have acces to internet, my app will be unaivalable, right?

  3. I hear a lot about React native used by Facebook, but it seems to be used to create the UI, but I prever create it in native. Can I use react only for logic?

I have an android app, created in android studio and written in Kotlin.

I want to create an iOS version of this application, would Kotlin/Native be the way to go? Or would it be best to completely start a fresh new swift project?

I know java and kotlin, and have never used swift or objective c.


Sure thing man!!

We used Kotlin Multiplatform to be able to share code across Android and iOS . We also used multiplatform libraries such as Ktor for networking, Serialization for JSON Parsing, and Coroutines for asynchronous tasks.