Appium is an open-source and free-to-use mobile automated testing framework that consists of an Appium server. It can be run from the command line, or it's also available as a desktop app. Appium supports a variety of programming languages for writing test cases. Once written, the automated tests are run on connected devices or simulators. All of this is covered well in our post titled "Appium Architecture, Explained."
And Appium comes with a lot of features and additional tools to add to its functionality. These tools include Appium Doctor and Appium Inspector.
Today, we're going to learn to set up Appium on macOS. We'll write automated tests in Java in Eclipse IDE. Finally, we'll run the test cases on an iPhone simulator. A Mac is required to develop iOS apps and run iOS simulators. Android apps can be created and tested on Windows system. Refer to our earlier post of testing with Python and Testing React Native app to learn about Android testing.
We need to do the proper setup even before running our tests on Mac. Here, we're first checking if Java is properly installed on the system by giving commands on the terminal.
We should also have Node.js and npm installed on the system. If you don't have them installed, you can install Node.js from this link.
Xcode is required to run iOS apps, which can be installed from the App Store on Mac. Besides this, we also need Xcode command line tools. And we can install it with the command xcode-select --install.
Now, we need to have an Apple ID set in Xcode. So, open Xcode and click on Preferences.
Here, I already have an account added. If you don't have an account added, you can add one by clicking on the plus sign on bottom-left corner of the screen.
The package Carthage is also required for Appium to run. We can install it using Homebrew, the package manager for macOS, by running the command brew install carthage.
Xcode Setup for Appium
We need to have the Appium Server package or desktop app installed on our macOS system. You can install it with this command:
sudo npm install -g appium
You can also install the desktop app from the Appium site for macOS. Since we've installed Appium Server using npm, we need to go to the below path and open the WebDriverAgent.xcodeproj with Xcode:
In Xcode, click on Window and then on Devices and Simulators. Here, in a new pop-up we'll get all the devices. Note down the different parameters from the simulator you intend to run the application on.
Open the newly created NewIosTest.java. Here, we've imported the required packages first. Then, from the main() method, we're calling the newTest() method. Inside newTest(), we have to give the desired capabilities first for Appium. Here, we've given the device name, platform name, and platform version from the earlier step.
We'll be running our simple test on Safari, so we'll give the capability type as well. After that, we've given the URL for the Appium Server. We're connecting to the iOS driver by passing the URL and capabilities.
Running Test Cases
To run the test cases, we should have Appium Server running. Since we've configured Appium from a Node.js package, we'll run Appium from the terminal.
Now, we've added a log. Right-click on the code System.out.println("Started the Application");. Then, run it as a Java application.
Since everything was set up correctly, we'll get the correct logs. Also, the mobile Safari app will open automatically on our connected mobile device.
In this post, we've set up Appium on a macOS machine. Then, we set up Xcode for Appium. Finally, we've created our automated test in Java using Eclipse IDE and ran it successfully in iOS simulator.
This all seems to be very complicated. So, we can just get the APK or IPA file and try Waldo. APK files are the file for the app which is deployed in Android Play Store. And IPA file is deployed in Apple App Store. Most of the time testers gets this file to test the app instead of the code.
With Waldo we can avoid writing test cases and learning a new language like Java in the process. So, start a free trial!