Getting Started

Introduction

In this series, we will setup a mobile automation framework from scratch, to test against a native iOS application. We will explain how to do this on MacOS as that is what is required for iOS (as you need Xcode).

The completed repository can be found at https://gitlab.com/testifyqa/java-ios-appium-maven

We will use the following in our framework:

  • Selenium WebDriver
    • Selenium is a portable software-testing framework for web applications. Selenium provides a playback (formerly also recording) tool for authoring tests without the need to learn a test scripting language (Selenium IDE). It also provides a test domain-specific language (Selenese) to write tests in a number of popular programming languages, including C#, Groovy, Java, Perl, PHP, Python, Ruby and Scala. The tests can then run against most modern web browsers. Selenium deploys on Windows, Linux, and macOS platforms. It is open-source software, released under the Apache 2.0 license: web developers can download and use it without charge.
      • Selenium is required by Appium
  • Cucumber
    • Cucumber is a software tool used by computer programmers for testing other software. It runs automated acceptance tests written in a behaviour-driven development style. Central to the Cucumber BDD approach is its plain language parser called Gherkin.
  • TestNG
    • TestNG is a testing framework for the Java programming language, inspired by JUnit and NUnit. The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-end, integration, etc., with more powerful and easy-to-use functionalities. It is similar to JUnit but has extra capabilities
  • Appium
    • Appium is an open source automation tool for running scripts and testing native applications , mobile-web applications and hybrid applications on Android or iOS using a webdriver.

Setting Up Java

Java JDK

The Java Development Kit is an implementation of either one of the Java Platform, Standard Edition, Java Platform, Enterprise Edition, or Java Platform, Micro Edition platforms released by Oracle.

  1. Download the Java JDK appropriate for your Operating System / Architecture from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  2. Follow the wizard and complete the installation of the Java JDK

Setting Up Java Environment Variables

An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer.  Because every developer on a team will have a slightly different Development environment on there local machine, using environment variables is good practice to help easily find and use needed processes and/or paths in an environment.

MacOS:

  1. Open up Terminal and type the following (exclude typing the $’s)…
    $ nano ~/.bash_profile
  2. Add the following lines to your .bash_profile file within Terminal to set the $JAVA_HOME environment variable…
    export JAVA_HOME=$(/usr/libexec/java_home)
    export PATH=$JAVA_HOME/bin:$PATH
  3. Save .profile and exit nano editor by pressing (in order, one at a time)…
    Ctrl + O
    [Return]
    Ctrl + X
  4. Completely quit out of Terminal and restart it to launch a fresh Terminal window with your changes applied
  5. Confirm you have correctly set the $JAVA_HOME environment variable by typing in Terminal…
    $ java -version

Setting Up Maven

Maven is a build automation tool used primarily for Java projects, to manage its dependencies and any external libraries and packages the Java project may need.  In Yiddish, the word maven means “accumulator of knowledge”.

Download Maven Binaries

  1. Download the Maven binaries from https://maven.apache.org/download.cgi
    1. If on Windows, download the zip file
    2. If on MacOS, download the tar.gz file
  2. Create a root directory for all your Framework related downloads (e.g. ‘C:\FrameworkSetup’ or ‘~/Users/username/FrameworkSetup’)
  3. Extract the downloaded Maven binaries and place the extracted Binaries directory inside the root directory you just created

Setting Up Maven Environment Variables

MacOS:

  1. Open up Terminal and type the following (exclude typing the $’s)…
    $ nano ~/.bash_profile
  2. Add the following lines to your .bash_profile file within Terminal to set the $M2_HOME (Maven) environment variable…
    export M2_HOME=/Users/username/FrameworkSetup/apache-maven-#.#.# (replace directory with where you extracted Maven binaries to on your machine)
    export PATH=$JAVA_HOME/bin:$PATH
  3. Save .profile and exit nano editor by pressing (in order, one at a time)…
    Ctrl + O
    [Return]
    Ctrl + X
  4. Completely quit out of Terminal and restart it to launch a fresh Terminal window with your changes applied
  5. Confirm you have successfully added and set the environment variable for Maven by entering…
    $ source ~/.bash_profile (exclude the $)
    $ echo $M2_HOME (exclude the $)

Setting Up IntelliJ IDEA

IntelliJ IDEA is a Java IDE for developing computer software.  It is developed by JetBrains, and is available as a free community edition, or as a paid commercial edition. For the purposes of this blog, the free, community edition is fine 🙂

  1. Download IntelliJ IDEA from https://www.jetbrains.com/idea/download
  2. Complete installation of IntelliJ IDEA
  3. Launch IntelliJ IDEA and choose to not import any settings (unless you have appropriate ones already)
  4. Select your UI theme and click ‘Next’
  5. Select your keymap scheme and click ‘Next’
  6. Keep clicking ‘Next’ without changing anything on the following screens in the wizard
  7. Click ‘Start using IntelliJ IDEA’

Setting Up Appium

Appium works by sending commands from our Appium client (added to our codebase in an IDE) to an Appium server, via JSON Wire Protocol.  Appium Server then creates a mobile automation session for the client and checks against any Desired Capabilities that we have specified to then connect to our respective vendor-provided framework (e.g. Selendroid/UIAutomator for Android or XCUITest for iOS) and run our tests in a session against the appropriate mobile device/platform defined in our Desired Capabilities. Don’t worry if you don’t understand all of this now, as hopefully it will make more sense as we go through everything.

iOS

Download and Install Xcode

Xcode is an integrated development environment (IDE) for macOS containing a suite of software development tools developed by Apple for developing software for macOS, iOS, watchOS, and tvOS.

Xcode should be included on macOS by default, but if it isn’t, open up the App Store on macOS, search for Xcode and click ‘Get’.

  1. Launch Xcode
  2. Advance to ‘Window’ –> ‘Devices & Simulators’
    • Select the ‘Simulators’ tab and view the list of iOS simulators available for use

Node.js & NPM (Node Package Manager)

Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser.

NPM is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js. It consists of a command line client, also called npm, and an online database of public and paid-for private packages, called the npm registry.

Mac

Setting up Homebrew

Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS operating system. Originally written by Max Howell, the package manager has gained popularity in the Ruby on Rails community and earned praise for its extensibility.

  1. Open up Terminal and paste the following command to download and install Homebrew (if you run into any issues, consult https://docs.brew.sh/Common-Issues)…
  2. Once Homebrew is installed, let’s make sure Homebrew is up to date by running the following command…
  3. It is also recommended to run Brew Doctor and follow any instructions to resolve any errors/warnings that the brew doctor returns…
Add Homebrew’s location to $PATH
  1. Open up Terminal and type the following (excluding typing the $)…
    $ nano ~/.bash_profile
  2. Add the following line to your .bash_profile within Terminal, to add Homebrew’s location to $PATH…
    export PATH="/usr/local/bin:$PATH"

Setting up Node.js and NPM

Mac
  1. Open up Terminal and use Homebrew to install Node.js (NPM will be installed with Node)…
  2. You can check that Node.js and NPM were installed successfully by checking their appropriate version numbers in Terminal…
    node -v
    npm -v

In the next section, we will add create our project, add our dependencies and install Appium Server as well as Appium Java Client 😀

Liked it? Take a second to support Thomas on Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.