Framework Setup

Creating the Gradle Project

  1. Launch IntelliJ and select ‘Create New Project’
  2. Select ‘Gradle’ in the left pane
    • Select the appropriate Java JDK in the ‘Project SDK’ dropdown at the top (should be the one installed previously.  For purposes of this guide and for simplicity reasons, we are using Java 8 JDK)
      • Make sure ‘Java’ is check in the right pane
    • Click ‘Next’
  3. In the ‘GroupId’ field, enter an appropriate name (e.g. “com.producttestframework”)
  4. In the ‘ArtifactId’ field, input an appropriate name (e.g. “AutomationFramework”)
  5. Click ‘Next’
  6. Check the ‘Use auto-import’ checkbox
  7. Ensure the ‘Use default gradle wrapper (recommended)’ radio button is selected
  8. Ensure ‘Use Project JDK’ is selected for the Gradle JVM
  9. Click ‘Next’
  10. Give an appropriate Project Name (e.g. “ProductAutomation”) and an appropriate project location on your local machine (e.g. ~/Users/username/DevProjects/ProductAutomation)
  11. Click ‘Finish’
  12. Advance to IntelliJ IDEA –> Preferences/Settings –> Build, Execution, Deployment –> Build Tools –> Gradle
    • Check the ‘Create directories for empty content roots automatically’ checkbox
      • This will create your src/main and src/test sub-directories and resources for you
  13. Click ‘Apply’
  14. Click ‘OK’

Gradle Dependencies

You can manage all your projects dependencies, plugins and packages by simply adding them accordingly into your Gradle project’s build.gradle file ?

  1. Open up the build.gradle file and add the following dependencies within the dependencies braces.
    • Remove the ‘junit’ dependency that was added by default

Please note that the latest versions may change since the date I wrote this guide.  I recommend searching for each dependency below on and simply copying the dependencies from there for Gradle and then pasting them into your project’s build.gradle file.

Do make sure however, that you include certain information like ‘exclusions’ for JUnit in the TestNG dependency as shown in my examples below.

Cucumber Dependencies

