Code Monkey home page Code Monkey logo

jcucumberng-framework's Introduction

java_selenium_cucumber_protractor

jCucumberNG-Framework

MAINTENANCE MODE

Project is no longer being updated but will stay here as portfolio artefact and reference implementation.

Allows automation testers to write feature files for Cucumber and implement step definitions in basic Java classes. ngWebDriver (Protractor) offers extended support for Angular/JS web applications.

Contents

  1. How It Works
  2. Technology Stack
  3. What You Need
  4. Running Tests
  5. Checking Results

How It Works

Test script logic is implemented directly in step definitions using Dependency Injection (DI) to focus test automation on developing tests instead of keeping up with page objects. An intelligent UI Map serves as the central object repository of web element locators.

Basic Usage

project.properties

ap.auth=http://automationpractice.com/index.php?controller=authentication&back=my-account

ui-map.properties

# User Interface (UI) Map

# Patterns
# ui.element.key=locator:selector
# ui.element.key=css_containing_text:selector|text
# ui.element.key=by_all:key1|key2|keyN
# ui.element.key=by_chained:key1|key2|keyN

# Selenium Locators
# id, name, link_text, partial_link_text, tag, class, css, xpath, by_all,
# by_chained, by_id_or_name

# ngWebDriver (Protractor) Locators
# binding, model, button_text, css_containing_text, exact_binding,
# exact_repeater, options, partial_button_text, repeater

#------------------------------------------------------------------------------#

ap.email.create=by_id_or_name:email_create
ap.submit.create=by_id_or_name:SubmitCreate
ap.page.heading=class:page-heading

Feature / Gherkin

Given I Am At Page: 'ap.auth'
When I Enter Email: '[email protected]'
Then I Should See Page Heading: 'CREATE AN ACCOUNT'

Step Definition

private Selenium selenium = null; // Extended Selenium API

// PicoContainer injects shared context
public NetIncomeSteps(ContextSteps contextSteps) {
    selenium = contextSteps.getSelenium(); // Instantly begin using API
}

@Given("I Am At Page: {string}")
public void I_Am_At_Page(String key) throws Throwable {
	// Use key from project.properties for app settings
	selenium.navigate(key); // 1
}

@When("I Enter Email: {string}")
public void I_Enter_Email(String email) throws Throwable {
	// Use key from ui-map.properties for web elements
	selenium.type(email, "ap.email.create"); // 2
	selenium.click("ap.submit.create"); // 3
}

@Then("I Should See Page Heading: {string}")
public void I_Should_See_Page_Heading(String expected) throws Throwable {
	// Use fluent assertion
	Assertions.assertThat(selenium.refreshAndTextToBePresent(expected, "ap.page.heading")).isTrue(); // 4
}

4 lines of actual test script, 1 class.

[ Back ]

Technology Stack

[ Back ]

What You Need

[ Back ]

Running Tests

The framework is running tests against 2 applications:

No further configurations needed at this point. The tests will run in headless browser mode using ChromeDriver as defined in framework.properties.

To run the tests:

Git Bash or Cmder is recommended.

$ cd /path/to/workspace/
$ git clone <repo-url>
$ cd jcucumberng-framework/
$ mvn verify

Maven performs a one-time download of all dependencies. Execute mvn verify again if needed after the downloads complete to begin running the tests.

Output:

6 Scenarios (6 passed)
22 Steps (22 passed)
1m37.038s

[ Back ]

Checking Results

HTML, JSON, XML test reports and logs are created in the /target/ directory after the build.

Static Reporting

Cucumber-JVM ships with its default HTML reporter. Best for debugging scripts.

Generate report into directory: /target/cucumber-html-default/

mvn verify

Output:

static_report

Dyamic Reporting (3-in-1)

Animated visuals with colorful graphs and charts are generated by 3 different reporting plugins. Best for stakeholder demos.

1. Masterthought

This report is standalone that can be zipped and emailed to clients. HTML files can be viewed locally using any browser.

Generate report into directory: /target/cucumber-html-reports/

mvn verify

Output:

maven_cucumber_reporting

2. Extent Reports

This report is standalone that can be zipped and emailed to clients. HTML files can be viewed locally using any browser.

Generate report into directory: /target/cucumber-extentreports/

mvn verify

The same command generates Masterthought and Extent Reports.

Output:

extent_reports_cucumber

3. Allure

This report is a single page application (SPA). Dynamic attributes use AJAX and need to be launched from a running web server to view.

Method 1: Generate report into temp folder and start local web server (launches browser)

mvn verify
mvn allure:serve

Method 2: Combine commands (run tests and invoke all reporting plugins)

mvn verify allure:serve

Output:

allure_report

Logging

Logs are written to a daily rolling file. Executions from the previous day are saved with a datestamp. Best for debugging scripts.

Directory:

target/
|__ test-logs/
    |__ jcucumberng_2019-06-21.log
    |__ jcucumberng_2019-06-22.log
    |__ jcucumberng_2019-06-23.log
    |__ jcucumberng.log

Output:

[INFO ] 2019-06-28 16:58:28,920 ContextSteps.setUp() - BEGIN TEST -> Verify Page Title
[INFO ] 2019-06-28 16:58:28,921 ContextSteps.setUp() - Browser=CHROME32_NOHEAD
[INFO ] 2019-06-28 16:58:30,618 ContextSteps.setUp() - Screen Resolution (WxH)=1366x768
[DEBUG] 2019-06-28 16:59:49,148 GlobalSteps.I_Am_At_Page() - Page URL=http://simplydo.com/projector/
[DEBUG] 2019-06-28 16:59:49,505 GlobalSteps.I_Should_See_Page_Title() - Page Title=Simply Do - Balance Projector
[INFO ] 2019-06-28 16:59:49,863 ContextSteps.tearDown() - END TEST -> Verify Page Title - PASSED

