October 19, 2016

Testing The-Internet with Geb + Groovy + Spock: Installing Yeoman and the Geb Generator

Part 2 of 5. Need to read from the beginning

To get more familiar with the Geb Framework + Groovy Language + Spock Framework, I was planning on figuring out how to automate Dave Haeffner's Login page on his test site, The-Internet.

A few days ago, I talked a bit about scaffolding a project, laying out the basic groundwork, and the history of Yeoman.io. With this blog post, we will walk a user through downloading and installing Yeoman through the Node Package Manager.

The installation will be done on the command line: the Mac's Terminal or the Windows Command Prompt.


We will be using a Geb Generator created by Chris Hluchan ( LinkedIn ), a Software Engineer at Google, formerly at Oracle.

You can take a look at the generator’s source code on GitHub at https://github.com/chluchan/generator-geb#readme

We will be borrowing heavily from "Let's Scaffold a Web App" written by Mehdy Dara ( Github: zckers ).

Want to see what the boilerplate source code the Geb generator produces? I have uploaded it to my GitHub site at https://github.com/tjmaher/geb_project_generated_by_yo .

The next few blog posts, we will be comparing that to the official Geb + Groovy + Spock Framework documentation to figure out how it works.

First, we need to figure out how to install everything.



Install JDK, Node.js, Update NPM, Git

1.  Install the Java Development Kit

  • Open up Terminal on the Mac or the Windows Command Prompt and check what version of Java is installed:
  • java -version
… If there isn’t a version number listed, or it is earlier than Java 8, install the latest version of the Java Development Kit from http://www.oracle.com/technetwork/java/javase/downloads/

2. Install Node.js

  • Open up Terminal on the Mac or the Windows Command Prompt  and check what version of Java is installed:
  •  node —version

… If there isn’t a version number listed, install the latest version of Node.js from https://nodejs.org/

3. Install the latest version of the Node Package Manager


  • npm install --global npm@latest

4. Install Git

  • Open up Terminal on the Mac or the Windows Command Prompt and check what version of Java is installed:
  •  git —version

… If there isn’t a version number listed, install the latest version of Git from https://git-scm.com/downloads

Install Yeoman and the Geb Generator

5. Install Yeoman

  • Installation: npm install --global yo
  • Check to see if everything is okay: yo --version

6. Install the Geb Generator


Configure the Geb Generator

7. Run the Geb Generator

  • Go to the directory where you want to install the project and type...
  • yo geb


Let's call this:

  • Name of project: geb_project_generated_by_yo
  • Base Package: com.tjmaher


8. Run the out-of-the-box test


  • Mac: ./gradlew chromeTest -Dprofile=production
  • PC, runs on a batch file: gradlew chromeTest -Dprofile=production 


The Test Output: What does it Mean?

A build configuration file was created, build.gradle. This file can be seen here. It sets up:

  • All the third party dependencies, what versions are needed
  • Sets up the browsers: Firefox, Chrome, and PhantomJS
  • Downloads all dependencies from mavenCentral
  • The Selenium version to be 2.46.0.
  • The built in selenium-chrome-driver and selenium-firefox-driver
  • HTML reporting to be stored in the "/tests" subfolder
  • Chromedriver depending on if the OS is Mac or Windows
  • Results in the Build Directory, in the "test-results" folder. 
  • Tests: chromeTest, phantomJsTest, or test to run all of them.
... It also allows us to set up the base url. 


The command to run the test:

  • C:\Users\tmaher\Documents\code\github\geb_project_generated_by_yo>gradlew chromeTest -Dprofile=production


Dependencies listed in the build.gradle file are downloaded:

  • Downloading https://services.gradle.org/distributions/gradle-2.7-bin.zip
  • <snip> 
  • Unzipping C:\Users\tmaher\.gradle\wrapper\dists\gradle-2.7-bin\4s0fcuuppw3tjb1sxpzh16mne\gradle-2.7-bin.zip to C:\Users\tmaher\.gradle\wrapper\dists\gradle-2.7-bin\4s0fcuuppw3tjb1sxpzh16mne
