Automating MacOS applications -Part 1

Kasun Wickramarathna
6 min readSep 12, 2022

--

Selenium has been conquering the world as the most popular test automation tool for over a decade, at the time this article is writing.

In the early days, Selenium was only a test automation tool for Web apps, but now it supports automating OS-based applications also. In my previous articles, I presented how to automate Windows-based applications using Selenium APIs.

Moving another step forward, I’m explaining in this article to set up the automation environment in Mac.

I have explicitly tested this installation process with Apple M1 chip computers and is the same process as below;

General system requirements ;

  • macOS Mojave 10.14 or later
  • CPU Intel or M1 chip
  • 8 GB of memory (16 GB preferable)

We are going to use Java as the programming language. First, get started with setting up Java on your Mac !!!

Install JDK 8 or higher and set Java Environment variables

Ensure your Java is setup correctly and the Environment variable is set;

Open Terminal App and execute the following commands one after the other;

javac -version
‘javac -version’ output on Terminal
echo $JAVA_HOME
‘echo $JAVA_HOME’ output on Terminal

Download and Install the Xcode 12 or higher

XCTest is a test framework which comes along with the Xcode. macOS Driver uses the XCTest framework to perform the tests.

Download and install Xcode from App Store (it is already installed, in this case)

Xcode after instllation

Once the installation is over, you must enable Accessibility Access for the Xcode helper app.

Xcode helper app can be found in the following file path on your Mac;

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Agents/Xcode Helper.app

Open the ‘Terminal’ and execute the following command (command to open up the following file path in the Finder application)

open /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Agents/
Xcode Helper app

Open the System Preferences > Security & Privacy. Then Navigate to the ‘Privacy’ tab and select the ‘Accessibility’ option on the left pane.

Drag and drop the ‘Xcode Helper. app’ to the application list.

Xcode Helper app is added to Accessibility

Install the NodeJs

Download and install the latest stable version of NodeJs from; https://nodejs.org/en/download/

If you have already installed Nodejs in your system and its version is old, It’s strongly suggested to upgrade Nodejs, to avoid compatibility/security issues. Else You may skip this step if you have already installed Node in your system.

Download Nodejs

Execute the below command in the Terminal to verify whether the NodeJs installation is successful and its version.

node -v
Node version verification

Update Node package manager (Update npm)

Once verified the Node installation, execute the following command to update to the latest version of npm.

I strongly recommend installing the latest npm, or else you might get incompatibility issues later.

sudo npm install -g npm@latest
npm installation is in progress

To verify whether you have successfully installed the npm latest version, execute the following ;

npm -v
npm installed version verification

So far, we have been preparing Mac for fulfilling the prerequisites for installing Appium. If you get up to this part without any issue, it’s ready to install Appium

Installation of Appium

Note: This is the non-GUI version of the Appium. Starting/Stopping of Appium services will be executed through terminal commands.

We are going to install the Appium 2.0 beta version. There are several reasons to choose the 2.0 -beta version, yet it’s not the right place to discuss it in this article.

At the time of writing this article, Appium 2.0 official version has not been released. However, the beta version is stable enough to develop and execute the day-to-day test scenarios. Hence we are going ahead with it.

Do not get confused with “npm install -g appium”, it downloads and installs the current production version of Appium, which is not the version we want.

Hence, we use the following command to install.

#install appium 2.0 using npm
sudo npm install -g appium@next
Appium installation is inprogress

Once the installation is over, we need to ensure that we have installed the Appium successfully;

#appium version check 
appium -v
#or
appium --version
Appium version verification

Mac2Driver installation

In the earlier versions of Appium, the installation of supporting drivers was executed as part of the Appium installation. Back then, separate Appium driver installation was not necessary. Now with the 2.0 version, all the drivers have been decoupled from the main application. If any driver is required, users need to install it separately. So is the Mac2driver (MacOs driver) in our case.

If you execute the following command, you may start seeing all the drivers installed on Appium 2.0.

#List of drivers in the appium 2.0
appium driver list

If you have not installed any Appium 2.0 driver before, you will get like this output from the Terminal;

Appium driver’s list

Also, you could see each driver’s installation status.

Note: in the event of uninstallation of Appium, these drivers will not be uninstalled as part of the Appium uninstallation process. Hence you may have to uninstall all the drivers separately. Otherwise they will sit on your hard drive as is. to uninstall execute the following command;

#Installation of appium driver
# appium driver install <driverName>
appium driver install mac2

Now let’s install the Mac2Driver executing the following command

#Installation of mac2 driver
appium driver install mac2
Appium mac2driver installation in progress

This driver installation may take a few minutes install. So wait patiently until the installation completes. It should look like the one below once the installation is complete.

mac2driver installation is completed message

To verify your Mac2driver has already is in Appium’s driver list

#Installed appium driver list
appium driver list --installed
Installed all Appium drivers

If you find the mac2driver in Appium installed drivers (as above), then all set. Your Mac is ready to perform the automated tests on OS-based applications !!!

It is the end first article, of the series of articles, regarding performing automated tests on Mac applications. I have explained in detail to set up the Mac environment before we start automating.

The next article of this series will be about how to write the code and execute a test on Mac.

--

--