Skip to content

Commit

Permalink
Gauge example project with Groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvam committed Feb 23, 2016
0 parents commit 0003291
Show file tree
Hide file tree
Showing 28 changed files with 782 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
@@ -0,0 +1,12 @@
reports/
out/
target/
logs/
gauge_bin/
libs/
.idea
.mvn/
.gradle/
*.iml
build/
*.log
49 changes: 49 additions & 0 deletions README.md
@@ -0,0 +1,49 @@
# Gauge example in Groovy

This is an example project for doing web automation testing with [Gauge](http://getgauge.io). This project tests some of the functionalities of the [active admin demo](https://github.com/getgauge/activeadmin-demo) app. This app is hosted as a Java WAR (with embedded Jetty).

## Running this example
The tests are run on Firefox by default.

### Prerequisites

This example requires the following softwares to run.
* Groovy
* [Gauge](http://getgauge.io/download.html)
* Gauge Java plugin
* Gauge Java plugin can be installed using `gauge --install java`

### Setting up the System Under Test (SUT)

* Download [activeadmin-demo.war](https://bintray.com/artifact/download/gauge/activeadmin-demo/activeadmin-demo.war)
* Bring up the SUT by executing the below command
```
java -jar activeadmin-demo.war
```
* The SUT should now be available at [http://localhost:8080/](http://localhost:8080)

### On Linux / Mac

```
mvn test
```

### On Windows

```
mvn test
```
This runs Gauge specs with [gradle](gradle.org).

Note:
* Gauge can also be used with other [build tools](http://getgauge.io/documentation/user/current/test_code/java/using_build_tools.html) like gradle and ant.
* You can use Gauge even without a build script!

## Topics covered in the example

* [Specification](http://getgauge.io/documentation/user/current/specifications/README.html), [Scenario](http://getgauge.io/documentation/user/current/specifications/scenarios.html), [Step](http://getgauge.io/documentation/user/current/specifications/steps.html), [Concepts](http://getgauge.io/documentation/user/current/specifications/concepts.html) and [Context Steps](http://getgauge.io/documentation/user/current/specifications/contexts.html)
* [Table parameters](http://getgauge.io/documentation/user/current/specifications/parameters.html#table-parameter)
* Using [External datasource (special param)](http://getgauge.io/documentation/user/current/specifications/parameters.html#special-parameters)
* Using [tags](http://getgauge.io/documentation/user/current/specifications/tags.html)
* Using Gauge with [Selenium Webdriver](http://docs.seleniumhq.org/projects/webdriver/)
* Running Gauge specs with [maven](https://maven.apache.org/)
1 change: 1 addition & 0 deletions env/chrome/browser.properties
@@ -0,0 +1 @@
browser.name = chrome
1 change: 1 addition & 0 deletions env/default/browser.properties
@@ -0,0 +1 @@
browser.name = firefox
18 changes: 18 additions & 0 deletions env/default/default.properties
@@ -0,0 +1,18 @@
# default.properties
# properties set here will be available to the test execution as environment variables

# sample_key = sample_value

#The path to the gauge reports directory. Should be either relative to the project directory or an absolute path
gauge_reports_dir = reports

#Set as false if gauge reports should not be overwritten on each execution. A new time-stamped directory will be created on each execution.
overwrite_reports = true

# Set to false to disable screenshots on failure in reports.
screenshot_on_failure = true

# The path to the gauge logs directory. Should be either relative to the project directory or an absolute path
logs_directory = logs

APP_ENDPOINT = http://localhost:8080/
19 changes: 19 additions & 0 deletions env/default/java.properties
@@ -0,0 +1,19 @@

# Specify an alternate Java home if you want to use a custom version
gauge_java_home =

# IntelliJ and Eclipse out directory will be usually autodetected
# Use the below property if you need to override the build path
gauge_custom_build_path =

# specify the directory where additional libs are kept
# you can specify multiple directory names separated with a comma (,)
gauge_additional_libs = libs/*

# JVM argument passed to java while launching
gauge_jvm_args =

# specify the directory containing java files to be compiled
# you can specify multiple directory names separated with a comma (,)
gauge_custom_compile_dir =

6 changes: 6 additions & 0 deletions manifest.json
@@ -0,0 +1,6 @@
{
"Language": "java",
"Plugins": [
"html-report"
]
}
69 changes: 69 additions & 0 deletions pom.xml
@@ -0,0 +1,69 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>demo</groupId>
<artifactId>gauge-groovy-example</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.thoughtworks.gauge</groupId>
<artifactId>gauge-java</artifactId>
<version>0.3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.48.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.6</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.52.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.52.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>com.thoughtworks.gauge.maven</groupId>
<artifactId>gauge-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<phase>test</phase>
<configuration>
<specsDir>specs</specsDir>
</configuration>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
4 changes: 4 additions & 0 deletions resources/product_data.csv
@@ -0,0 +1,4 @@
specifier,value
title,The Way to Go On
author,Ivo Jay Balbaert
description,hohoho
4 changes: 4 additions & 0 deletions resources/user.csv
@@ -0,0 +1,4 @@
# users
FredFlintstone
JohnnyQuest
ScroogeMcduck
6 changes: 6 additions & 0 deletions specs/concepts/delete_product.cpt
@@ -0,0 +1,6 @@
# Delete product <name>

Calls another concept below!

* Find and Open product page for <name>
* Delete this product
5 changes: 5 additions & 0 deletions specs/concepts/find_and_open_product.cpt
@@ -0,0 +1,5 @@
# Find and Open product page for <name>

* On product page
* Search for product <name>
* Open description for product <name>
4 changes: 4 additions & 0 deletions specs/concepts/signup.cpt
@@ -0,0 +1,4 @@
# Sign up a new customer

* On signup page
* Fill in and send registration form
23 changes: 23 additions & 0 deletions specs/customer.spec
@@ -0,0 +1,23 @@
Customers
=========
Specifications are defined via H1 tag, you could either use the syntax above or "# Customers"

The below is a context step, gets executed before every scenario. Every unordered list is a step.

* On the customer page

The below is a scenario, defined via H2 tag. You could also use "## Search for a customer"

Search for a customer
---------------------
tags: admin, customer, search

* Search for customer "ScroogeMcduck"
* The customer "ScroogeMcduck" is listed

Verify a bunch of customers
---------------------------
tags: admin, customer, search
Can use a csv datasource!

* Search for customers <table:resources/user.csv>
38 changes: 38 additions & 0 deletions specs/products.spec
@@ -0,0 +1,38 @@
Products
========

Create a new product
--------------------
tags: admin, product, create

* Create a product
|Title |Description |Author |Price|
|--------------|--------------------|--------------|-----|
|Go Programming|ISBN: 978-1453636671|John P. Baugh |25.00|
|The Way to Go |ISBN: 978-1469769165|Ivo Balbaert |20.00|
|Go In Action |ISBN: 9781617291784 |Brian Ketelsen|30.00|
|Learning Go |ebook |Miek Gieben |0.00 |

Search for a product
--------------------
tags: admin, product, search
"Find and Open product page for" is a concept
* Find and Open product page for "Go Programming"
* Verify product "author" as "John P. Baugh"
Search and edit and existing product
------------------------------------
tags: admin, product, edit
"Find and store productId for" and "Open product edit page for stored productId" uses the sceanrio datastore
* Open product edit page for stored productId
* Update product specifier to new value <table:resources/product_data.csv>
* Check product specifier has new value <table:resources/product_data.csv>
Delete a product
----------------
tags: admin, product, delete
The below concept is an example of nested concept, check out the definition.
* Delete product "Learning Go"
21 changes: 21 additions & 0 deletions specs/user.spec
@@ -0,0 +1,21 @@
Signup
======

The below Scenarios usees the datastore on scenario level.
A new customer gets registered, its name gets stored and reused.

Register a customer
-------------------
Use tags to enrich information about:
Which interface is used? user, admin, manager, ...
What functionality is tested? signup, login, serach, ...
What is the status of the implementation? inprogress, final, dericated, ...
What is the execution priority / iteration? low, medium, high, smoke, nightly, ...
e.g.:
tags: user, signup, high, final, smoke

* Sign up a new customer
* On the customer page
* Just registered customer is listed


49 changes: 49 additions & 0 deletions src/groovy/com/thoughtworks/gauge/example/CustomerSpec.groovy
@@ -0,0 +1,49 @@
package com.thoughtworks.gauge.example
import com.thoughtworks.gauge.Step
import com.thoughtworks.gauge.Table
import com.thoughtworks.gauge.TableRow
import com.thoughtworks.gauge.example.pages.CustomerPage
import org.openqa.selenium.WebDriver
import org.openqa.selenium.support.PageFactory

public class CustomerSpec {
private final WebDriver driver

public CustomerSpec() {
this.driver = DriverFactory.getDriver()
}

@Step("On the customer page")
def navigateToCustomersPage() {
driver.get(CustomerPage.CustomerUrl)
}

@Step("Search for customer <name>")
def searchUser(String username) {
CustomerPage customerPage = PageFactory.initElements(driver, CustomerPage.class)
customerPage.searchUser(username)
}

@Step("The customer <name> is listed")
def verifyUserIsListed(String username) {
CustomerPage customerPage = PageFactory.initElements(driver, CustomerPage.class)
customerPage.verifyUserListed(username)
}

@Step("Search for customers <table>")
def verifyCustomers(Table table) {
List<TableRow> rows = table.getTableRows()
List<String> columnNames = table.getColumnNames()
for (TableRow row : rows) {
searchUser(row.getCell(columnNames.get(0)))
verifyUserIsListed(row.getCell(columnNames.get(0)))
}
}

@Step("Just registered customer is listed")
def verifyJustRegisteredCustomerListed() {
CustomerPage customerPage = PageFactory.initElements(driver, CustomerPage.class)
String currentUser = customerPage.fetchStringFromScenarioDataStore("currentUser")
verifyUserIsListed(currentUser)
}
}
32 changes: 32 additions & 0 deletions src/groovy/com/thoughtworks/gauge/example/DriverFactory.groovy
@@ -0,0 +1,32 @@
package com.thoughtworks.gauge.example

import com.thoughtworks.gauge.AfterSuite
import com.thoughtworks.gauge.BeforeSuite
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.firefox.FirefoxDriver

public class DriverFactory {
private static final String CHROME = "chrome"

public static WebDriver getDriver() {
return driver
}

private static WebDriver driver

@BeforeSuite
def Setup() {
String browser = System.getenv("browser.name")
if (browser.toLowerCase().equals(CHROME)) {
driver = new ChromeDriver()
} else {
driver = new FirefoxDriver()
}
}

@AfterSuite
def TearDown() {
driver.close()
}
}

0 comments on commit 0003291

Please sign in to comment.