Skip to content

Commit edf91fa

Browse files
authored
feat(issues): added scenario outline example (#45)
1 parent c77dbdf commit edf91fa

File tree

10 files changed

+57
-32
lines changed

10 files changed

+57
-32
lines changed

config/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const config: Config = {
99

1010
SELENIUM_PROMISE_MANAGER: false,
1111

12-
baseUrl: "http://www.google.com",
12+
baseUrl: "https://www.google.com",
1313

1414
capabilities: {
1515
browserName: "chrome",
@@ -33,7 +33,7 @@ export const config: Config = {
3333
format: "json:./reports/json/cucumber_report.json",
3434
require: ["../../typeScript/stepdefinitions/*.js", "../../typeScript/support/*.js"],
3535
strict: true,
36-
tags: "@TypeScriptScenario or @CucumberScenario or @ProtractorScenario",
36+
tags: "@CucumberScenario or @ProtractorScenario or @TypeScriptScenario or @OutlineScenario",
3737
},
3838

3939
onComplete: () => {

features/ScenarioOutline.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Feature: To search keywords in google
2+
3+
@OutlineScenario
4+
Scenario Outline: Searching on google
5+
6+
Given I am on "<search>" search page
7+
When I type "<search keyword>"
8+
Then I click on search button
9+
Then I clear the search text
10+
11+
Examples:
12+
| search | search keyword |
13+
| google | cucumber |
14+
| cucumber | protractor |
15+
| protractor | typescript |
16+

features/cucumber.feature renamed to features/evalCucumber.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Feature: To search cucumber in google
22

33
@CucumberScenario
44
Scenario: Cucumber Google Search
5-
Given I am on google page
6-
When I type "Cucumber"
7-
Then I click on search button
5+
Given I am on "google" search page
6+
When I type "cucumber"
7+
When I click on search button
88
Then I clear the search text

features/protractor.feature renamed to features/evalProtractor.feature

Lines changed: 3 additions & 3 deletions
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 cucumber search results page
6-
When I type "Protractor"
7-
Then I click on search button
5+
Given I am on "cucumber" search page
6+
When I type "protractor"
7+
When I click on search button
88
Then I clear the search text

features/evalTypescript.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Feature: To search typescript in google
2+
3+
@TypeScriptScenario
4+
Scenario: Typescript Google Search
5+
Given I am on "protractor" search page
6+
When I type "typescript"
7+
When I click on search button
8+
Then I clear the search text
9+
Then I click on google logo

features/typescript.feature

Lines changed: 0 additions & 8 deletions
This file was deleted.

pages/searchPage.ts

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

33
export class SearchPageObject {
4-
public searchTextBox: any;
5-
public searchButton: any;
4+
public searchTextBox: ElementFinder;
5+
public searchButton: ElementFinder;
6+
public logo: ElementFinder;
67

78
constructor() {
89
this.searchTextBox = $("#lst-ib");
910
this.searchButton = $("input[value='Google Search']");
11+
this.logo = $('#logo > img');
1012
}
1113
}

stepdefinitions/homePage.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ const expect = chai.expect;
66

77
const search: SearchPageObject = new SearchPageObject();
88

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");
9+
Given(/^I am on "(.*?)" search page$/, async (text) => {
10+
if(text === 'google') {
11+
await expect(browser.getTitle()).to.eventually.equal("Google");
12+
} else if(text === 'cucumber') {
13+
await expect(browser.getTitle()).to.eventually.equal(text+" - Google Search");
14+
} else if(text === 'protractor') {
15+
await expect(browser.getTitle()).to.eventually.equal(text+" - Google Search");
16+
}
1917
});

stepdefinitions/search.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ When(/^I type "(.*?)"$/, async (text) => {
88
await search.searchTextBox.sendKeys(text);
99
});
1010

11-
Then(/^I click on search button$/, async () => {
11+
When(/^I click on search button$/, async () => {
1212
await browser.actions().sendKeys(protractor.Key.ENTER).perform();
1313
});
14+
15+
Then(/^I click on google logo$/, async () => {
16+
await search.logo.click();
17+
});

support/hooks.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const { BeforeAll, After, Status } = require("cucumber");
1+
const { BeforeAll, After, AfterAll, Status } = require("cucumber");
22
import * as fs from "fs";
33
import { browser } from "protractor";
44
import { config } from "../config/config";
55

6-
BeforeAll({timeout: 10 * 1000}, async () => {
6+
BeforeAll({timeout: 100 * 1000}, async () => {
77
await browser.get(config.baseUrl);
88
});
99

@@ -14,3 +14,7 @@ After(async function(scenario) {
1414
this.attach(screenShot, "image/png");
1515
}
1616
});
17+
18+
AfterAll({timeout: 100 * 1000}, async () => {
19+
await browser.quit();
20+
});

0 commit comments

Comments
 (0)