Translation of the Appium Essentials book. Chapter 2
- Tutorial
Hey. We continue to translate the book on Appium. Ahead, in my opinion, is the most boring, but nevertheless, necessary chapter - it tells how to deploy all the necessary environment on your machine. From installing the JDK to creating a JAVA project in the IDE.
If you missed: Chapter 1 , and here - Chapter 3
Let's go
Today, in the world of mobile development, a lot of things are happening and we need testing to meet user expectations. Advancement in mobile development contributes to advances in test automation for mobile applications. Dan Cuellar came up with the brilliant idea of integrating tools with Selenium. After, he created Appium. Appium is a good and widely used tool for automating mobile applications. The best part is the open source project.
In this chapter:
Appium is an open source project for automating mobile applications: native, web-based and hybrid, developed for Android, iOS and Firefox OS.
Before talking about the advantages of Appium, let's look at its disadvantages:
Now, let's discuss the benefits of Appium, based on its philosophy. The philosophy of Appium is different from the philosophy of competitors. Formally, the philosophy is as follows:
Appium uses the existing infrastructure provided by the [iOS, Android] provider, which meets the first requirement, so we do not need to embed third-party code in the application under test. This allows us to test the same application [even the same assembly], which we will place in the marketplace.
If we talk about the second requirement, Appium extends the WebDriver client libraries, which are already written in popular programming languages. So we are free to choose a language for test development.
Appium extends the existing WebDriver JSONWP with additional API methods that are suitable for mobile automation. So Appium has the same standard as WebDriver and there is no need to revise the approach to automation, which, in turn, meets the third requirement.
Last but not least, Appium is an open source project.
The tool provides a cross-platform solution for native and hybrid applications. This means that the same test cases will work on several platforms. If you are already familiar with Selenium WebDriver, then Appium will seem familiar to you, otherwise, it is recommended that you first study WebDriver for a better understanding. Appium uses the same scripts as WebDriver. Also available is cloud testing; You can run your tests on cloud services such as Sauce Labs and Testdroid. They provide services for running tests on real devices and simulators.
All these advantages make Appium superior compared to other automation tools. The following table shows the advantages of Appium over its competitors, based on the philosophy described above:
We read about Appium; It's time to find out the system requirements for Android / iOS.
In the next section, we will see how to install different software, mentioned above.
To get started with Appium, we need to install some software.
The requirements are as follows:
To install the JDK, you need to click on the link . After installing the JDK, you need to set the environment variables:
[The rest of the book tells how to register JAVA_HOME ].
You must also add the value "% JAVA_HOME% \ bin" to the PATH variable. [You can verify that everything worked out by writing the following command in cmd:
Android SDK can be downloaded on the official website for your OS.
[The ANDROID_HOME variable is set in the same way as JAVA_HOME. As a value, the path to the directory where the Android SDK is installed is passed. In the PATH variable, add the values "% ANDROID_HOME% \ tools;% ANDROID_HOME% \ platform-tools". Next, you will need to run Android Studio. Go to Tools → Android → SDk Manager in the menu. Download platforms of interest (SDK Platforms tab) and tools (SDK Tools tab)].
[I suspect readers have less user experience with Macs than with Windows. Like mine, for example. Therefore, here, perhaps, I will describe in detail].
If you set the variables for the first time, you need to create
Now, we have the bash_profile file. To specify the paths to the Java and Android SDK, you need to set the variables JAVA_HOME and ANDROID_HOME and bash_profile. In the file we write:
The contents of the file must be saved.
After these steps are completed, you can write in the terminal
We will need:
To start Xcode, you can go to the Applications folder and then double-click on the Xcode icon.
Homebrew is a package manager for Mac that is used to install different packages that Apple did not install. With Homebrew, you can install dozens of open source tools. To install Homebrew, do the following:
npm - Node.js package manager, open source Node.js project online repository. Command line utility for installing packages. Appium server is written in NodeJS; that's why we need npm - to download Appium. There are other ways to download Appium, which we will talk about later.
Let's put Node using brew commands:
You can download Appium from the official website , or download it from the repository: github.com/appium/appium.git .
To make sure that everything is installed and configured correctly, run the command line:
You don’t even have to download NodeJS - it comes bundled with Appium. If the node command is not recognized, set the PATH variable to the path to the NodeJS directory (for example, C: \ AppiumForWindows \ node_modules \ appium \ bin).
You can download it from the site, or you can use npm. Run the command in the terminal:
After installation, run [in the same place, in the terminal] appium-doctor to make sure everything is configured correctly.
You need to download some libraries to work with Appium:
Now let's see how emulators and simulators are created. Let's start with the iOS simulator, and then move on to the Android emulator.
On a Mac, we don’t need to create a simulator: we already installed it by installing Xcode. When you launch the Appium server for the first time, it will prompt you to authorize the use of tools. Or, if you run through npm, run
A virtual device [AVD] can be created in two ways:
Let's create an AVD through the command line:
You can customize AVD using different command line options; more information on the site . The link may be out of date. If it’s out of date, google “avds command line”.
Now let's try to create AVD using the AVD Manager (it can be found in the Android SDK folder):
After completing these steps, you will see your emulator in the list of available ones.
To write test cases, we need an IDE. There are many open source IDEs on the market today, such as Eclipse, NetBeans, IntelliJ IDEA, and others. We will use the Eclipse IDE [well, here you go! Below I will describe the project setup in IntelliJ IDEA]. If you downloaded Android ADT, then you already have Eclipse. If anything, you can always download from the site.
Launch the IDE by double-clicking on the eclipse.exe icon. After that, to configure the Java project, you will need to perform the following steps:
We created the project and added all the necessary JAR files. We will also use TestNG. We need to install the TestNG plugin for Eclipse:
Now we are ready to write the first Appium test.
Here on this positive note, the author completes the chapter.
PS:
In the next chapter, we will look at the Appium GUI.
If you missed: Chapter 1 , and here - Chapter 3
Let's go
Today, in the world of mobile development, a lot of things are happening and we need testing to meet user expectations. Advancement in mobile development contributes to advances in test automation for mobile applications. Dan Cuellar came up with the brilliant idea of integrating tools with Selenium. After, he created Appium. Appium is a good and widely used tool for automating mobile applications. The best part is the open source project.
In this chapter:
- Benefits of Appium
- System Requirements for Android / iOS
- Installation of different software
- Creation of emulators and simulators
- Setting up a Java project in Eclipse
Appium Pros and Cons
Appium is an open source project for automating mobile applications: native, web-based and hybrid, developed for Android, iOS and Firefox OS.
Before talking about the advantages of Appium, let's look at its disadvantages:
- There is no implementation of working with Android Alert: handling pop-up dialogs in native applications has not yet been implemented through the Alert API, but there is an alternative way to work with alerts, which we will discuss in Chapter 7 (Advanced User Actions). We hope that work with dialog boxes will be implemented soon.
- Limited support for Android versions: Appium directly supports versions of Android 17 and higher, but if we want to work with versions older, we need to use the integratedSelendroid.
- No image recognition: there is no way to localize images on the page; in order to work with images, we will have to work with the coordinates on the screen, which is not the best practice, but the development plans of the tool have the ability to work with images.
- Gesture support: support for some gestures is not yet implemented, for example, the java library does not double-click, but it is in other libraries. As before, we hope that it will be realized in the near future.
Now, let's discuss the benefits of Appium, based on its philosophy. The philosophy of Appium is different from the philosophy of competitors. Formally, the philosophy is as follows:
- No need to recompile or complement your application to automate it
- The user should not be tied to a specific programming language for writing tests
- The user should not reinvent the wheel when it comes to the framework [apparently, this refers to the practice of working with Selenium]
- The solution must be open source, both in spirit and in practice.
Appium uses the existing infrastructure provided by the [iOS, Android] provider, which meets the first requirement, so we do not need to embed third-party code in the application under test. This allows us to test the same application [even the same assembly], which we will place in the marketplace.
If we talk about the second requirement, Appium extends the WebDriver client libraries, which are already written in popular programming languages. So we are free to choose a language for test development.
Appium extends the existing WebDriver JSONWP with additional API methods that are suitable for mobile automation. So Appium has the same standard as WebDriver and there is no need to revise the approach to automation, which, in turn, meets the third requirement.
Last but not least, Appium is an open source project.
The tool provides a cross-platform solution for native and hybrid applications. This means that the same test cases will work on several platforms. If you are already familiar with Selenium WebDriver, then Appium will seem familiar to you, otherwise, it is recommended that you first study WebDriver for a better understanding. Appium uses the same scripts as WebDriver. Also available is cloud testing; You can run your tests on cloud services such as Sauce Labs and Testdroid. They provide services for running tests on real devices and simulators.
All these advantages make Appium superior compared to other automation tools. The following table shows the advantages of Appium over its competitors, based on the philosophy described above:
Tool | T1 | T2 | T3 | T4 |
Calabash | - | - | - | + |
iOS driver | + | + | + | - |
Robotium | - | - | + | - |
Selendroid | - | + | + | - |
Appium | + | + | + | + |
System Requirements for Android / iOS
We read about Appium; It's time to find out the system requirements for Android / iOS.
Requirements for testing Android on Windows and Mac
- Java (version 7 and higher)
- Android SDK API (version 17 and higher)
- Android Virtual Device (AVD) [emulator is at least available after installing Android Studio] or a real device
Requirements for iOS:
- Mac OS X 10.7 and later
- Xcode (4.6.3 and later; 5.1 recommended) with command-line build tools
- Java (version 7 and higher)
- Homebrew
- NodeJS and npm
In the next section, we will see how to install different software, mentioned above.
Installation of different software
To get started with Appium, we need to install some software.
Installing Appium for Android
The requirements are as follows:
- JDK (Java development kit)
- Android SDK (Software development kit)
- Appium for different operating systems
Install JDK on Windows
To install the JDK, you need to click on the link . After installing the JDK, you need to set the environment variables:
[The rest of the book tells how to register JAVA_HOME ].
You must also add the value "% JAVA_HOME% \ bin" to the PATH variable. [You can verify that everything worked out by writing the following command in cmd:
echo %JAVA_HOME% //выведется добавленное содержимое
echo %PATH% //значение должно будет содержать текст из %JAVA_HOME% + "\bin"
]Install Android SDK
Android SDK can be downloaded on the official website for your OS.
[The ANDROID_HOME variable is set in the same way as JAVA_HOME. As a value, the path to the directory where the Android SDK is installed is passed. In the PATH variable, add the values "% ANDROID_HOME% \ tools;% ANDROID_HOME% \ platform-tools". Next, you will need to run Android Studio. Go to Tools → Android → SDk Manager in the menu. Download platforms of interest (SDK Platforms tab) and tools (SDK Tools tab)].
Setting environment variables for Mac
[I suspect readers have less user experience with Macs than with Windows. Like mine, for example. Therefore, here, perhaps, I will describe in detail].
If you set the variables for the first time, you need to create
.bash_profile
file:- Open terminal
- Type
touch ~/.bash_profile
and press Enter. - Type
open ~/.bash_profile
and press Enter. The .bash_profile file will open
Now, we have the bash_profile file. To specify the paths to the Java and Android SDK, you need to set the variables JAVA_HOME and ANDROID_HOME and bash_profile. In the file we write:
- export JAVA_HOME = path / to / the / java / home
- export ANDROID_HOME = path / to / the / android / sdk
- export PATH = $ PATH: $ ANDROID_HOME / tools: $ ANDROID_HOME / platform-tools
The contents of the file must be saved.
After these steps are completed, you can write in the terminal
java –version
to verify the installation of the path to Java.Appium for iOS
We will need:
- Xcode
- Homebrew
- Node and npm
Install Xcode
- We go to the site . Click on the button “View in Mac App Store”.
- The system will launch the App Store automatically on your Mac and open the Xcode page.
- Click on the “Free” button, and then on the “Install App” button.
To start Xcode, you can go to the Applications folder and then double-click on the Xcode icon.
Install Homebrew
Homebrew is a package manager for Mac that is used to install different packages that Apple did not install. With Homebrew, you can install dozens of open source tools. To install Homebrew, do the following:
- Open the terminal and write:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Next, follow the instructions displayed in the terminal.
- After installing Homebrew, we execute the command
brew doctor
. You should receive the message "Your system is ready to brew"; if not, try fixing the issues that brew doctor points out.
Node and npm
npm - Node.js package manager, open source Node.js project online repository. Command line utility for installing packages. Appium server is written in NodeJS; that's why we need npm - to download Appium. There are other ways to download Appium, which we will talk about later.
Let's put Node using brew commands:
brew install node
Appium for Windows
You can download Appium from the official website , or download it from the repository: github.com/appium/appium.git .
To make sure that everything is installed and configured correctly, run the command line:
node Appium-doctor
[if something is missing, the utility will report this and give tips on how to fix the situation]. You don’t even have to download NodeJS - it comes bundled with Appium. If the node command is not recognized, set the PATH variable to the path to the NodeJS directory (for example, C: \ AppiumForWindows \ node_modules \ appium \ bin).
Appium for Mac
You can download it from the site, or you can use npm. Run the command in the terminal:
npm install –g appium
After installation, run [in the same place, in the terminal] appium-doctor to make sure everything is configured correctly.
Download the necessary JAR files
You need to download some libraries to work with Appium:
Creation of emulators and simulators
Now let's see how emulators and simulators are created. Let's start with the iOS simulator, and then move on to the Android emulator.
IOS simulator
On a Mac, we don’t need to create a simulator: we already installed it by installing Xcode. When you launch the Appium server for the first time, it will prompt you to authorize the use of tools. Or, if you run through npm, run
sudo authorize_ios
to work with the simulator.Android emulator
A virtual device [AVD] can be created in two ways:
- Through the command line;
- Using AVD Manager.
Let's create an AVD through the command line:
- Open a command prompt and write
android list targets
. A list of available platforms is displayed. - The next team .
android create avd –n
-t --abi
You can customize AVD using different command line options; more information on the site . The link may be out of date. If it’s out of date, google “avds command line”.
Now let's try to create AVD using the AVD Manager (it can be found in the Android SDK folder):
- Double-click on AVD Manager. press the New button {write, as through Android Studio}
- Specify the name of the emulator [arbitrary] and set the necessary parameters
- Click Ok
After completing these steps, you will see your emulator in the list of available ones.
Setting up a Java project in Eclipse
To write test cases, we need an IDE. There are many open source IDEs on the market today, such as Eclipse, NetBeans, IntelliJ IDEA, and others. We will use the Eclipse IDE [well, here you go! Below I will describe the project setup in IntelliJ IDEA]. If you downloaded Android ADT, then you already have Eclipse. If anything, you can always download from the site.
Launch the IDE by double-clicking on the eclipse.exe icon. After that, to configure the Java project, you will need to perform the following steps:
- At startup, the IDE will ask you where the [Workspace location] folder will be located. Specify a convenient path and click Ok
- On the welcome screen, click the Workbench icon [in the upper right corner].
- Create a new project. This can be done via the File | New | Project
- В открывшемся окне, выбрать в папке Java тип проекта Java Project и нажать Next
- Указать имя проекта [Project name], кликнуть на Use a project specific JRE и нажать Finish
- Вы создали проект. Теперь создайте пакет: правой кнопкой по папке src [в обозревателе проекта], в контекстном меню — New | Package. Указать имя пакета. Например, «com.example.appium». Затем нажать Finish.
- В созданном пакете создаем класс: правой кнопкой по пакету com.example.appium. В контекстном меню — New | Class и указать имя класса, например, FirstScript. Затем нажать Finish.
- В созданном пакете создаем класс: правой кнопкой по пакету com.example.appium. В контекстном меню — New | Class и указать имя класса, например, FirstScript. Затем нажать Finish.
- Перед тем, как писать тест, нужно добавить несколько JAR-файлов. Правой кнопкой по проекту. В контекстном меню — Build Path | Configure Build Path. Eclipse откроет диалоговое окно. Выберите вкладку Libraries и нажмите Add External JARs...
- Выберите JAR-файлы, показанные на скриншоте и нажмите Ok
We created the project and added all the necessary JAR files. We will also use TestNG. We need to install the TestNG plugin for Eclipse:
- Click the Help tab, then Install New Software
- In the Work field, enter beust.com/eclipse . TestNG will appear below; select TestNG and click Next. Next, follow the instructions of the installer to install the TestNG plugin.
- TestNG plugin will be displayed in the Preferences section of the Window tab
Now we are ready to write the first Appium test.
Here on this positive note, the author completes the chapter.
PS:
How to create a Java project if you work with IntelliJ IDEA
- Launch IntelliJ IDEA
- In the dialog that opens, click Create New Project
- The type of project is Java. Verify that the JDK is specified in the Project SDK field. If not, specify the path through the New ... button
- Click Next. Next window also Next
- Specify Project name. Click Finish
- A project will be created. Add packages and classes in the same way as in Eclipse (right click on src package, etc.)
- To add JAR files, go to File | Project structure
- In the left pane, select the Modules section
- Select the Dependencies tab
- Press "+" and select the necessary JAR files
- Click Ok
In the next chapter, we will look at the Appium GUI.