Author: Mao TAKAHASHI
Published: June 1, 2023
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 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.
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.
# 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.
- Launch
WebDriverAgent.xcodeproj
in Xcode - Select the Team you want to use under Team in Signing & Capabilities in Xcode
- Connect and build your iPhone.
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.
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.
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
- Search the app from the App Store using Mac.
- Note down the id part of the URL.
- Open the following URL. https://itunes.apple.com/lookup?id=[id from 2. above]
- Identify the bundle ID from the downloaded file.
[Example]
URL : https://apps.apple.com/jp/app/app-name/id123456789 For this example the id is 123456789.
[Example] https://itunes.apple.com/lookup?id=123456789
a text file will be downloaded.
Method 2
- Connect iPhone to Mac.
- Launch "Console," a standard installed utility on Mac.
- Launch the app that you want to identify the bundle ID for on iPhone.
- Get the bundle ID from the console.
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 .
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();
}
}
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
.
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!