Giter Site home page Giter Site logo

igniteram / protractor-cucumber-allure Goto Github PK

View Code? Open in Web Editor NEW
49.0 20.0 47.0 2.09 MB

e2e kickstarter framework for using protractorJS with cucumberJS and allure jenkins CI reports

License: MIT License

JavaScript 89.39% Gherkin 10.61%
protractor cucumberjs allure-report

protractor-cucumber-allure's Introduction

Protractor-Cucumber-Allure Setup Guide

circleCI Status code climate status MIT License

This project demonstrates the basic protractor-cucumber framework project setup with Jenkins CI and Allure Reports integration


Features

  • Crisp & Clear folder structures
  • Page Object design pattern implementation
  • Extensive hooks implemented for BeforeAll, After etc.
  • MultiCapabalities and Test Sharding example
  • Screenshots on failure feature scenarios
  • PosgreSQL database connection feature example - see Database
  • Support for cucumber-html-reports
  • Support for CI and Cucumber-Allure-Jenkins reports - check the Caveat section below

To Get Started

Pre-requisites

1.NodeJS installed globally in the system. https://nodejs.org/en/download/

Note Min node version 6.9.x

2.Chrome or Firefox browsers installed.

3.Text Editor(Optional) installed-->Sublime/Visual Studio Code.

Run Scripts

  • Clone the repository into a folder
  • Go inside the folder and run following command from terminal/command prompt which would then install all the dependencies from package.json
npm install
  • Then first step is to fire up the selenium server which could be done in many ways, webdriver-manager proves very handy for this.The below command should download the chrome & gecko driver binaries locally for you!
npm run webdriver-update
  • Then you should start your selenium server!
npm run webdriver-start
  • Following command will launch the chrome browser and run the scripts
npm test

Writing Features

Feature: To search allure reports in google
    @AllureScenario
    Scenario: Allure Reports Google
        Given I am on google page
        When I type "allure reports"
        Then I click search button
        Then I clear search textbox

Writing Step Definitions

"use strict";
"use strict";
const search = require("../pages/searchPage");
const { Given } = require("cucumber");

  Given(/^I am on google page$/, function() {
    return expect(browser.getTitle()).to.eventually.equal("Google");
  });

Writing Page Objects

function googleSearch() {
  this.searchTextBox = $("#lst-ib");
  this.searchButton = $("input[value='Google Search']");
}
module.exports = new googleSearch();

Cucumber Hooks

