Skip to content

Commit d004524

Browse files
authored
Cucumber3.0 support (#30)
* chore(upgrade):cucumber3.0 support * updated readme
1 parent bcba69d commit d004524

File tree

14 files changed

+337
-755
lines changed

14 files changed

+337
-755
lines changed

README.md

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
![protractorcucumbertypescript](https://raw.githubusercontent.com/igniteram/protractor-cucumber-typescript/master/images/protractor-typescript-cucumber.png)
1+
<p align="center">
2+
<img src= "./images/protractor-typescript-cucumber.png" height=300 alt="titleImage.png"/>
3+
</p>
4+
5+
<p align="center">
6+
<i><strong>This project demonstrates the basic protractor-cucumber-typescript framework project setup.
7+
</strong></i>
8+
<p>
9+
10+
<p align="center">
11+
<a href="https://circleci.com/gh/igniteram/protractor-cucumber-typescript/tree/master"><img alt="circleCI Status" src="https://circleci.com/gh/igniteram/protractor-cucumber-typescript/tree/master.svg?style=shield"></a>
12+
<a href="https://david-dm.org/igniteram/protractor-cucumber-typescript"><img alt="dependencies status" src="https://david-dm.org/igniteram/protractor-cucumber-typescript.svg"></a>
13+
<a href=""><img alt="typescript" src="https://badges.frapsoft.com/typescript/code/typescript.svg?v=101">
14+
<a href="https://opensource.org/licenses/MIT"><img alt="MIT License" src="https://img.shields.io/dub/l/vibe-d.svg"></a>
15+
</p>
16+
17+
---
218

3-
[![CircleCI](https://circleci.com/gh/igniteram/protractor-cucumber-typescript/tree/master.svg?style=shield)](https://circleci.com/gh/igniteram/protractor-cucumber-typescript/tree/master) [![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/ellerbrock/typescript-badges/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/8b225581-89f5-42bd-bd82-bfefb0e39a1f/big.png)](https://insight.sensiolabs.com/projects/8b225581-89f5-42bd-bd82-bfefb0e39a1f)
419

520
### Protractor-Cucumber-TypeScript Setup Guide
6-
This project demonstrates the basic protractor-cucumber-typescript framework project setup.
721

822
### Medium Article
923
Please do checkout my medium article which would give you more insight on this setup. [protractor-cucumber-typescript(Medium)](https://medium.com/@igniteram/e2e-testing-with-protractor-cucumber-using-typescript-564575814e4a)
@@ -51,7 +65,7 @@ npm run webdriver-start
5165

5266
* The below command would create an output folder named 'typeScript' and transpile the .ts files to .js.
5367
```
54-
npm run tsc
68+
npm run build
5569
```
5670

5771
* Now just run the test command which launches the Chrome Browser and runs the scripts.
@@ -74,57 +88,54 @@ Feature: To search typescript in google
7488
#### Writing Step Definitions
7589

7690
```
77-
import { browser } from 'protractor';
78-
import { SearchPageObject } from '../pages/searchPage';
79-
import { defineSupportCode } from 'cucumber';
80-
let chai = require('chai').use(require('chai-as-promised'));
81-
let expect = chai.expect;
91+
import { browser } from "protractor";
92+
import { SearchPageObject } from "../pages/searchPage";
93+
const { Given } = require("cucumber");
94+
const chai = require("chai").use(require("chai-as-promised"));
95+
const expect = chai.expect;
8296
83-
defineSupportCode(function ({Given}) {
84-
let search: SearchPageObject = new SearchPageObject();
97+
const search: SearchPageObject = new SearchPageObject();
8598
86-
Given(/^I am on google page$/, async () => {
87-
await expect(browser.getTitle()).to.eventually.equal('Google');
88-
});
89-
})
99+
Given(/^I am on google page$/, async () => {
100+
await expect(browser.getTitle()).to.eventually.equal("Google");
101+
});
90102
```
91103

92104
#### Writing Page Objects
93105
```
94-
import {$} from 'protractor';
95-
106+
import { $ } from "protractor";
107+
96108
export class SearchPageObject {
97-
public searchTextBox:any;
98-
public searchButton:any;
109+
public searchTextBox: any;
110+
public searchButton: any;
99111
100112
constructor() {
101-
this.searchTextBox = $("input[name='q']");
102-
this.searchButton = $("button[name='btnG']");
113+
this.searchTextBox = $("#lst-ib");
114+
this.searchButton = $("input[value='Google Search']");
103115
}
104116
}
105117
```
106118
#### Cucumber Hooks
107119
Following method takes screenshot on failure of each scenario
108120
```
109-
After(async function (scenarioResult) {
110-
let world = this;
111-
if (scenarioResult.isFailed()) {
112-
let screenShot = await browser.takeScreenshot();
113-
// screenShot is a base-64 encoded PNG
114-
world.attach(screenShot, 'image/png');
115-
}
116-
})
121+
After(async function(scenario) {
122+
if (scenario.result.status === Status.FAILED) {
123+
// screenShot is a base-64 encoded PNG
124+
const screenShot = await browser.takeScreenshot();
125+
this.attach(screenShot, "image/png");
126+
}
127+
});
117128
```
118129
#### CucumberOpts Tags
119130
Following configuration shows to call specific tags from feature files
120131
```
121132
cucumberOpts: {
122133
compiler: "ts:ts-node/register",
134+
format: "json:./reports/json/cucumber_report.json",
135+
require: ["../../stepdefinitions/*.ts", "../../support/*.ts"],
123136
strict: true,
124-
format: ["pretty"],
125-
require: ['../StepDefinitions/*.ts', '../Support/*.ts'],
126-
tags: '@TypeScriptScenario or @CucumberScenario or @ProtractorScenario'
127-
}
137+
tags: "@TypeScriptScenario or @CucumberScenario or @ProtractorScenario",
138+
},
128139
```
129140
#### HTML Reports
130141
Currently this project has been integrated with [cucumber-html-reporter](https://github.com/gkushang/cucumber-html-reporter), which is generated in the `reports` folder when you run `npm test`.

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
1515
- sudo dpkg -i google-chrome.deb
1616
- sleep 3
17-
- yarn run tsc
17+
- yarn run build
1818
- yarn run webdriver-update
1919
- yarn run webdriver-start:
2020
background: true

config/config.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
import { browser, Config } from 'protractor';
1+
import * as path from "path";
2+
import { browser, Config } from "protractor";
3+
import { Reporter } from "../support/reporter";
4+
const jsonReports = process.cwd() + "/reports/json";
25

3-
export let config: Config = {
6+
export const config: Config = {
47

5-
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
8+
seleniumAddress: "http://127.0.0.1:4444/wd/hub",
69

710
SELENIUM_PROMISE_MANAGER: false,
811

9-
baseUrl: 'http://www.google.com',
12+
baseUrl: "http://www.google.com",
1013

1114
capabilities: {
12-
browserName: 'chrome'
15+
browserName: "chrome",
1316
},
1417

15-
framework: 'custom',
16-
frameworkPath: require.resolve('protractor-cucumber-framework'),
18+
framework: "custom",
19+
frameworkPath: require.resolve("protractor-cucumber-framework"),
1720

1821
specs: [
19-
'../../features/*.feature'
22+
"../../features/*.feature",
2023
],
2124

2225
onPrepare: () => {
23-
2426
browser.ignoreSynchronization = true;
2527
browser.manage().window().maximize();
26-
28+
Reporter.createDirectory(jsonReports);
2729
},
30+
2831
cucumberOpts: {
2932
compiler: "ts:ts-node/register",
33+
format: "json:./reports/json/cucumber_report.json",
34+
require: ["../../stepdefinitions/*.ts", "../../support/*.ts"],
3035
strict: true,
31-
format: ['pretty'],
32-
require: ['../../stepdefinitions/*.ts', '../../support/*.ts'],
33-
tags: '@TypeScriptScenario or @CucumberScenario or @ProtractorScenario'
34-
}
35-
};
36+
tags: "@TypeScriptScenario or @CucumberScenario or @ProtractorScenario",
37+
},
38+
39+
onComplete: () => {
40+
Reporter.createHTMLReport();
41+
},
42+
};

features/protractor.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Feature: To search protractor in google
22

33
@ProtractorScenario
44
Scenario: Protractor Google Search
5-
Given I am on google page
5+
Given I am on cucumber search results page
66
When I type "Protractor"
77
Then I click on search button
88
Then I clear the search text

features/typescript.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Feature: To search typescript in google
22

33
@TypeScriptScenario
44
Scenario: Typescript Google Search
5-
Given I am on google page
5+
Given I am on protractor search results page
66
When I type "Typescript"
77
Then I click on search button
88
Then I clear the search text

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "protractor-typescript-cucumber",
3-
"version": "2.0.0",
3+
"version": "3.0.0",
44
"license": "MIT",
55
"description": "To demostrate protractor cucumber tests for angular/non angular apps with allure report framework",
66
"homepage": "https://github.com/igniteram/protractor-cucumber-typescript",
@@ -20,27 +20,28 @@
2020
],
2121
"main": "index.js",
2222
"scripts": {
23-
"tsc": "tsc",
23+
"build": "tsc",
24+
"clean": "rimraf typeScript/",
25+
"clean-build": "npm run clean && npm run build",
2426
"test": "protractor typeScript/config/config.js",
2527
"webdriver-update": "webdriver-manager update",
2628
"webdriver-start": "webdriver-manager start"
2729
},
2830
"author": "Ram Pasala <[email protected]>",
2931
"devDependencies": {
30-
"@types/cucumber": "0.0.38",
32+
"@types/cucumber": "^2.0.4",
3133
"@types/node": "^8.0.3",
32-
"@types/selenium-webdriver": "^3.0.0",
34+
"@types/selenium-webdriver": "^3.0.7",
3335
"chai": "^4.0.2",
3436
"chai-as-promised": "^7.0.0",
35-
"cucumber": "^2.3.0",
37+
"cucumber": "^3.0.4",
38+
"cucumber-html-reporter": "^3.0.4",
3639
"mkdirp": "^0.5.1",
37-
"protractor-cucumber-framework": "^3.1.1"
38-
},
39-
"dependencies": {
40-
"cucumber-html-reporter": "^2.0.0",
4140
"protractor": "^5.1.2",
42-
"ts-node": "^3.1.0",
43-
"typescript": "^2.2.1"
41+
"protractor-cucumber-framework": "^4.0.8",
42+
"rimraf": "^2.6.2",
43+
"ts-node": "^3.3.0",
44+
"typescript": "^2.5.3"
4445
},
4546
"repository": "https://github.com/igniteram/protractor-cucumber-typescript"
4647
}

pages/searchPage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { $ } from 'protractor';
1+
import { $ } from "protractor";
22

33
export class SearchPageObject {
44
public searchTextBox: any;
55
public searchButton: any;
66

77
constructor() {
8-
this.searchTextBox = $("input[name='q']");
8+
this.searchTextBox = $("#lst-ib");
99
this.searchButton = $("input[value='Google Search']");
1010
}
11-
}
11+
}

stepdefinitions/clearPage.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { SearchPageObject } from '../pages/searchPage';
2-
import { defineSupportCode } from 'cucumber';
1+
import { SearchPageObject } from "../pages/searchPage";
2+
const { Then } = require("cucumber");
33

4-
defineSupportCode(function ({ Then }) {
5-
let search: SearchPageObject = new SearchPageObject();
4+
const search: SearchPageObject = new SearchPageObject();
65

7-
Then(/^I clear the search text$/, async () => {
8-
await search.searchTextBox.clear();
9-
});
10-
})
6+
Then(/^I clear the search text$/, async () => {
7+
await search.searchTextBox.clear();
8+
});

stepdefinitions/homePage.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import { browser } from 'protractor';
2-
import { SearchPageObject } from '../pages/searchPage';
3-
import { defineSupportCode } from 'cucumber';
4-
let chai = require('chai').use(require('chai-as-promised'));
5-
let expect = chai.expect;
6-
7-
defineSupportCode(function ({ Given }) {
8-
let search: SearchPageObject = new SearchPageObject();
9-
10-
Given(/^I am on google page$/, async () => {
11-
await expect(browser.getTitle()).to.eventually.equal('Google');
12-
});
13-
})
1+
import { browser } from "protractor";
2+
import { SearchPageObject } from "../pages/searchPage";
3+
const { Given } = require("cucumber");
4+
const chai = require("chai").use(require("chai-as-promised"));
5+
const expect = chai.expect;
6+
7+
const search: SearchPageObject = new SearchPageObject();
8+
9+
Given(/^I am on google page$/, async () => {
10+
await expect(browser.getTitle()).to.eventually.equal("Google");
11+
});
12+
13+
Given(/^I am on cucumber search results page$/, async () => {
14+
await expect(browser.getTitle()).to.eventually.equal("Cucumber - Google Search");
15+
});
16+
17+
Given(/^I am on protractor search results page$/, async () => {
18+
await expect(browser.getTitle()).to.eventually.equal("Protractor - Google Search");
19+
});

stepdefinitions/search.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { SearchPageObject } from '../pages/searchPage';
2-
import { defineSupportCode } from 'cucumber';
1+
import { browser, protractor } from "protractor";
2+
import { SearchPageObject } from "../pages/searchPage";
3+
const { When, Then } = require("cucumber");
34

4-
defineSupportCode(function ({ When, Then }) {
5-
let search: SearchPageObject = new SearchPageObject();
6-
When(/^I type "(.*?)"$/, async (text) => {
7-
await search.searchTextBox.sendKeys(text);
8-
});
5+
const search: SearchPageObject = new SearchPageObject();
96

10-
Then(/^I click on search button$/, async () => {
11-
await search.searchButton.click();
12-
});
7+
When(/^I type "(.*?)"$/, async (text) => {
8+
await search.searchTextBox.sendKeys(text);
9+
});
1310

14-
})
11+
Then(/^I click on search button$/, async () => {
12+
await browser.actions().sendKeys(protractor.Key.ENTER).perform();
13+
});

0 commit comments

Comments
 (0)