The post Writing Your First Appium Test For iOS Devices appeared first on Automated Visual Testing | Applitools.
]]>This is the third and final post in our Hello World introduction series to Appium, and we’ll discuss how to create your first Appium test for iOS. You can read the first post for an introduction to Appium, or the second to learn how to create your first Appium test for Android.
Congratulations on having made it so far. I hope you are slowly becoming more comfortable with Appium and realizing just how powerful a tool it really is for mobile automation, and that it’s not that difficult to get started with it.
This is the final post in this short series on helping you start with Appium and write your first tests. If you need a refresher on what Appium is and writing your first Android test with it, you can read the earlier parts here:
In this post, we’ll learn how to set up your dev environment and write your first Appium based iOS test.
We’ll need some dependencies to be preinstalled on your dev machine.
Let’s go over them one by one.
Also, remember it’s completely okay if you don’t understand all the details of these in the beginning since Appium pretty much abstracts those details away and you can always dig deeper later on if you need some very specific capabilities of these libraries.
To run iOS tests, we need a machine running macOS with Xcode installed.
The below command would setup Command-line scripts that are needed for us to be able to run our first test:
xcode-select --install
You can think of Carthage as a tool to allow adding frameworks to your Cocoa applications and to build required dependencies:
brew install carthage
libimobiledevice library allows Appium to talk to iOS devices using native protocols:
brew install libimobiledevice
ios-deploy helps to install and debug iOS apps from the command line:
brew install ios-deploy
brew install ios-webkit-debug-proxy
IDB (iOS Device bridge) is a node JS wrapper over IDB that are a set of utilities made by Facebook:
brew tap facebook/fb
brew install idb-companion
pip3.6 install fb-idb
If you are curious, you could read the below reference blogs below that helped me come up with this shortlist of dependencies and are good reads for more context:
For our first iOS test, we’ll use a sample demo app provided by Appium.
You can download the zip file from here, unzip it and ensure you copy it under src/test/resources dir in the project, such that we have a TestApp.app file under the test resources folder.
If you are following these tests along by checking out the GitHub repo appium-fast-boilerplate, you’ll see the iOS app path is mentioned under a file ios-caps.json under src/main/resources/.
This file represents Appium capabilities in JSON format and you can change them based on which iOS device you want to run them on.
When we run the test DriverManager will pick these up and help create the Appium session. You can read part 2 of this blog series to know more about this flow.
{
"platformName": "iOS",
"automationName": "XCUITest",
"deviceName": "iPhone 13",
"app": "src/test/resources/TestApp.app"
}
Our app has a set of UI controls with one section representing a calculator wherein we could enter two numbers and get their sum (see below snapshot):
We would automate the below flow:
Pretty basic right?
Below is how a sample test would look like (see the code here):
import constants.TestGroups;
import org.testng.Assert;
import org.testng.annotations.Test;
import pages.testapp.home.HomePage;
public class IOSTest extends BaseTest {
@Test(groups = {TestGroups.IOS})
public void addNumbers() {
String actualSum = new HomePage(this.driver)
.enterTwoNumbersAndCompute("5", "5")
.getSum();
Assert.assertEquals(actualSum, "10");
}
}
Here, we follow the same good patterns that have served us well (like using Fluent, page objects, a base test, and driver manager) in our tests just as we did in our Android test.
You can read about these in detail in this earlier blog.
The beauty of the page object pattern is that it looks very similar regardless of the platform.
Below is the complete page object for the above test that implements the desired behavior for this test.
package pages.testapp.home;
import core.page.BasePage;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
public class HomePage extends BasePage {
private final By firstNumber = By.name("IntegerA");
private final By secondNumber = By.name("IntegerB");
private final By computeSumButton = By.name("ComputeSumButton");
private final By answer = By.name("Answer");
public HomePage(AppiumDriver driver) {
super(driver);
}
public HomePage enterTwoNumbersAndCompute(String first, String second) {
typeFirstNumber(first);
typeSecondNumber(second);
compute();
return this;
}
public HomePage typeFirstNumber(String number) {
WebElement firstNoElement = getElement(firstNumber);
type(firstNoElement, number);
return this;
}
public HomePage typeSecondNumber(String number) {
WebElement secondNoElement = getElement(secondNumber);
type(secondNoElement, number);
return this;
}
public HomePage compute() {
WebElement computeBtn = getElement(computeSumButton);
click(computeBtn);
return this;
}
public String getSum() {
waitForElementToBePresent(answer);
return getText(getElement(answer));
}
}
Let’s unpack this and understand its components.
We create a HomePage class that inherits from BasePage that has wrappers over Appium API methods.
public class HomePage extends BasePage
We define our selectors of type By, using the Appium inspector to discover that name is the unique selector for these elements, in your projects trying to depend on ID is probably a safer bet.
private final By firstNumber = By.name("IntegerA");
private final By secondNumber = By.name("IntegerB");
private final By computeSumButton = By.name("ComputeSumButton");
private final By answer = By.name("Answer");
Next, we initialize this class with a driver instance that’s passed the test and also its parent class to ensure we have the appropriate driver instance set:
public HomePage(AppiumDriver driver) {
super(driver);
}
We then create a wrapper function that takes two numbers as strings, types numbers in the two text boxes, and taps on the button.
public HomePage enterTwoNumbersAndCompute(String first, String second) {
typeFirstNumber(first);
typeSecondNumber(second);
compute();
return this;
}
We implement these methods by reusing methods from BasePage while ensuring the correct page object is returned.
Since there is no redirection happening in these tests and it’s a single screen we just return this (i.e. the current page object in Java syntax). This enables writing tests in the Fluent style that you saw earlier.
public HomePage typeFirstNumber(String number) {
WebElement firstNoElement = getElement(firstNumber);
type(firstNoElement, number);
return this;
}
public HomePage typeSecondNumber(String number) {
WebElement secondNoElement = getElement(secondNumber);
type(secondNoElement, number);
return this;
}
public HomePage compute() {
WebElement computeBtn = getElement(computeSumButton);
click(computeBtn);
return this;
}
Finally, we return the string that has the sum of two numbers in the getSum() method and let the test perform desired assertions:
public String getSum() {
waitForElementToBePresent(answer);
return getText(getElement(answer));
}
Before running the test, ensure that the Appium server is running in another terminal and that your appium 2.0 server has the XCUITest driver installed by following the below steps
# Ensure driver is installed
appium driver install xcuitest
# Start the appium server before running your test
appium
Within the project, you could run the test using the below command or use IntelliJ or equivalent editors test runner to run the desired test.
gradle wrapper clean build runTests -Dtag="IOS" -Dtarget="IOS"
With this, we come to an end to this short three-part series on getting started with Appium, from a general introduction to Appium to working with Android to this post on iOS. Hopefully, this series makes it a little bit easier for you or your friends to get set up with Appium.
Exploring the remainder of Appium’s API, capabilities and tooling is left as an exercise to you, my brave and curious reader. I’m sure pretty soon you’ll also be sharing similar posts and hopefully, I’ll learn a thing or two from you as well. Remember Appium docs, the community, and Appium Conf are great sources to go deeper into Appium ?.
So, what are you waiting for? Go for it!
Remember, you can see the entire project on Github at appium-fast-boilerplate, clone or fork it, and play around with it. Hopefully, this post helps you a little bit in starting on iOS automation using Appium. If you found it valuable, do leave a star on the repo and in case there is any feedback, don’t hesitate to create an issue.
You could also check out https://automationhacks.io for other posts that I’ve written about Software engineering and Testing and this page for a talk that I gave on the same topic.
As always, please do share this with your friends or colleagues and if you have thoughts or feedback, I’d be more than happy to chat over on Twitter or in the comments. Until next time. Happy testing and coding.
The post Writing Your First Appium Test For iOS Devices appeared first on Automated Visual Testing | Applitools.
]]>The post Writing Your First Appium Test For Android Mobile Devices appeared first on Automated Visual Testing | Applitools.
]]>This is the second post in our Hello World introduction series to Appium, and we’ll discuss how to create your first Appium test for Android. You can read the first post where we discussed what Appium is, including its core concepts and how to set up the Appium server. You can also read the next post on setting up your first Appium iOS test.
In this post, we’ll build on top of earlier basics and focus on the below areas:
We have lots to cover but don’t worry, by the end of this post, you will have run your first Appium-based Android test. Excited? ? Let’s go.
To run Android tests, we need to set up an Android SDK, ADB (Android debug bridge), and some other utilities.
The easiest way to set these up is to go to the Android site and download Android Studio (An IDE to develop Android apps), which will install all the desired libraries and also give us everything we need to run our first Android test.
Once downloaded and installed, open Android Studio, click on Configure, and then SDK Manager. Using this you can download any android API version from SDK Platforms.
Also, You can install any desired SDK Tools from here.
We’ll go with the defaults for now. This tool can also install any required updates for these tools which is quite a convenient way of upgrading.
The Appium server needs to know where the Android SDK and other tools like Emulator, Platform Tools are present to help us run the tests.
We can do so by adding the below variables in the system environment.
On Mac/Linux:
source <shell_profile_file_name>
for e.g. source.zshrc
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$ANDROID_HOME/emulator:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
If you are on Windows, you’ll need to add the path to Android SDK in the ANDROID_HOME variable under System environment variables.
Once done, run the adb command on the terminal to verify ADB is set up:
➜ appium-fast-boilerplate git:(main) adb
Android Debug Bridge version 1.0.41
Version 30.0.5-6877874
Installed as /Users/gauravsingh/Library/Android/sdk/platform-tools/adb
These are a lot of tedious steps and in case you want to set these up quickly, you can execute this excellent script written by Anand Bagmar.
Our Android tests will run either on an emulator or a real Android device plugged in. Let’s see how to create an Android emulator image.
You’ll be greeted with a blank screen with no virtual devices listed. Tap on Create a virtual device to launch the Virtual device Configuration flow:
Next, select an Android device like TV, Phone, Tablet, etc., and the desired size and resolution combination.
It’s usually a good idea to set up an emulator with Play Store services available (see the Play Store icon under the column) as certain apps might need the latest play services to be installed.
We’ll go with Pixel 3a with Play Store available.
Next, we’ll need to select which Android version this emulator should have. You can choose any of the desired versions and download the image. We’ll choose Android Q (10.0 version).
You need to give this image a name. We’ll need to use this later in Appium capabilities so you can give any meaningful name or go with the default. We’ll name it Automation.
Nice, ?We have created our emulator. You can fire it up by tapping the Play icon under the Actions section.
You should see an emulator boot up on your device similar to a real phone.
While the emulator is an in-memory image of the Android OS that you can quickly spin up and destroy, it does take physical resources like Memory, RAM, and CPU. It’s always a good idea to verify your app on a real device.
We’ll see how to set up a real device so that we can run automation on it.
You need to connect your device to your machine via USB. Once done:
And thats all you need to potentially run our automation on a connected real device.
Appium comes with a nifty inspector desktop app that can inspect your Application under test and help you identify element locators (i.e. ways to identify elements on the screen) and even play around with the app.
It can easily run on any running Appium server and is really a cool utility to help you identify element locators and develop Appium scripts.
You can download it by just going to the Appium Github repo, and searching for appium-inspector.
Go to release and find the latest .dmg (on Mac) or .exe (on Windows) to download and install.
On Mac, you may get a warning stating: “Appium Inspector” can’t be opened because Apple cannot check it for malicious software.
To mitigate this, just go to System preferences > Security & Privacy > General and say Open Anyway for Appium Inspector. For more details see Issue 1217.
Once you launch Appium inspector, you’ll be greeted with the below home screen. If you see there is a JSON representation sector under Desired Capabilities section.
Think of them as properties that you want your driver’s session to have. For example, you may want to reset your app after your test, or launch the app in a particular orientation. These are all achievable by specifying a Key-Value pair in a JSON that we provide to the Appium server session.
Please see Appium docs for more idea on these capabilities.
Below are some sample capabilities we can give for Android:
{
"platformName": "android",
"automationName": "uiautomator2",
"platformVersion": "10",
"deviceName": "Automation",
"app": "/<absolute_path_to_app>/ApiDemos-debug.apk",
"appPackage": "io.appium.android.apis",
"appActivity": "io.appium.android.apis.ApiDemos"
}
For this post, we’ll use the sample apps provided by Appium. You can see them here, once you’ve downloaded them. Keep track of its absolute path and update it in-app key in the JSON.
We’ll add this JSON under JSON representation and then tap on the Save button.
It would be a good idea to save this config for the future. You can tap on ‘Save as’ and give it a meaningful name.
To start the inspection session, You need to have an Appium server run locally, run it via typing appium
on the command line:
➜ appium-fast-boilerplate git:(main) appium
[Appium] Welcome to Appium v2.0.0-beta.25
[Appium] Attempting to load driver uiautomator2...
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[Appium] Available drivers:
[Appium] - uiautomator2@2.0.1 (automationName 'UiAutomator2')
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.
Let’s make sure our emulator is also up and running. We can start the emulator via AVD Manager in Android studio, or in case you are more command-line savvy, I have written an earlier post on how to do this via CMDline as well.
Once done, tap on the Start Session button, this should bring launch the API Demos app and show the inspector home screen.
Using this you can tap on any element in the app and see its Element hierarchy, elements properties. This is very useful to author Appium scripts and I’ll encourage you to explore each section of this tool and get familiar since you’ll be using this a lot.
Phew, that seemed like a lot of setup steps but don’t worry, you only have to do this once and now we can get down to the real business of writing our first Automated test on Android.
You can download the project using Github from appium-fast-boilerplate.
We’ll also understand what the fundamental concepts of writing page objects and tests are based on these. Let’s take a look at the high-level architecture.
Before automating any test, we need to be clear on what is the purpose of that test. I’ve found the Arrange Act Assert pattern quite useful to reason about it. Read this post by Andrew Knight in case you are interested to know more about it.
Our test would perform the below:
Let’s start by seeing our test.
import constants.TestGroups;
import org.testng.Assert;
import org.testng.annotations.Test;
import pages.apidemos.home.APIDemosHomePage;
public class AndroidTest extends BaseTest {
@Test(groups = {TestGroups.ANDROID})
public void testLogText() {
String logText = new APIDemosHomePage(this.driver)
.openText()
.tapOnLogTextBox()
.tapOnAddButton()
.getLogText();
Assert.assertEquals(logText, "This is a test");
}
}
There are a few things to notice above:
public class AndroidTest extends BaseTest
Our class extends a BaseTest, this is useful since we can perform common setup and tear down functions, including setting up driver sessions and closing it once our script is done.
This ensures that the tests are as simple as possible and does not overload the reader with any more details than they need to see.
String logText = new APIDemosHomePage(this.driver)
.openText()
.tapOnLogTextBox()
.tapOnAddButton()
.getLogText();
We see our tests read like plain English with a series of actions following each other. This is called a Fluent pattern and we’ll see how this is set up in just a moment.
Let’s see our BaseTest class:
import constants.Target;
import core.driver.DriverManager;
import core.utils.PropertiesReader;
import exceptions.PlatformNotSupportException;
import io.appium.java_client.AppiumDriver;
import org.testng.ITestContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import java.io.IOException;
public class BaseTest {
protected AppiumDriver driver;
protected PropertiesReader reader = new PropertiesReader();
@BeforeMethod(alwaysRun = true)
public void setup(ITestContext context) {
context.setAttribute("target", reader.getTarget());
try {
Target target = (Target) context.getAttribute("target");
this.driver = new DriverManager().getInstance(target);
} catch (IOException | PlatformNotSupportException e) {
e.printStackTrace();
}
}
@AfterMethod(alwaysRun = true)
public void teardown() {
driver.quit();
}
}
Let’s unpack this class.
protected AppiumDriver driver;
We set our driver instance as protected so that all test classes will have access to it.
protected PropertiesReader reader = new PropertiesReader();
We create an instance of PropertiesReader class to read relevant properties. This is useful since we want to be able to switch our driver instances based on different test environments and conditions. If curious, please see its implementation here.
Target target = (Target) context.getAttribute("target");
this.driver = new DriverManager().getInstance(target);
We get the relevant Target
and then using that gets an instance of AppiumDriver from a class called DriverManager.
We’ll use this reusable class to:
package core.driver;
import constants.Target;
import exceptions.PlatformNotSupportException;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import static core.utils.CapabilitiesHelper.readAndMakeCapabilities;
public class DriverManager {
private static AppiumDriver driver;
// For Appium < 2.0, append /wd/hub to the APPIUM_SERVER_URL
String APPIUM_SERVER_URL = "http://127.0.0.1:4723";
public AppiumDriver getInstance(Target target) throws IOException, PlatformNotSupportException {
System.out.println("Getting instance of: " + target.name());
switch (target) {
case ANDROID:
return getAndroidDriver();
case IOS:
return getIOSDriver();
default:
throw new PlatformNotSupportException("Please provide supported target");
}
}
private AppiumDriver getAndroidDriver() throws IOException {
HashMap map = readAndMakeCapabilities("android-caps.json");
return getDriver(map);
}
private AppiumDriver getIOSDriver() throws IOException {
HashMap map = readAndMakeCapabilities("ios-caps.json");
return getDriver(map);
}
private AppiumDriver getDriver(HashMap map) {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities(map);
try {
driver = new AppiumDriver(
new URL(APPIUM_SERVER_URL), desiredCapabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return driver;
}
}
You can observe:
Let’s take a look at the example of a page object that enables a Fluent pattern.
package pages.apidemos.home;
import core.page.BasePage;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import pages.apidemos.logtextbox.LogTextBoxPage;
public class APIDemosHomePage extends BasePage {
private final By textButton = By.xpath("//android.widget.TextView[@content-desc=\"Text\"]");
private final By logTextBoxButton = By.xpath("//android.widget.TextView[@content-desc=\"LogTextBox\"]");
public APIDemosHomePage(AppiumDriver driver) {
super(driver);
}
public APIDemosHomePage openText() {
WebElement text = getElement(textButton);
click(text);
return this;
}
public LogTextBoxPage tapOnLogTextBox() {
WebElement logTextBoxButtonElement = getElement(logTextBoxButton);
waitForElementToBeVisible(logTextBoxButtonElement);
click(logTextBoxButtonElement);
return new LogTextBoxPage(driver);
}
}
Notice the following:
Above is an example page object class:
package core.page;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
public class BasePage {
protected AppiumDriver driver;
public BasePage(AppiumDriver driver) {
this.driver = driver;
}
public void click(WebElement elem) {
elem.click();
}
public WebElement getElement(By by) {
return driver.findElement(by);
}
public List<WebElement> getElements(By by) {
return driver.findElements(by);
}
public String getText(WebElement elem) {
return elem.getText();
}
public void waitForElementToBeVisible(WebElement elem) {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(elem));
}
public void waitForElementToBePresent(By by) {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(by));
}
public void type(WebElement elem, String text) {
elem.sendKeys(text);
}
}
Every page object inherits from a BasePage that wraps Appium methods.
Congratulations, you’ve written your first Appium Android test. You can run this either via the IDE or via a Gradle command
./gradlew clean build runTests -Dtag="ANDROID" -Ddevice="ANDROID"
You can see the entire project on the Github appium-fast-boilerplate, clone it and play around with it. Hopefully, this post helps you a little bit in starting on Android automation using Appium.
In the next post, we’ll dive into the world of iOS Automation with Appium and write our first hello world test.
You could also check out https://automationhacks.io for other posts that I’ve written about software engineering and testing.
As always, do share this with your friends or colleagues and if you have thoughts or feedback, I’d be more than happy to chat over at Twitter or elsewhere. Until next time. Happy testing and coding.
The post Writing Your First Appium Test For Android Mobile Devices appeared first on Automated Visual Testing | Applitools.
]]>The post Hello Appium, Part 1: What is Appium? An Introduction to Appium and its Tooling appeared first on Automated Visual Testing | Applitools.
]]>In the first article in this series, learn how to get started with Appium. We’ll dig into what Appium is, the essentials of the Appium architecture and how you can use Appium to solve your mobile test automation issues today. You can also skip ahead to read about how to set up your first Appium Android test and how to set up your first Appium iOS test.
I recently had the privilege to speak at Appium Conf 2021 on a topic quite near to my heart: Getting started with Appium.
If you are an intermediate or advanced Appium user, then sure, ?? you may be familiar with this already.
However, I’m a fan of a concept called Shoshin (loosely translated as “Beginner’s mind”) and believe that relearning something opens up new ways of solidifying concepts and often enlightens you about the gaps in your knowledge.
When I started learning Appium back in 2018, I remember I had to struggle a lot to figure out where to start, what setups are needed to run my first test, or just even the underlying architecture.
This was a lot of initial friction and I remember thinking to myself:
It shouldn’t be this hard just to get started, eh?
Appium is a great automation tool and now having used it for a few years and having gone through the trenches I wanted to improve this experience for beginners. Hence the reason for my talk and this blog series. If you are curious about the Appium talk, the video is out on YouTube and slides over a static site.
In this 3 part series we’ll deep dive into:
Let’s begin.
Appium is an open source ecosystem of tools and libraries that help you drive your mobile apps (native, hybrid, and mobile web on platforms such as Android, iOS), desktop apps (Windows, Mac), and now even on platforms like Smart TV and much more ?.
Language agnostic: With Appium you can choose the language binding of your choice (Such as Java, Kotlin, Python, JavaScript, Ruby, C# … ?) and don’t have to be tied to the programming language of the platform vendors (Kotlin, Swift, etc.).
Does not reinvent the wheel: Appium provides a convenient API compliant with Web driver protocol that wraps automation libraries from vendors (Google UIAutomator2/Espresso, Apple XCUITest/UIAutomation, Windows WinApp) and allows you to write cross-platform tests.
No requirement of SDK or recompilation of the app: Appium can drive the app from a grey box user perspective but does not need any app compilation step.
Cross-platform: Drives apps on different platforms and provided apps have the same business logic, could drive them with a single cross-platform test.
Before diving into practical setup and tests, it’s important to understand the Appium ecosystem in a birds-eye so that you can make sense of all the different components at play
The below high-level architecture diagram gives the perspective:
The core components are:
A typical request in Appium loosely looks like below:
{
"orientation": "LANDSCAPE|PORTRAIT"
}
Now that we understand the high-level components at play, let’s install some of these to set up our environment regardless of the platform that we choose to automate.
To set up the Appium server and other utilities, we’ll need to install npm, node. These could be easily installed with a tool like homebrew (mac), Linux brew (Linux), or chocolatey (windows)
We’ll assume using a Mac/Linux or WSL (Windows Subsystem for Linux) environment for this series but you’ll be able to find equivalent steps for the Windows platform by googling.
We’ll need it to install npm and node.
To install on macOS:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
On Linux or WSL (Windows Subsystem for Linux), you may need to install Linux brew.
You can download and install node (10+) for your platform. Prefer choosing LTS (Long term support version) since that would be the stable version.
On macOS:
brew install node
Verify running the below command returns desired version:
node -v
And verify that npm is installed as well:
npm -v
To install Appium server < 2.0
npm install -g appium
Verify Appium server is installed by typing appium command in your terminal and see all server logs.
➜ appium-fast-boilerplate git:(main) appium
[Appium] Welcome to Appium v1.17.0
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
Appium 1.2x.x would be the last version supported by Appium devs and an EOL (End of Life) plan is already published on the Appium Github repo. Read it here. Since Appium 2.0 is the future of the project, let’s see how to install the new server and some key commands.
To install Appium 2.0:
npm install -g appium@next
You’ll get an output like:
/usr/local/bin/appium -> /usr/local/lib/node_modules/appium/build/lib/main.js
> appium@2.0.0-beta.16 postinstall /usr/local/lib/node_modules/appium
> node ./postinstall.js
Not auto-installing any drivers or plugins
+ appium@2.0.0-beta.16
added 113 packages from 587 contributors, removed 316 packages, updated 136 packages and moved 5 packages in 81.611s
With Appium 2.0, drivers are decoupled and not bundled into the main server. This makes sense since if your app is only on Android, you wouldn’t need iOS, desktop, and TV drivers anyways right?
We’ll install Android and iOS drivers for this project using the below commands:
appium driver install xcuitest
appium driver install uiautomator2
You can list all available drivers using the command:
appium driver list
Or list only installed drivers using:
appium driver list --installed
After running the appium command, you’ll see an output like this and as you can see our installed drivers:
[Appium] Welcome to Appium v2.0.0-beta.16
[Appium] Non-default server args:
[Appium] tmpDir: /var/folders/5d/flg6q03n3j7769kffzly2x_r0000gp/T
[Appium] Attempting to load driver xcuitest...
[Appium] Attempting to load driver uiautomator2...
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
[Appium] Available drivers:
[Appium] - xcuitest@3.53.1 (automationName 'XCUITest')
[Appium] - uiautomator2@1.67.0 (automationName 'UiAutomator2')
You can install Java from the Oracle site or the OpenJDK version:
On macOS: If you choose to install OpenJDK, then execute the below command:
brew install openjdk@8
sudo ln -sfn /usr/local/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk
Add JDK home path as JAVA_HOME variable. Since we would use the Java client binding for this series, this is a needed step.
export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-8.jdk/Home
export PATH=$JAVA_HOME/bin:$PATH
Appium doctor is a CLI that provides insights on what dependencies are missing as well as how to install them. It even provides very helpful suggestions or notes on how exactly a dependency might be useful.
Make sure all required dependencies are installed:
npm install -g appium-doctor
Run below commands:
# For both android and iOS
appium-doctor
# For only android
appium-doctor --android
# For only iOS
appium-doctor --ios
If I run it at this point in time, it intelligently warns me about the required dependencies that are installed, optional dependencies that could be installed, and how to go about installing them.
So hopefully you are set up with Appium, have a conceptual understanding of the different components, and are now ready to dive into writing our first tests for Android and iOS. Stay tuned for the next part. In the meantime, you can read the below docs to get further context.
Looking for more? We’ve got other great content to help you dig in and get started with Appium. Here are a few places to help you get started with Appium today.
The post Hello Appium, Part 1: What is Appium? An Introduction to Appium and its Tooling appeared first on Automated Visual Testing | Applitools.
]]>