Table of Contents
Getting Started
Introduction
In this series, we will setup an automation framework scratch to test against the frontend of a web application.
The completed repository can be found at https://gitlab.com/testifyqa/Java-Web-Selenium-Gradle
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.
- We will set up WebDrivers for automation in Google Chrome and Mozilla Firefox
- 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.
- 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
- Alternatively, you could use JUnit, but TestNG is usually the favourite by QA Automation folk. However, JUnit5 has now released, which is definitely a worthy contender to TestNG. For a thorough comparison between TestNG and JUnit5, please see the slides on https://seleniumcamp.com/talk/testng-vs-junit-5-battle/ and for details on how the JUnit TestRunner class would differ for using JUnit with Cucumber, please see http://toolsqa.com/cucumber/junit-test-runner-class/
- 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
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.
- Download the Java JDK appropriate for your Operating System / Architecture from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- 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:
- Open up Terminal and type the following (exclude typing the $’s)…
$ nano ~/.bash_profile
- 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
- Save .profile and exit nano editor by pressing (in order, one at a time)…
Ctrl + O
[Return]
Ctrl + X
- Completely quit out of Terminal and restart it to launch a fresh Terminal window with your changes applied
- Confirm you have correctly set the $JAVA_HOME environment variable by typing in Terminal…
$ java -version
Windows:
- Click ‘Start’ and search for “System”
- Go to ‘Advanced System Settings’ –> ‘Advanced’ –> ‘Environment Variables’
- Under the ‘System Variables’ section, click ‘New’ and then add and set the following new System Variable…
- Variable Name:
JAVA_HOME
- Variable Value:
C:\Program Files\jdk1.#.#_###
(replace with directory path of where JDK was installed)
- Variable Name:
- Double-click on ‘Path’ in the System Variables pane
- Click ‘New’ and add and set the following PATH environment variable…
C:\Program Files\jdk1.#.#_###\bin
({jdk-root-directory-path}\bin)
- Click ‘OK’ where applicable to apply your changes
- Confirm you have correctly set the $JAVA_HOME environment variable by opening CMD Prompt and entering…
$ java -version
(exclude typing the $)
Setting Up Gradle
Gradle is an open-source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven for declaring the project configuration. Gradle uses a directed acyclic graph (“DAG”) to determine the order in which tasks can be run.
Install Gradle
MacOS:
Install HomeBrew (Package Manager)
Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS operating system.
- Go to https://brew.sh/
- Copy the command and paste it into Terminal…
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install Gradle
- Open up Terminal and enter…
$ brew install gradle
(without the $)
Windows
Install Chocolatey (Package Manager)
- Open up a command prompt (cmd.exe) with administrative privileges
- Enter in the following command…
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
Install Gradle
- Open up a command prompt (cmd.exe) with administrative privileges again
- Enter in the following command…
choco install gradle
Setting Up Gradle Environment Variables
MacOS:
- Open up Terminal and type the following (exclude typing the $’s)…
$ nano ~/.bash_profile
- Add the following lines to your .bash_profile file within Terminal to set the $M2_HOME (Maven) environment variable…
export PATH=$PATH:/opt/gradle/gradle-4.9/bin
- Save .profile and exit nano editor by pressing (in order, one at a time)…
Ctrl + O
[Return]
Ctrl + X
- Completely quit out of Terminal and restart it to launch a fresh Terminal window with your changes applied
Windows:
- Click ‘Start’ and search for “System”
- Go to ‘Advanced System Settings’ –> ‘Advanced’ –> ‘Environment Variables’
- Double-click on ‘Path’ in the System Variables pane
- Set and append the following PATH environment variable…
C:\Gradle\gradle-4.9\bin;
({gradle-directory-path}\bin)
- Click ‘OK’ where applicable to apply your changes
- Confirm you have correctly set the Gradle environment variable by opening CMD Prompt and entering…
$ gradle -v
(exclude typing 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 🙂
- Download IntelliJ IDEA from https://www.jetbrains.com/idea/download
- Complete installation of IntelliJ IDEA
- Launch IntelliJ IDEA and choose to not import any settings (unless you have appropriate ones already)
- Select your UI theme and click ‘Next’
- Select your keymap scheme and click ‘Next’
- Keep clicking ‘Next’ without changing anything on the following screens in the wizard
- Click ‘Start using IntelliJ IDEA’