In this blog, I am sharing my experience of exploring Appium on iOS when I migrated to it from Selenium Webdriver. Mobile automation poses different types of challenges in comparison to the automation of Web browsers. In this blog, I will be exploring a few interesting challenges that I faced while doing iOS App automation.
First let’s see why automating mobile apps is important:
Now let’s try to launch an iOS app through code. In the Appium 3.2 Java client, there is a provision to start/stop the Appium server programmatically through code. Let’s look into it:
In order to run this code snippet without any errors, I need to have the following jar files in my buildpath:
Now, I will be discussing some challenges and findings that I came across while automating an iOS app.
Scrolling is one of the important functions that we need to perform when we are using or manually testing an app. Appium has given this functionality to make our mobile test automation suite more robust.
So, let’s explore how scrolling is implemented in an iOS app for different scenarios:
Scrolling can be performed on UIATableViews. So, in order to use the scrollTo() or scrollToExact() methods, we need to find the required UIATableView because it has UIATableCells that we need to scroll down to.
This is how our screen appears when we navigate to it.
When we execute the scrollTo() method, it puts focus on that element where “THE PURSUIT” text is found first. So in the above figure, the focus is on the first cell having “THE PURSUIT” text.
After the scroll and click operation is performed.
In the above method, we have successfully scrolled and clicked on the element with “THE PURSUIT” text. But if we want to click on the second cell with “THE PURSUIT” text, that approach won’t work. Therefore, in order to do this we need to consider indexes while performing scrolling.
We will be clicking the second element with the text “THE PURSUIT.”
Here we have successfully clicked on the second element with the desired text. We have made the scrolling operation dynamic by considering indexes.
Appium has the capabilities to perform geolocation testing. So, we will see different variations of it.
In order to set the simulator to a specific country, we can send this information with the “locale” capability provided by Appium.
But when we try to start iOSDriver with the “locale” capability, an error is shown, as given below, and execution halts.
(Original error: Appium was unable to set locale info: Error: Settings file /Users/Administrator/Library/Developer/CoreSimulator/Devices/BAD846F7-14D4-4704-A299-E6BD05FFFDC5/data/Library/Preferences/.GlobalPreferences.plist did not exist)","origValue":"Appium was unable to set locale info: Error: Settings file /Users/Administrator/Library/Developer/CoreSimulator/Devices/BAD846F7-14D4-4704-A299-E6BD05FFFDC5/data/Library/Preferences/.GlobalPreferences.plist did not exist"},"sessionId":null} info: <-- POST /wd/hub/session 500 31292.624 ms - 562
So in order to perform geolocation testing, we will be setting the latitudes, longitudes, and altitudes of a particular region using the Location object provided by Selenium Webdriver API.
This way we can set the simulator to a specific region within a country with some precision. This is a much better workaround to perform geolocation testing because an exact region can be set. However, there is no method to fetch the location set by setLocation() method. If we do Locale.getDefault(), we will be getting our System’s locale, whereas the Simulator’s locale has been changed programmatically. Once the location is set correctly, the simulator’s maps can manually verify it.
It is not possible to access images embedded in Table Cells. Let’s take a scenario where there is a star icon on the app and I need to verify that it toggles when clicked. So, when I inspect this star icon, I see that it is embedded in table cell; therefore, it can’t be accessed because there is no UIAImage element present. In the below screenshots, the star icon is toggled but the properties are exactly same. In comparison, in the case of the checkbox, the “value” property gets changed to 1 when checked.
In order to inspect elements in a Webview opened in an iPhone/simulator, we should be able to see its DOM. These are the steps to see an iPhone/simulator’s DOM on the Safari browser.
Enable Web Inspector in iPhone/simulator
After enabling Web Inspector, the Webview can be seen in the Safari browser as explained above.
Dragging images to a certain level with precision is another challenge that I faced while automating an iOS app.
Let’s take a scenario where I have an image that shows different results when dragged to different levels. To do this, I have made use of the UI Automation library’s dragInsideWithOptions(startOffset, endoffset).
Below is the screen appearance when I navigated to the image. The image is present in the center and can be dragged to see different results. To do this, I made use of the x and y offsets.
When image is in the center, the x offset = 0.5 and the y offset = 0.5. Now I intend to move the image on the y-axis to see varied results. In a similar manner, the x offset can also be moved.
Let’s see what happens when the y offset moves from 0.5 to 1.0.
Let’s see what happens when the y offset is moves from 0.5 to -0.5.
Page indicators are used to implement pagination in an iOS app. Let’s take a scenario where some new features are added in an app and page indicators are added to inform users about those new features. Page Indicators move when a user swipes it to see the next one. Performing the swipe precisely is a bit difficult using the swipe() method, So its workaround is to find UIAPageIndicators and perform the click operation on it.