Skip to content

A test framework using Selenium, Cucumber, and ngWebDriver (Protractor) in Java.

License

Notifications You must be signed in to change notification settings

kathyrollo/jcucumberng-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: 'username@xyz.com'
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.