In this chapter, we will write our first script for both Android and iOS native applications.
In this chapter, we will cover:
Android App Key Concepts
iOS App Key Concepts
Install and Launch Native Apps
Desired Capabilities for Appium for both Android and iOS native applications
Appium Inspector with Appium Desktop
Write our first script for Android and iOS native applications
Before we write our first script for an Android application, we should know three things about that Android applications:
A file with an APK file extension is an Android Package file that's used to distribute applications on Google's Android operating system.
APK files are typically downloaded directly to Android devices, and you can use, for example, the Google Play Store application.
Here from this link, you can download the APK and install it on your device directly.
AppPackage is a technical name of the application, which is provided by its developers.
It's a top-level package under which all the code for the app resides.
For example, the appPackage for YouTube for Android is com.google.android.youtube
.
appActivity refers to the different functionalities that are provided by the application.
For example, YouTube provides multiple functionalities, such as a video player, search, profile information, login, or registration.
All these functionalities are represented by different appActivity.
For example, if I wanted to open a specific activity, I would first open the appPackage by mentioning com.google.android.youtube
, then I would select the specific appActivity - for example, I could open the video player or search or profile information with our Appium scripts.
With these activities, every app has a main activity, which is sort of the main screen you see when you launch the application - which, in the case of YouTube, can be the video player.
When you launch the app with Appium, it needs to know which activity has to be launched.
Now it's time to learn the iOS App Key Concepts.
The iOS App Key Concepts contain:
A file with the IPA file extension is an iOS Package file that's used to distribute applications on Apple's iOS operating systems, like .APK for Android.
IPA files are typically downloaded directly to iOS devices.
For the development and the testing purposes, we can use .app instead of the .ipa, because sometimes we don't need to sign and provision the application with IPA and we only need to use it.APP in our case.
UDID is a Unique Device Identifier, which any Apple device is equipped with.
As the name suggests, the UDID is unique, cannot be changed, and thus remains constant over the entire service life of the device.
For example, when you open the iPhone 11 Pro, on the device or from Xcode, you can find the Identifier, which is this - the UDID.
In our case, why are we mentioning the UDID here?
Because when you are running on the physical device, you should pass or add desired capabilities with the UDID to be able to reach the device correctly.
BundleID is the AppPackage in Android.
It represents the app's unique identifiers that you can register, modify, and delete.
You need the BundleID before you can assign capabilities with the BundleID Capabilities resource or create a provisioning profile with the Profiles resource.
Here, under "Signing & Capabilities" in the project, you can find the Bundle Identifier.
You can add the unique name or identifier for your package or BundleID for your application to be able to install it on the physical device and use it in the provisioning profile.
Now in our demo, let's install and launch the native apps for iOS and Android, to be able to use them with our demo with Appium.
To install our applications on our Android device and iOS, we should have the Android APK or we should have the Android application, and also, we should have iOS.application or iOS .IPA application.
If you have already signed iOS applications, we can use them.
For example, here we can open the browser, and then we can redirect to the Appium repository.
Under the Appium repository on GitHub, we can find the sample-code
folder.
Under sample-code
, we have the apps
folder, and here we have two applications.
We can download and use this APK, and also this zip folder including the iOS application, to be able to use it for the first demo.
In our case, I will use this apk only for Android.
I will have another application for iOS - it's also under Appium and it's the ios-uicatalog
.
It's an application including different elements to be able to use the UI kit or UI elements on iOS applications.
I have already downloaded these applications on my desktop.
Here is the UIKitCatalog
application which I opened in Xcode, built, and extracted the application on the desktop.
Also, I have the ApiDemos.apk
.
I have one additional APK, APKInfo.apk
, which will be installed to learn how we can get the appActivity and the appPackage from our Android application using the app info.
Here on the command line, I will redirect to the Desktop.
cd Desktop
For Android, I will use:
adb install ApiDemos.apk
This is the first way to install the Android application on the device.
That installed successfully so now I can find the application on the device.
So, I will open the Android emulator, open Applications, and here I can find that API demo.
The same is the case for APKInfo.
I can just run:
adb install APKInfo.apk
It succeeded and now we have both applications on the device.
Another way to install is we can use drag and drop.
For example, I can drag and drop the APKInfo.apk
to this Android emulator, and the same for the APIDemos.apk
.
This is also the way that we will install the iOS application.
For example, I will drag and drop the iOS applications into the iOS simulator, and now it is installed and I can open it.
These are the applications that I will use in my demo.
Now, we will learn how we can install our applications to learn what element we will use in our demo.
For example, here we have something similar with UIKit in iOS, including different things for clipboard, views, storage, resources, and everything.
Quiz
The quiz for this chapter can be found in Chapter 4.8