testCompile group: 'io.cucumber', name: 'cucumber-java', version: '4.8.0'
testCompile group: 'io.cucumber', name: 'cucumber-jvm-deps', version:'1.0.6'
compile(group: 'io.cucumber', name: 'cucumber-testng', version:'4.8.0') {
    exclude(module: 'junit')
compile group: 'net.masterthought', name: 'cucumber-reporting', version:'4.11.2'

TestNG Dependencies

testCompile group: 'org.testng', name: 'testng', version:'6.14.3'

Selenium WebDriver Dependencies

Selenium Java
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version:'3.13.0'

Appium Dependencies

Appium Java Client
compile group: 'io.appium', name: 'java-client', version: '6.1.0'

Tell Gradle to use TestNG.xml File

Later in this blog series, we will create a testng.xml file which we use to run our different test suites, defined for example in our TestRunner class that we will also make.  We need to specifically tell Gradle to use our testng.xml file for test classes and ordering, so lets configure a test suite (xml) to be executed in a Gradle task 🙂

  1. Add the following TestNG task below the dependencies section in your build.gradle file…
    test {
        useTestNG() {
            suites 'testng.xml'

When complete, the whole build.gradle file should look similar to below…

apply plugin: 'java'
apply plugin: 'maven'

group = 'com.testifyqa.appiumandroid'
version = '1.0-SNAPSHOT'

description = """"""

sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'

repositories {

    maven { url "" }
dependencies {
    compile(group: 'io.cucumber', name: 'cucumber-testng', version:'4.8.0') {
        exclude(module: 'junit')
    compile group: 'net.masterthought', name: 'cucumber-reporting', version:'4.11.2'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version:'3.12.0'
    compile group: 'io.appium', name: 'java-client', version:'6.1.0'
    compile group: '', name: 'guava', version:'25.0-jre'
    compile group: '', name: 'gson', version:'2.8.4'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.11.0'
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version:'2.11.0'
    testCompile group: 'io.cucumber', name: 'cucumber-java', version:'4.8.0'
    testCompile group: 'io.cucumber', name: 'cucumber-jvm-deps', version:'1.0.6'
    testCompile group: 'org.testng', name: 'testng', version:'6.9.8'

tasks.withType(Test) {
    systemProperties = System.getProperties()
    maxParallelForks = 2
    forkEvery = 1

task runTests(type: Test) {
    useTestNG() // specify that we use TestNG instead of JUnit
    include '**/*TestRunner.class'
    outputs.upToDateWhen { false }

IntelliJ Plugins

Cucumber for Java Plugin

  1. Ensure ‘Cucumber for Java’ plugin is installed and enabled in IntelliJ by going to Settings –> Plugins and ensuring ‘Cucumber for Java’ is checked
    1. MacOS: IntelliJ IDEA –> Preferences –> Plugins
    2. Windows: File –> Settings –> Plugins

Create a .gitignore File

  1. In IntelliJ, right-click on your project root and select New –> File
    1. Name the file .gitignore and click OK
  2. Paste the following into your .gitignore file (this is a default template used for Maven projects)
    # Ignore Gradle GUI config
    # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
    # Cache of project
    # # Work around
    # gradle/wrapper/

    Now would be a good time to save the Maven project if you haven’t yet done so! 🙂

Packages & Directory Structure

  1. Right-click on the {project-root}/src/test/java directory, select New –> Package, and add the following packages (as well as sub packages within other packages.  You may need to put a temporary dummy file in ‘utils’ package first before adding the sub-packages)
    • pages
    • steps
    • utils
      • drivers
      • extensions
      • helpers
      • hooks
      • appium
  2. Right-click on the {project-root}/src/test directory, select New –> Directory
    • Name the directory ‘resources’ and click OK
  3. Right-click on the {project-root}/src/test/resources directory and select ‘Mark Directory As’ –> ‘Test Resources Root’ (if not marked already)
  4. Right-click the /src/test/resources directory again and select New –> Directory
    • Name the directory ‘features’ and click OK

Initial Files in each Package / Directory

Features folder

  1. Right-click the ‘features’ directory, select ‘New’ –> ‘File’ and add the following feature files (Feature files is what Cucumber uses to write BDD scenarios using Gherkin language. Please see for more information)
    • BaseScenarios.feature

Pages package

  1. Right-click the ‘pages’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘pages’ package will contain all our class files for our web pages / page objects, following Page Object Model (POM) principles. Please see for more information)
    • Page
    • BasePage

Steps package

The steps package will contain all our step definition classes, which will contain our step definitions / glue which links our steps in our test scenarios to the java methods which perform different actions.

When it comes to grouping our step definitions, it is good practice to have a Step Definition class file for each major domain object we are trying to test.

For example, in this blog series, we will mainly be testing that a user can navigate and view information on pieces by a specific, chosen artist in the Artistry app.

So in this case, we could have the following Step Definition files…

  1. Right-click the ‘steps’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘steps’ package will contain all our step definitions, which acts as the glue that connects our BDD/Gherkin language scenarios in our Feature files, to our test methods in our Java classes.  Please see for more information)
    • BaseSteps
      • this class contains all the step definitions for your base scenarios and steps that apply across multiple domain objects
        • This can also include steps that involve the initial on-boarding screens of the app (if any)
    • NavigationSteps
      • this class contains all the step definitions for steps that perform navigation actions in the Artistry app
    • PaintingSteps
      • this class contains all the step definitions that involve individual/selected paintings

Utils package

Drivers package

  1. Right-click the ‘drivers’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘drivers’ package will contain class files for all the different AppiumDrivers our test framework will use)
    • IOSAppDriver

Extensions package

  1. Right-click the ‘extensions’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘extensions’ package will contain class files for all our static methods that we can use as extensions to our existing functionality)
    • GeneralExtensions
    • JavascriptExtensions
    • JqueryExtensions
    • JquerySelectorExtensions
    • WebDriverExtensions
    • MobileElementExtensions
    • XCTestExtensions (for iOS / XCTest specific mobile gestures)

Helpers package

  1. Right-click the ‘helpers’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘helpers’ package will contain class files for all our static methods which can act as helpers to our existing functionality)
    • GeneralHelpers
    • JavascriptHelpers

Hooks package

  1. Right-click the ‘hooks’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘hooks’ package will contain classes for all the different hooks we can run before and/or after test runs/suites/scenarios etc.)
    • CucumberHooks
    • StepHooks
    • TestRunHooks

Appium package

  1. Right-click the ‘selenium’ package, select ‘New’ –> ‘Java Class’ and add the following classes to the package (the ‘selenium’ package will contain our core WebDriver setup and DriverController instance, as well as a Settings class where we can list public static variables to be used in our project)
    • Driver
    • DriverController
    • Settings

Installing Appium Server

We can now use NPM (Node Package Manager) to install Appium server globally on our system.

Normally, I like to follow best practices and install all my NPM packages locally to the project that depends on them, however with Appium Server, it is required to install it globally (or add ‘./node_modules/.bin/appium’ to PATH) if you want to be able to start it up programatically in Java using ‘AppiumDriverLocalService’.

This is OK as in a later part of this series when we add our Appium test framework to a CI/CD build server like Jenkins, we can define any NPM packages that we want to install globally in it (and of course Appium Server will be one of those). Obviously any developer working on the project will also need to install Appium Server globally on their machine.

  1. Open up Terminal (or Command Prompt) and change directory (cd) into the local project root for this project…
    cd path/to/Project

    (change ‘path/to/Project’ to the path of your local project)

  2. Once at the project root in Terminal (or Command Prompt), let’s initialise NPM so we can create our package.json file which will list all the NPM packages we contain in / that are local to our project (we won’t actually have any because we are installing appium globally, but it’s good practice any how)…
    npm init -y
  3. Now let’s install Appium Server globally to our system…
    npm install -g appium
    • You can check Appium Server was successfully installed globally after, by entering into Terminal (or Command Prompt):
      appium -v

Updating .gitignore file

Let’s now exclude the ./node_modules directory from being included in our remote repository. Because we initialised NPM and our project contains a package.json file, any one who clones our repo can simply run

npm install

and NPM would read through the package.json file and automatically install all the listed packages.

  1. Open up the .gitignore file and add

    to it

Installing Appium Desktop

Unlike Android, iOS does not have a tool like UIAutomatorViewer that we can use to inspect elements in an iOS app.

Instead, we can use Appium Desktop to create a new session with specified Desired Capabilities and inspect elements of an iOS app within the Appium Desktop session.

  1. Go to and download the DMG of the latest version of Appium Desktop
  2. Open the DMG and drag and drop the Appium Desktop application into your /Applications folder on your MacAppium Desktop is now installed, we will use it later in this blog series to inspect elements of the iOS app 🙂


Apache Log4j is a Java-based logging utility. It was originally written by Ceki Gülcü and is part of the Apache Logging Services project of the Apache Software Foundation. Log4j is one of several Java logging frameworks.

Configuring Log4J2

In our framework, we will create a Log4J2 config file and use it to configure our logging to the console.  You can also use Appender class in Log4J2 with a config file to configure logging to files, however we will stick to the Console in this blog series.

You can have one of many different types of Log4J2 config files, with certain filetypes being read before falling back to others.

In our framework, we will go with a simple XML config file.

For more info, please visit

Log4J2 XML File

  1. Right-click on the ‘/src/test/resources‘ directory and select ‘New’ -> ‘File’, name the file ‘log4j2-test.xml’ and press OK
  2. Paste the following into the xml file, it should look like below…
    <?xml version="1.0" encoding="UTF-8"?>
            <Console name="Console">
                <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %c{1} -%msg%n"/>
            <Root level="info">
                <AppenderRef ref="Console"/>

In the next section, we will begin writing code for our drivers and the rest of the core framework 😀

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

Previous Article

Next Article

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.