Following method takes screenshot on failure of each scenario

     
After(function(scenario) {
    if (scenario.result.status === Status.FAILED) {
    const attach = this.attach; // cucumber's world object has attach function which should be used
        return browser.takeScreenshot().then(function(png) {
        const decodedImage = new Buffer(png, "base64");
        return attach(decodedImage, "image/png");
    });
}
       

CucumberOpts Tags

Following configuration shows to call specific tags from feature files

cucumberOpts: {
    strict: true,
    format: 'json:./reports/json/cucumber_report.json',
    require: ["../stepDefinitions/*.js", "../support/*.js"],
    tags: "(@AllureScenario or @CucumberScenario or @ProtractorScenario)"
}

Database

You need to install PostgreSQL nodejs modulewith this framework.

npm install -D pg

database feature file elaborates the connection and how the query results are retrieved.

const pg = require('pg');
const connectDB = function() {
const conString = "postgres://username:password@localhost:5432/database_name";
this.client = new pg.Client(conString);
this.client.connect(function(err){
    if(err){
        return console.error('could not connect to postgres', err);
    }
    });
};

HTML Reports

Currently this project has been integrated with two types of cucumber HTML reports just for demo, which are generated when you run npm test in the reports folder. They can be customized according to user's specific needs-

cucumberreporterscreen cucumberreportscreen

Allure Reports

Caveat

These reports do not support latest cucumber 2.0 version, however they work with older version cucumber 1.3.5 & less. You would have to use the older cucumber syntax as well.

The reporter.js file in Support folder generates the target directory "Reports" in which the xml files are generated.For detail instructions on how it works, please refer the Allure-CucumberJS official repo : https://github.com/allure-framework/cucumberjs-allure-reporter

How to setup Jenkins and Allure framework : http://wiki.qatools.ru/display/AL/Allure+Jenkins+Plugin

const reporter = require('cucumberjs-allure-reporter');
 reporter.config(
 {
    targetDir:'./reports/'
 }
 );
module.exports = reporter;

allurereportscreen alluregraphscreen

Contributions

For contributors who want to improve this repo by contributing some code, reporting bugs, issues or improving documentation - PR's are highly welcome, please maintain the coding style , folder structure , detailed description of documentation and bugs/issues with examples if possible.

protractor-cucumber-allure's People

Contributors

igniteram avatar paulohfcanuto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

protractor-cucumber-allure's Issues

Chrome Driver Execution: Error message: Could not find update-config.json. Run 'webdriver-manager update' to download binaries.

Hi Ram,

Script is not getting executed on changing the browser in config.js from "firefox" to "chrome".
The issue here was that you need to specify the path to your selenium jar and chrome driver exe in your protractor config file. Mine was installed globally in AppData folder so i have mentioned the path of both the variables i.e chrome driver and selenium standalone server in config.js and things started working for me as expected.
OR
Copy the selenium folder from the AppData folder and place it within the solution explorer under "protractor-cucumber-allure-master\node_modules\protractor\node_modules\webdriver-manager".

Json reports name issue

Hi Ram,
The json report get generated based on the option json:./reports/json/cucumber_report.json in Cucumber opts section result in json file gernated like cucumber_report1234.json(some additional number in the file name),so HTML report genrateion get failed as the Traget json name mismatch.

function timed out after 5000 milliseconds

protractor-cucumber-allure.zip
Hi,
I am able to create POM using your framework, but the problem is when i run " NPM Test". It is just opening the web browser and directly giving the results with out interacting with the web elements.So i have added CallBack in my each step def function. Then i am getting "function timed out after 5000 milliseconds" error message.

If i remove callBack it is running with out errors but giving results directly without interacting with application.
If i add callBack it is throwing ""function timed out after 5000 milliseconds".

Please could you help me with the solution.
``

CucumberHtmlReport is not a constructor

While executing , I am getting following error :
[17:14:37] E/launcher - CucumberHtmlReport is not a constructor
[17:14:37] E/launcher - TypeError: CucumberHtmlReport is not a constructor

browser.restart with Page object pattern do not work

Hi again!

I am facing a problem when trying to implement a restart between scenarios.

Changes I done :

registerHandler("BeforeScenario", { timeout: 10 * 1000 }, function() {
return browser.get(conf.baseUrl);
});

After(function(scenario) {
if (scenario.isFailed()) {
var attach = this.attach; // cucumber's world object has attach function which should be used
return browser.takeScreenshot().then(function(png) {
var decodedImage = new Buffer(png, "base64");
attach(decodedImage, "image/png");
return browser.restart();
})
}
});

And this restarts the browser between tests, but strangely I am getting exception same as mentioned in this ticket :

angular/protractor#3595

Can you please help here to understand what's happening. And how I can utilie the world object as explained in above solution (if really thats the only option )

I really want to close the browser in case of failure of the tests.

Upgrading cuucmber-protratctor-framework and cuucmber version to latest version breaks the tests

I upgraded to below

"cucumber": "^2.0.0",
"protractor": "^5.0.0",
"protractor-cucumber-framework": "^2.0.0"

and tests now break with error below

Unhandled rejection Error: Not empty
at TagExpressionParser.parse (C:\code\protractor-cucumber-allure-master\node
_modules\cucumber-tag-expressions\lib\tag_expression_parser.js:49:13)
at new ScenarioFilter (C:\code\protractor-cucumber-allure-master\node_module
s\cucumber\lib\scenario_filter.js:44:52)
at Cli. (C:\code\protractor-cucumber-allure-master\node_modules\c
ucumber\lib\cli\index.js:145:30)
at next (native)
at undefined.tryCatcher (C:\code\protractor-cucumber-allure-master\node_modu
les\bluebird\js\release\util.js:16:23)
at PromiseSpawn._promiseFulfilled (C:\code\protractor-cucumber-allure-master
\node_modules\bluebird\js\release\generators.js:97:49)
at Promise._settlePromise (C:\code\protractor-cucumber-allure-master\node_mo
dules\bluebird\js\release\promise.js:574:26)
at Promise._settlePromise0 (C:\code\protractor-cucumber-allure-master\node_m
odules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\code\protractor-cucumber-allure-master\node_m
odules\bluebird\js\release\promise.js:693:18)
at Async._drainQueue (C:\code\protractor-cucumber-allure-master\node_modules
\bluebird\js\release\async.js:133:16)
at Async._drainQueues (C:\code\protractor-cucumber-allure-master\node_module
s\bluebird\js\release\async.js:143:10)
at Immediate.Async.drainQueues (C:\code\protractor-cucumber-allure-master\no
de_modules\bluebird\js\release\async.js:17:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)

Not able to run test by command 'npm test'

when trying to run test after doing npm install, i am getting following error:
[23:42:12] I/launcher - Running 1 instances of WebDriver
[23:42:12] I/direct - Using ChromeDriver directly...
[23:42:12] E/direct - Error code: 135
[23:42:12] E/direct - Error message: Could not find update-config.json. Run 'webdriver-manager update' to download binaries.
[23:42:12] E/direct - Error: Could not find update-config.json. Run 'webdriver-manager update' to download binaries.
at IError (/Users/vijaysingh/Desktop/cucumber/protractor-cucumber-allure-master/node_modules/protractor/built/exitCodes.js:5:1)
at ProtractorError (/Users/vijaysingh/Desktop/cucumber/protractor-cucumber-allure-master/node_modules/protractor/built/exitCodes.js:10:9)
at BrowserError (/Users/vijaysingh/Desktop/cucumber/protractor-cucumber-allure-master/node_modules/protractor/built/exitCodes.js:51:9)
at Direct.getNewDriver (/Users/vijaysingh/Desktop/cucumber/protractor-cucumber-allure-master/node_modules/protractor/built/driverProviders/direct.js:62:31)
at Runner.createBrowser (/Users/vijaysingh/Desktop/cucumber/protractor-cucumber-allure-master/node_modules/protractor/built/runner.js:194:43)
at q.then.then (/Users/vijaysingh/Desktop/cucumber/protractor-cucumber-allure-master/node_modules/protractor/built/runner.js:338:29)
at _fulfilled (/Users/vijaysingh/Desktop/cucumber/protractor-cucumber-allure-master/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/Users/vijaysingh/Desktop/cucumber/protractor-cucumber-allure-master/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/Users/vijaysingh/Desktop/cucumber/protractor-cucumber-allure-master/node_modules/q/q.js:796:13)
at /Users/vijaysingh/Desktop/cucumber/protractor-cucumber-allure-master/node_modules/q/q.js:556:49
[23:42:12] E/launcher - Process exited with error code 135

I have tried running webdriver-manager update, but no luck.
Please suggest a way to fix as soon as possible.

Thank you
Vijay

Parallel execution does not work

When tried to run tests in parallel via multiConfig.js, 4 instances are launched with console message "I/launcher - Running 4 instances of WebDriver" and protractor execution hangs indefinitely.

Node: v8.11.2
npm: 5.6.0

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.