Logo
  • Home
  • Services
  • Blog
  • Company
Contact Us

Running iOS app test after migrating Appium 1.x to Appium 2.0

Author: Mao TAKAHASHI

Published: June 1, 2023

image

I usually use Appium to create automated tests. One day I found an announcement on Appium's github regarding a release of Appium 2.0, a beta version with the following notes.

appium

appium ⋅ 6 days ago

Appium core team does not maintain Appium 1.x anymore since the 1st of January 2022. All recent versions of officially supported platform drivers are not compatible to Appium 1.x anymore, and require Appium 2 to run. Please read the migration guide from 1.x to 2.0 to manage the Appium server.

Testing app with Appium 1.x is still possible. But in this article I want to share my experience on how I run my test after updating Appium 1.x to Appium 2.0 without significant impact.

Environment

Environment
Version
OS
macOS Ventura 13.4
Programing language
Java 17
Test framework
JUnit 5.8.1
Appium
1.22.3 to 2.0.0-beta.71
Node
v16.15.1
npm
9.6.6
Xcode
14.3
iOS
16.3
io.appium:java-client
8.5.0

Migration Methods

Migration method to Appium 2.0 can also be found in detail in the official documentation. Basically, you can follow the steps mentioned here.

Migrating from Appium 1.x to Appium 2.x - Appium Documentation

The Appium automation project documentation

appium.io

The actual steps that I did are as follows.

** I had previously installed a flutter-driver because I wanted to try it. Because of this, there are some points where my steps are different from the official document method.

appium-flutter-driver

appium ⋅ 7 days ago

# upgrade to appium2.0
$ npm install -g appium@next

# install uiautomator2(for android) and xcuitest(for ios)
$ npm install --global appium --drivers=xcuitest,uiautomator2

# check installed driver
$ appium driver list --installed
✔ Listing installed drivers
- flutter@1.12.0 [installed (npm)]
- xcuitest@4.30.1 [installed (npm)]
- uiautomator2@2.25.1 [installed (npm)]

Execution of this command will complete the update. That is how easy it is to update!

If Appium 2.0 cannot be installed with just this command, please uninstall Appium 1.x. However, npm uninstall command alone might not be able to remove it completely. Make sure that Appium in node_module is completely removed before trying to install Appium 2.0 again.

Building WebDriverAgent

To run iOS app tests, an Apple Developer certificate is required.

If you can build WebDriverAgent successfully, that means you have all the requirements needed to test iOS apps. I suggest building it manually.

**You can also build it using commands. However, there were several times the test was not successful, so I will explain how to build it manually.

  1. Launch WebDriverAgent.xcodeproj in Xcode
  2. In my case, I had previously installed Node with nodebrew, so the xcode project was saved in the following path.

    /Users/(username)/.nodebrew/node/v16.15.1/lib/node_modules/appium-flutter-driver/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj

    Appium’s website, the installation path is shown as $APPIUM_HOME/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent.

    I did not set $APPIUM_HOME value in the environment variables myself. But $APPIUM_HOME was somehow recognized as /Users/(username)/.nodebrew/node/v16.15.1/lib/node_modules/appium-flutter-driver/.

    It is rare to happen, but if WebDriverAgent.xcodeproj cannot be located in the expected location, please try to look in an unexpected location.

  3. Select the Team you want to use under Team in Signing & Capabilities in Xcode
  4. Select [Signing & Capabilities] > select object under [TARGETS] > select the team you want to use from [Team] pulldown. Do the same for all objects under [TARGETS] to avoid rework.

  5. Connect and build your iPhone.
  6. Make sure to enable developer mode on iPhone in advance.

Identify the app bundle ID

Identify the app's bundle ID that you want to test. There are two ways to identify the bundle ID.

Method 1 for apps that were installed from the App Store and Method 2 for otherwise.

Method 1

  1. Search the app from the App Store using Mac.
  2. Note down the id part of the URL.
  3. [Example]

    URL : https://apps.apple.com/jp/app/app-name/id123456789 For this example the id is 123456789.

  4. Open the following URL. https://itunes.apple.com/lookup?id=[id from 2. above]
  5. [Example] https://itunes.apple.com/lookup?id=123456789

    a text file will be downloaded.

  6. Identify the bundle ID from the downloaded file.

Method 2

  1. Connect iPhone to Mac.
  2. Launch "Console," a standard installed utility on Mac.
  3. Launch the app that you want to identify the bundle ID for on iPhone.
  4. Get the bundle ID from the console.
  5. It is easier to locate the information by searching for the app name.

Prepare and run source code

First, launch Appium via terminal.

$ appium server

Next, I will prepare a source code and then run it. Here is the source code that I prepared.

This code will i)launch the iOS Settings app, ii)click on Bluetooth, and iii)go back to the settings page .

By the way, you can find the source code required for launching in the Session Information tab of Appium Inspector 2023.5.2.

You may use those source code after you launch the app in Appium Inspector.

Please note, that the latest version of the library : java_client, does not support MobileElement.

java-client/v7-to-v8-migration-guide.md at master · appium/java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol - java-client/v7-to-v8-migration-guide.md at master · appium/java-client

github.com

java-client/v7-to-v8-migration-guide.md at master · appium/java-client
image

Conclusion

In this article, I explained how to run an iOS app test with Appium 2.0.

Although I did not mention any Appium 2.0 unique features, I hope you can understand how easy it is to migrate from Appium 1.x to Appium 2.0.

Since Appium 1.x will not be updated much in future, it is recommended that you migrate to Appium 2.0 when you have time!

Home

About Us

Services

Blog

Contact Us

Privacy Policy

Cookie

©ARRANGILITY SDN. BHD.

import io.appium.java_client.AppiumBy;
import io.appium.java_client.ios.IOSDriver;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

public class iOSAppSettings {
    private IOSDriver driver;

    @BeforeEach
    public void setUp() throws MalformedURLException {
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability("platformName", "app");
        desiredCapabilities.setCapability("appium:automationName", "XCUITest");
        desiredCapabilities.setCapability("appium:platformVersion", "16.3.1");
        desiredCapabilities.setCapability("appium:bundleId", "com.apple.Preferences");
        desiredCapabilities.setCapability("appium:noReset", true);
        desiredCapabilities.setCapability("appium:udid", "YourUDID");

        driver = new IOSDriver(new URL("http://0.0.0.0:4723/"), desiredCapabilities);
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));

    }

    @Test
    public void TestIOSSettings() throws InterruptedException {
        driver.findElement(AppiumBy.xpath("//XCUIElementTypeStaticText[@name='Bluetooth']")).click();
        driver.findElement(AppiumBy.xpath("//XCUIElementTypeButton[@name='Settings']")).click();
    }

    @AfterEach
    public void tearDown() {
        driver.quit();
    }
}