Compilation tasks are run:
  • :compileJava UP-TO-DATE
  • :compileGroovy UP-TO-DATE
  • :processResources UP-TO-DATE
  • :classes UP-TO-DATE
  • :compileTestJava UP-TO-DATE
  • :compileTestGroovy
More dependencies are downloaded:
  • Download https://repo1.maven.org/maven2/org/gebish/geb-spock/0.12.2/geb-spock-0.12.2.pom
  • Download https://repo1.maven.org/maven2/org/spockframework/spock-core/1.0-groovy-2.4/spock-core-1.0-groovy-2.4.pom
  • Download https://repo1.maven.org/maven2/org/codehaus/groovy/groovy-all/2.4.1/groovy-all-2.4.1.pom
  • Download https://repo1.maven.org/maven2/org/gebish/geb-junit4/0.12.2/geb-junit4-0.12.2.pom
  • Download https://repo1.maven.org/maven2/com/codeborne/phantomjsdriver/1.2.1/phantomjsdriver-1.2.1.pom
  • Download https://repo1.maven.org/maven2/org/gebish/geb-core/0.12.2/geb-core-0.12.2.pom
  • Download https://repo1.maven.org/maven2/org/gebish/geb-waiting/0.12.2/geb-waiting-0.12.2.pom
  • Download https://repo1.maven.org/maven2/org/gebish/geb-ast/0.12.2/geb-ast-0.12.2.pom
  • Download https://repo1.maven.org/maven2/org/gebish/geb-exceptions/0.12.2/geb-exceptions-0.12.2.pom
  • Download https://repo1.maven.org/maven2/org/gebish/geb-implicit-assertions/0.12.2/geb-implicit-assertions-0.12.2.pom
  • Download https://repo1.maven.org/maven2/org/gebish/geb-spock/0.12.2/geb-spock-0.12.2.jar
  • Download https://repo1.maven.org/maven2/org/spockframework/spock-core/1.0-groovy-2.4/spock-core-1.0-groovy-2.4.jar
  • Download https://repo1.maven.org/maven2/org/codehaus/groovy/groovy-all/2.4.1/groovy-all-2.4.1.jar
  • Download https://repo1.maven.org/maven2/org/gebish/geb-junit4/0.12.2/geb-junit4-0.12.2.jar
  • Download https://repo1.maven.org/maven2/com/codeborne/phantomjsdriver/1.2.1/phantomjsdriver-1.2.1.jar
  • Download https://repo1.maven.org/maven2/org/gebish/geb-core/0.12.2/geb-core-0.12.2.jar
  • Download https://repo1.maven.org/maven2/org/gebish/geb-waiting/0.12.2/geb-waiting-0.12.2.jar
  • Download https://repo1.maven.org/maven2/org/gebish/geb-ast/0.12.2/geb-ast-0.12.2.jar
  • Download https://repo1.maven.org/maven2/org/gebish/geb-exceptions/0.12.2/geb-exceptions-0.12.2.jar
  • Download https://repo1.maven.org/maven2/org/gebish/geb-implicit-assertions/0.12.2/geb-implicit-assertions-0.12.2.jar
The final batch of tasks, both pre-installed Gradle tasks and customized gradle tasks listed in the build.gradle file are run:
  • :processTestResources
  • :testClasses
  • :downloadChromeDriver
  • :unzipChromeDriver
  • :chromeTest

A Browser will open, and the two tests will run!

Want to look at the source code generated? I uploaded the basic framework to my GitHub site at https://github.com/tjmaher/geb_project_generated_by_yo

We will dig into the code a bit more in the next blog post.

Need Help with Yeoman?

If you ever need any help with Yeoman, you can type into the command line: yo





With the next blog post, we will be really digging into the scaffolding code and how the project is set up.

Until then, Happy Testing!


Testing The-Internet with Geb + Groovy + Spock:

-T.J. Maher
Twitter | LinkedIn | GitHub

// Sr. QA Engineer, Software Engineer in Test, Software Tester since 1996.
// Contributing Writer for TechBeacon.
// "Looking to move away from manual QA? Follow Adventures in Automation on Facebook!"
Post a Comment