Automation, Sytem Engineer

Preparing Jenkins to do Automated Testing

Good afternoon, guys. Back to my routines, it is time to post some knowledge πŸ˜€

In this article, i would like to tell you about preparing our Jenkins server to run QA Testing so your QA can automate their tests. In my test, i used my mac as Jenkins server. So if you have another UNIX system, this article might work for you πŸ™‚

There are some steps to make Jenkins can doing QA Automation in Android, iOS, and Web.

In this guide, Jenkins will have one node which is in the same Mac as Jenkins itself.

Jenkins Preparation

  1. Install Jenkins on your mac. You can download jenkins from https://jenkins.io/download/.
  2. After Jenkins is installed, you can configure its plugin. For this article, we need below Plugins:
  • Environment Injector Plugin
  • JDK Parameter Plugin
  • Node and Label Parameter Plugin

Maven 3.3.9

You can download the archive file from https://maven.apache.org/download.cgi, then extract it to /opt/ directory.

After it’s extracted, change the owner of the directory to jenkins and add its path to .zshrc.

sudo chown -R jenkins:wheel apache-maven-3.3.9

Add Path to .zshrc

export PATH=/opt/apache-maven-3.3.9/bin:$PATH

Add Path in Jenkins system configuration:

screen-shot-2017-01-16-at-11-29-35-am

Java

You could install Java using this instruction: https://java.com/en/download/help/mac_install.xml

To verified that java is installed, you can check it by:

java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

You can also add Java’s Path to your environment:

export JAVA_HOME=$(/path/to/java_home)

Android SDK

You can download the latest SDK command line tools from: https://developer.android.com/studio/index.html?hl=sk

Extract the archive file then add it to your $PATH

export ANDROID_HOME=/Users/rezasetiadi/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/build-tools:$PATH

If Jenkins can’t access Android SDK, you could extract the archive file once again in other directory such as /opt/ and change the owner of the directory then add its Path to Jenkins system configuration.

screen-shot-2017-03-02-at-2-55-29-pm

screen-shot-2017-03-02-at-2-55-35-pm

Appium

You can install Appium on your Mac using npm:

npm install -g appium

To check if your environment is already suit to do Android and iOS automation with Appium, we can install appium-doctor.

npm install -g appium-doctor

After it is installed, check it like below:

~appium-doctor --ios
info AppiumDoctor Appium Doctor v.1.2.5
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor βœ” Xcode is installed at: /Applications/Xcode73.app/Contents/Developer
info AppiumDoctor βœ” Xcode Command Line Tools are installed.
info AppiumDoctor βœ” DevToolsSecurity is enabled.
info AppiumDoctor βœ” The Authorization DB is set up properly.
info AppiumDoctor βœ” The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor βœ” Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor βœ” HOME is set to: /Users/rezasetiadi
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor 
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor
~ appium-doctor --android
info AppiumDoctor Appium Doctor v.1.2.5
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor βœ” ANDROID_HOME is set to: /Users/rezasetiadi/Library/Android/sdk
info AppiumDoctor βœ” JAVA_HOME is set to: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
info AppiumDoctor βœ” adb exists at: /Users/rezasetiadi/Library/Android/sdk/platform-tools/adb
info AppiumDoctor βœ” android exists at: /Users/rezasetiadi/Library/Android/sdk/tools/android
info AppiumDoctor βœ” emulator exists at: /Users/rezasetiadi/Library/Android/sdk/tools/emulator
info AppiumDoctor βœ” Bin directory of $JAVA_HOME is set
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor 
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor

If there is some item that not checklisted by appium-doctor, you can repair it is installed correctly.

Chrome driver & Safari driver

You can install chrome driver using brew command like below:

brew install chromedriver

To install Safari driver, you can follow this instruction:

https://itisatechiesworld.wordpress.com/2015/04/15/steps-to-get-selenium-webdriver-running-on-safari-browser/

Setting Jenkins Node

Because of Jenkins user in our Mac is headless (has no GUI), we can use our user as Jenkins Node. This configuration will help us to run Web QA Automation.

On the Jenkins configuration create new Jenkins Node as follow:

screen-shot-2017-01-16-at-11-52-32-am

 

screen-shot-2017-01-16-at-11-52-43-am

Make sure this node is connected to the Jenkins server, usually we can just configuring from this setting page.

Make Jenkins Job

Create jenkins job like below:

screen-shot-2017-01-16-at-1-37-53-pm screen-shot-2017-01-16-at-1-38-04-pm

On the build step, you can see the Maven Goals, you can ask the QA team what command to run their script.

Last:

Before run the jenkins job, don’t forget to run the appium server from your terminal and specify which port which you’ll use to run the test.

Note:

If you want to run iOS and Android QA Automation, you need to specify the appium server, make sure you have the same version as the QA.

If you want to run web QA automation, you can select the node you have created before, so that jenkins can open browsers to run automation.

To run iOS QA Automation, you need to install the same XCode as the QA team requirements. If you have multiple XCode on your Mac, you need to set the default XCode using XCode Command Line Tools.

If your iOS test can’t launch the App because of error Instrument Exited with error code 253, you can try to restart your Mac, or if you have multiple XCode, try to reselect the default XCode to use by Appium.

For example, in the first try QA ask to use XCode 7.3. And you have XCode 7.3 and XCode 8.2, try to select the default to 8.2 first, then turn it back to 7.3.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s