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.
- Unfamiliar with the Command Line Interface? Read this blog post!
- Need a Quick Gradle Overview to do build configuration and run tests?
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
- View the instructions at https://github.com/chluchan/generator-geb#readme
- npm install -g generator-geb
Configure the Geb Generator
7. Run the Geb Generator
- Go to the directory where you want to install the project and type...
- yo geb
- 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: yoWith 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:
- Part One: About Yeoman, scaffolding, and other tooling applications
- Part Two: A Step-By-Step Process: Installing and Configuring Yeoman and Chris Hluchan's Geb Generator
- Part Three: Running the built-in tests from the command line, and examining how they have been set up with Gradle
- Part Four: Examining the Geb + Groovy + Spock code automatically generated
- Part Five: Modifying the Geb + Groovy + Spock Code to fit our needs
- Source Code: Initial source code generated out-of-the-box by the Yeoman Geb generator
-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!"
No comments:
Post a Comment