[ Back ]

LICENSE

Copyright 2018 Katherine Rollo

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

jcucumberng-framework's People

Contributors

kathyrollo avatar

Stargazers

 avatar

jcucumberng-framework's Issues

Implement Cucumber Extent Reporter

Implement Allure Test Report

Fix classification files for maven-cucumber-reporting

Classification files stopped working.
classification.zip

Classification File:

# Classification file for maven-cucumber-reporting plugin
# See pom.xml for configuration

AngularVersion=0.0.0
AutUiVersion=0.0.0
AutApiVersion=0.0.0
chromeVersion=0.0.0
firefoxVersion=0.0.0

pom.xml:

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>krollo.jcucumberng</groupId>
	<artifactId>jcucumberng-framework</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>
	<name>jCucumberNG-Framework</name>
	<description>A test framework using Selenium, Cucumber, and ngWebDriver (Protractor) in Java</description>
	<url></url>
	<properties>
		<!-- Project Properties -->
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<!-- Maven Properties -->
		<timestamp>${maven.build.timestamp}</timestamp>
		<maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
		<!-- Framework Core Dependencies -->
		<selenium.version>3.12.0</selenium.version>
		<ngwebdriver.version>1.1.3</ngwebdriver.version>
		<cucumber.version>3.0.2</cucumber.version>
		<java.version>1.8</java.version>
	</properties>
	<dependencies>
		<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-server</artifactId>
			<version>${selenium.version}</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/com.paulhammant/ngwebdriver -->
		<dependency>
			<groupId>com.paulhammant</groupId>
			<artifactId>ngwebdriver</artifactId>
			<version>${ngwebdriver.version}</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
		<!-->
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-testng</artifactId>
			<version>${cucumber.version}</version>
			<scope>test</scope>
		</dependency>
		-->
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-junit</artifactId>
			<version>${cucumber.version}</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
		<dependency>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-picocontainer</artifactId>
			<version>${cucumber.version}</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
		<dependency>
			<groupId>org.assertj</groupId>
			<artifactId>assertj-core</artifactId>
			<version>3.10.0</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-slf4j-impl</artifactId>
			<version>2.11.0</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
		<dependency>
			<groupId>com.itextpdf</groupId>
			<artifactId>itextpdf</artifactId>
			<version>5.5.13</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml</artifactId>
			<version>3.17</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.7.0</version>
				<configuration>
					<source>${java.version}</source>
					<target>${java.version}</target>
				</configuration>
			</plugin>
			<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.21.0</version>
				<configuration>
					<includes>
						<include>**/*Runner.java</include>
					</includes>
					<testFailureIgnore>false</testFailureIgnore>
					<reportsDirectory>./target/test-output/${timestamp}</reportsDirectory>
				</configuration>
			</plugin>
			<!-- https://mvnrepository.com/artifact/net.masterthought/maven-cucumber-reporting -->
			<plugin>
				<groupId>net.masterthought</groupId>
				<artifactId>maven-cucumber-reporting</artifactId>
				<version>3.17.1</version>
				<executions>
					<execution>
						<id>execution</id>
						<phase>verify</phase>
						<goals>
							<goal>generate</goal>
						</goals>
						<configuration>
							<projectName>Simply Do - Balance Projector</projectName>
							<outputDirectory>${project.build.directory}</outputDirectory>
							<jsonFiles>
								<param>**/test-report.json</param>
							</jsonFiles>
							<classificationFiles>
								<param>**/test-report.properties</param>
							</classificationFiles>
							<parallelTesting>false</parallelTesting>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

Implement multiple Configurers for DataTables

Implement TableConfigurer and TableEntryConfigurer for different DataTable types.

Currently not supported:
cucumber/cucumber-jvm#1426

TableConfigurer.java:

package project.datatable;

import java.util.Locale;

import cucumber.api.TypeRegistry;
import cucumber.api.TypeRegistryConfigurer;
import io.cucumber.datatable.DataTable;
import io.cucumber.datatable.DataTableType;
import io.cucumber.datatable.TableTransformer;
import project.domain.Transaction;

/**
 * Maps DataTable with label column in feature file to a single object of
 * Type{@literal <T>}. Left column is field name, right column is value.
 */
public class TableConfigurer implements TypeRegistryConfigurer {

	@Override
	public Locale locale() {
		return Locale.ENGLISH;
	}

	@Override
	public void configureTypeRegistry(TypeRegistry registry) {

		registry.defineDataTableType(new DataTableType(Transaction.class, new TableTransformer<Transaction>() {
			@Override
			public Transaction transform(DataTable dataTable) throws Throwable {
				return new Transaction(dataTable.asMaps().get(0));
			}
		}));

	}

}

TableEntryConfigurer.java:

package project.datatable;

import java.util.Locale;
import java.util.Map;

import cucumber.api.TypeRegistry;
import cucumber.api.TypeRegistryConfigurer;
import io.cucumber.datatable.DataTableType;
import io.cucumber.datatable.TableEntryTransformer;
import project.domain.Transaction;

/**
 * Maps DataTable with header row in feature file to multiple objects of
 * Type{@literal <T>}. Each row below the header is an object.
 */
public class TableEntryConfigurer implements TypeRegistryConfigurer {

	@Override
	public Locale locale() {
		return Locale.ENGLISH;
	}

	@Override
	public void configureTypeRegistry(TypeRegistry registry) {

		registry.defineDataTableType(new DataTableType(Transaction.class, new TableEntryTransformer<Transaction>() {
			@Override
			public Transaction transform(Map<String, String> map) {
				return new Transaction(map.get("name"), map.get("amount"), map.get("frequency"), map.get("month"));
			}
		}));

	}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.