How to Configure macOS for iOS Mobile App Automation using Appium?

How to Configure macOS for iOS Mobile App Automation using Appium?

iOS App Automation on macOS – Configuring a macOS system for testing on real iOS devices for mobile app automation is a lengthy and complicated process. The steps to follow for this configuration are tricky, and many times testers struggle with it.

The steps involved are installing the right software, setting environment variables, configuring settings on the device, and connecting the devices properly for iOS app automation. This can cause lots of issues in configuration and slow down the testing process.

In this blog, we’ll make this process easy for you to follow.

We’ll walk you through each step, from installing necessary software like the Java Development Kit (JDK) and Xcode, to setting up your iOS device for iOS app automation on macOS.

We’ll also show you how to install Appium, configure it correctly, and use tools like Appium Inspector to interact with your app.

By following this simple guide, you’ll be ready to test your mobile apps on real devices quickly and efficiently for iOS app automation on macOS.

What is Appium testing in iOS App Automation on macoS

Appium is a freely distributed open-source automation tool used for testing mobile applications. It allows testers to automate native, hybrid, and mobile web applications on iOS and Android platforms using the WebDriver protocol. 

Appium provides a unified API (Application Programming Interface) that allows you to write tests using your preferred programming language (such as Java, C#, Python, JavaScript, etc.) and test frameworks. It supports a wide range of automation capabilities and handling various types of mobile elements.
Appium enables cross-platform testing, where the same tests can be executed on multiple devices, operating systems, and versions, providing flexibility and scalability in mobile app testing or iOS testing. It has NO dependency on Mobile device OS; because APPIUM has a framework or wrapper that translates Selenium WebDriver commands into UIAutomation (iOS) or UIAutomator (Android) commands depending on the device type, not any OS type.

Prerequisites for iOS Automation Setup on macOS

  1. JDK Installation 
  2. Install npm and Node.js 
  3. Install Appium Server & Appium Inspector 
  4. Setting up environment variables
  5. Xcode installation and setup
  6. Install XCUITest Driver
  7. Install WebDriverAgent 
  8. Real Device Settings
  9. Get the device-identifier or udid of real device
  10.  Configure the desired capabilities of Appium Inspector
  • 1. JDK Installation:
    Download and Install JAVA JDK for MAC OS (https://www.oracle.com/in/java/technologies/downloads/#jdk21-mac)
    If already installed on the system, please check and confirm using command-
    • java -version
  • 2. Install npm and Node.js:
    Download the Node.js pre-built installer for mac platform and install it. (https://nodejs.org/en/download) If already installed on the system, please check and confirm using the following commands on the terminal.
    • To see if Node is installed, type in node -v .
    • To see if NPM is installed, type in npm -v  
  • 3. Install Appium Server & Appium Inspector:
    Install the Appium via terminal you need to run the below commands:
  • 4. Setting up environment variables:
    Do below settings in .profile file. Open a terminal and type following command-
    • nano ~/.profile
    • Then, paste the below commands: (Change your username!).
    • export JAVA_HOME=$(usr/libexec/java_home)
    • export PATH=$JAVA_HOME/bin:$PATH
  • 5. Xcode installation and setup:
    You can download Xcode from the App Store (https://apps.apple.com/us/app/xcode/id497799835?mt=12 ) to install the command line tools use following command in terminal-
    • xcode-select — install
    • Open Xcode a Preferences -> Accounts -> Add Apple ID
  • 6. Install XCUITest Driver:
    Now we need to install XCUITest driver which allows to interact with the UI elements of iOS apps during automated testing. Use following command in terminal to install XCUITest driver-
    • appium driver install xcuitest
  • 7. Install WebDriverAgent:
    Open Terminal & Run the following command:
    • cd /Applications/Appium-Server-GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitestdriver/appium-webdriveragent
    • To make directory in Resources folder mkdir -p Resources/WebDriverAgent.bundle

How to setup WebDriverAgent on Mac for iOS App Automation

WebDriverAgent is a WebDriver server implementation for iOS that can be used to remote control iOS devices. We need to add an account to XCode (you can use your Apple Id or create new).

For that go to XCode —> Preferences —> Accounts

setup for iOS app automation

Once you are signed in — your account will appear at the left.

We need to add Signing Certificate to this account iOS Automation:

1. Click on Download Manual Profiles
2. Click on Manage Certificates — Plus icon — Apple Development. Once it is done — you will see a new certificate added to the list as per screenshot below

iOS automation account

Open the WebDriverAgent.xcodeproj project in xcode

To find it please use the path:
/Applications/Appium-Server-GUI.app/ Contents/ Resources/ app/node_modules /appium/node_modules/appium-xcuitestdriver/appium-webdriveragent

(NOTE: If you do not see this folder — please use shortkeys “Shift”+”Command”+”.” to display hidden files in your Macintosh HD root)

Click on Project name at the left navigation (WebDriverAgent)

For both the WebDriverAgentLib and WebDriverAgentRunner targets, Go to Signing & Capabilities and Select the Automatically Manage Signing check box select your development team and Select your device. This should also auto select Signing Certificate. The outcome should look as shown below:

automation project in xcode

If the error below appears while changing the Bundle Identifier, we will need to change the  value of Bundle Identifier to something else which xCode can accept.

error in setup

The value for Bundle Identifier should be changed in the following places:

  1. WebDriverAgentLib target:
    • From the Signing & Capabilities tab —change value of Bundle Identifier
    • From Build Settings tab — Packaging section — change value of Product Bundle Identifier
  2. WebDriverAgentRunner target:
    • From Build Settings tab — Packaging section — change value of Product Bundle Identifier
  3. IntegrationApp target:
    • From the Signing & Capabilities tab — change value of Bundle Identifier
    • From Build Settings tab —> Packaging section —> change value of Product Bundle Identifier

After changing the values of Bundle Identifier,
Build the WebDriverAgentLib, WebDriverAgenrRunner, IntegrationApp from WebDriverAgent project in xcode.

  • 8. Now for real device testing
    • we also need to make some changes on device side too so we need to enable  developer option for this:
    • Open settings and click on Privacy and Security-> Developer Option:
real device ios automation
pop-up
  • 9. Get the device-identifier or udid of real device
    • Once the xcode build is succeeded and Developer mode of device is turned on, get the udiid or device-identifier connected to the mac machine from xcode as well as get the bundleId.
    • xcode- windows-Devices and Simulators – check the identifier and other device details, which are required to define capabilities to connect to device either programmatically or through Appium inspector.
device identifier

Get the bundleId from xcode-

  • A bundle ID, also known as a CFBundleIdentifier. It is a unique identifier for an app in Xcode, allowing the system to distinguish it.
  • Bundle IDs are typically written in reverse-DNS format and can only contain alphanumeric characters (A–Z, a–z, and 0–9), hyphens (-), and periods (.). They are also case-insensitive.
  • BundleId is required to define capabilities to connect to the device either programmatically or through Appium inspector.
    For that, from xcode, select the top project item in the project navigator at the left then select TARGETS -> General. Bundle Identifier is found under Identity.

After all the settings, you need to build the xcode project from the Terminal – for that we need to run the following command:
(xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=udid’ test ) from the location where the WebDriverAgent project is present. To go to that location first run the command-

cd /Applications/Appium-Server-GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appiumxcuitestdriver/appiumwebdriveragent

Now run the command with device identifier and WebDriverAgent project location.

(e.g. –
xcodebuild -project /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appiumxcuitestdriver/appiumwebdriveragent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘platform=iOS,id=53e4089fac10d5307c8f0d9a1f35aeb84e89b819’ test)

After the above configurations, Start Appium Server from the terminal.
Start Appium Inspector and set the desired capabilities.

  • 10. Configure the desired capabilities and other settings of Appium Inspector:

Appium inspector is a tool which provides testers with a graphical user interface  for inspecting and interacting with elements within mobile applications.When setting up automation with Appium for ios devices, it’s crucial to define the desired capabilities appropriately. These capabilities act as parameters that instruct Appium on how to interact with the device and the application under test.

Open the Appium Inspector and enter Remote Host as 0.0.0.0 and Remote Port as 4723. and set the following parameters as desired capabilities:

appium parameters for ios automation
  • deviceName: This parameter specifies the name of the testing device. It’s essential to provide an accurate device name to ensure that Appium connects to the correct device. 
  • udid: The Unique Device Identifier (UDID) uniquely identifies the device among all others. Appium uses this identifier to target the specific device for automation. Make sure to input the correct UDID of the device you intend to automate. 
  • platformName: The platform name is set to “iOS,” indicating that the automation targets the iOS platform.
  • platformVersion: This parameter denotes the version of the ios platform of the device. 
  • automationName: Appium supports multiple automation frameworks, and here, “XCUITest” is specified as the automation name. XCUITest is a widely used automation framework for testing iOS apps. 
  • bundleId: This unique identifier for an app in Xcode allows the system to distinguish it.

Once you set all the above capabilities, click the Start Session button to open the application in Appium Inspector with the specified capabilities. Your app is now ready for inspection to prepare for efficient automation testing.

automation testing

also you can see the following image on your device’s screen:

Automation running

Conclusion

Setting up Appium for testing on real iOS devices can initially seem complicated due to the numerous steps involved and the technical nuances of configuring software and environment variables. However, by following this step-by-step guide, the process becomes easy and manageable.

Having the right tools and configurations in place streamlines your testing workflow, ensuring efficient and effective testing of your mobile apps on real devices. This not only improves the quality of your apps but also enhances your overall development process.

Remember, the key to successful automation testing is meticulous setup and configuration. By taking the time to follow each step carefully, you will save yourself from potential issues down the line and make your testing process smoother.

Click here to read more blogs like this.

Effective Locator Strategy for Mobile App Automation using Appium

Effective Locator Strategy for Mobile App Automation using Appium

Introduction:

Mobile App Automation using Appium involves various ways to locate elements for effective testing. In this blog, we’ll se the Mobile app automation Using Appium Inspector, we can inspect elements on both iOS and Android devices.

Now we’ll go for locating the Android Element

  • Mobile App Testing tools are available in the market right now are as follows:
    • Katalon
    • Appium
    • Espresso
    • XCTest
    • Robotium
    • Selndroid
    • Flutter
    • Robot Framework
    • iOS-driver
    • Xamarin

So currently we are going to Inspecting the Locator Strategy for Mobile App Automation using Appium, For the initial setup of Appium for Android device you can refer this blog How To Configure Our System For Real Mobile App Automation. This  blog will guide you for the mobile app automation using Appium setup on Android device.

We have various ways to locate the elements for mobile app automation using Appium Inspector, mainly we have the following ways to locate the elements:

  • Id
  • Xpath
  • Customized Xpath
  • Accessible Id

First, we’ll see how to locate the specific element for Mobile App Automation using Appium

After starting the session on an Android phone you will see the below Appium inspector window

Mobile App Automation - 1

In this image, you can see the mobile screen, App source, and Selected Element tabs.

When you select the particular element on the mobile screen displayed on Appium Inspector, You will see the below image, I have selected the C button from a calculator for mobile app automation using appium.

Mobile App Automation using Appium - 2

Now we can see the DOM content is loaded in the App Source tab, and the Attributes and values will be displayed in the Selected Element tab.

Now we’ll see how to locate the element from the Selected Element tab.

Select Element

In the above image you can see the attribute and values to locate the element

Now we can see the Locator strategies to locate this element for mobile app automation using appium. First, we’ll see locating the element using the Id

First, we’ll have to see the available Attributes for that particular element and then try to locate the element. So copy the ID from given Selected Element tab as shown below

Copied-id

So now We’ll see how to check whether the Id is a valid locator or not.

  • For that first click on the Search bar
Search Bar
  • Then make sure you have selected the correct locator Strategy as shown in the below image.
search for element
  • Now after clicking on the search element, you will get to see the identified element as shown in the below image
Mobile App automation using appium. -3
  • As the element is getting highlighted it indicated that we can use that ID to locate that particular element

Now we’ll see locating elements using XPath for Mobile App Automation using Appium

In a similar way to Id we can locate the element using Xpath, So for first we need to click on the Xpath shown in the below image.

Mobile App Automation using Appium-4

Now click on the search button explained above

XPath

Make sure that you have selected the XPath as Locator Strategy as shown. Then Paste the copied XPath in the Selector Box and click on the Search Button, so then you can see the below image the element is located by the XPath

Locate XPath

The element is getting highlighted and that means we can use this XPath to locate this element

Now we’ll see how to use customized XPath for Mobile App Automation

This allows us to handle parameterization and overcome limitations when ID or XPath is not available by default. So for that, we need to know how we can create XPath

  • The first step is you need to find the class for that particular element
Mobile App AUtomation-5
  • As you can see the above image, class is present for that particular element. So first step is we need to copy this class value
  • The next step is to choose the attribute you want to use the value of.
Mobile App Automation-6
  • These are the various attributes you can use to customize XPath
  • So after that, you can create the Customized XPath, So here is a sample XPath I have used to locate the equal button from the Calculator app
  • In this XPath, I have chosen text attribute. So in the below image, you can see the combination of class and attribute and value. This is how we can create customized XPath
XPath Mobile App Automation
  • As shown in the below image you can see the Located element
Located Elements
  • So when the requirement is there to create a parameterized locator or ID is not available, at that time you can use Customized XPath

For accessibility Id you can follow similar steps like ID to locate the element. The only condition is Accessibility ID should be available for that particular element

Now we’ll go for locating the iOS element for Mobile App Automation using Appium

For iOS automation We’ll be going to see how we can locate the element. To locate elements on iOS devices following strategies are available

  • Accessibility Id
  • XPath
  • Customized XPath

Now we’ll see how to locate the element using Accessibility ID on iOS device.

For that, we’ll have to start the Appium Session on iOS. After starting the Appium session on iOS device you  will get to see the below window of Appium inspector

Appium Inspector

This will be the home page of the calculator on the iOS App. On this screen, you can see three windows Mobile screen, App Source, and Selected  Element. When you select any of the elements displayed on the Mobile screen the screen will be shown below.

Mobile Screen

In the above Image, I have selected the AC button which is for All Clear. After selecting that element the DOM content is loaded in the App Source window and in the Selected Element window we can see the attributes and values that can be used for inspecting the elements.

We have so many options to locate the element as you can see in the Selected Element window. We have accessibility ID, XPath, and customized XPath for Mobile App Automation using Appium.

Now we’ll see how to locate the element using accessibility id for Mobile App Automation using Appium

So first we’ll go to search for element as shown in the below image

Element Search

As shown in the above image you can see that I have selected Locator Strategy as the Accessibility ID and the value I have passed the accessibility ID got from the Selected Element window. Now, I’ll click on the Search button.

The system will display the result window below.

Search Button

As shown in the screenshot, the AC button is highlighted after successfully finding the window element. The count for the found element is 1, and you can use this accessibility ID to locate this specific element.

Note: So for locating the elements using XPath and customized XPath you can refer the steps mentioned for Android.

  • Preffered Locator Strategy: As you can see the Selected element window, We have multiple options to locate the element for Mobile App Automation. So there might be a confusion to select the correct locator strategy. So here are some key points which you can consider while choosing the locator strategy
    • Most preferred locator strategy will be id (Android) or accessibility id (iOS). Because id’s are designed to be unique for direct access.
    • name locator strategy can be used if the particular element have the unique name which can be used to locate element.
    • The XPath are more likely to use if id not available or we have requirement to create locator which needs to be parameterized.

Conclusion:

As we see, we have multiple ways to locate the elements on the Mobile Application. Here in this blog, we got to know the the locator strategies to locate the elements on Android and iOS Application for Mobile App Automation using Appium. So you have multiple options to locate the elements, From which you have to decide which strategy suits best for your requirements. So as mentioned above id is fastest way to locate elements, But you have choice to use XPath and customized XPath for parameterization. https://github.com/appium/appium-inspector/releases

Overall, this blog provides an overview of how to locate elements Mobile App Automation using Appium Inspector. Additionally, it explains the various locator strategies you can choose based on the requirements of your test script.