Skip to content

Commit 9179a92

Browse files
committed
Import initial du projet.
0 parents  commit 9179a92

18 files changed

+2134
-0
lines changed

Diff for: .editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
reports
2+
node_modules

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# cucumber-typescript-selenium
2+
3+
Un modèle de projet utilisant Cucumber, Typescript et Selenium pour des tests
4+
utilisateurs automatiques de bout en bout.

Diff for: cucumber.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let common = [
2+
'--require-module ts-node/register',
3+
'--require "./features/support/**/*.ts"',
4+
'--require "./features/steps/**/*.ts"',
5+
'--format json:./reports/report.json',
6+
'--format progress',
7+
].join(' ');
8+
9+
module.exports = {
10+
default: common + ' --tags "not @ignore"',
11+
selected: common + ' --tags "@selected and not @ignore"'
12+
};

Diff for: features/datatable.feature

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# language: fr
2+
Fonctionnalité: Une fonctionnalité avec des tables
3+
4+
Contexte:
5+
Etant donné les personnes suivantes:
6+
| Prénom | Nom |
7+
| Joe | Dalton |
8+
| Lucky | Luke |
9+
10+
Scénario: Joe
11+
Quand je recherche le nom de "Joe"
12+
Alors j'ai "Dalton"
13+
14+
Scénario: Luke
15+
Quand je recherche le nom de "Lucky"
16+
Alors j'ai "Luke"

Diff for: features/dragndrop.feature

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# language: fr
2+
Fonctionnalité: Glisser et déposer
3+
4+
@ignore
5+
Scénario: Un simple glisser-déposer
6+
Etant donné que je vais sur le site "https://bestvpn.org/html5demos/drag/"
7+
Quand je déplace "one" vers "bin"
8+
Alors je ne vois plus "one"

Diff for: features/google.feature

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# language: fr
2+
Fonctionnalité: Faire une recherche Google
3+
4+
Plan du scénario: Un simple recherche
5+
Etant donné que je vais sur Google
6+
Quand je recherche "<Terme recherché>"
7+
Alors je vois une liste de <Nombre de résultats> résultats
8+
Et "<Résultat>" fait partie de la liste des résultats
9+
10+
Exemples:
11+
| Terme recherché | Nombre de résultats | Résultat |
12+
| le monde | 5 | Le Monde.fr |
13+
| le progrès | 6 | Autre chose |

Diff for: features/steps/datatable_steps.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { expect } from 'chai';
2+
import { Given, TableDefinition, Then, When } from 'cucumber';
3+
4+
interface Person {
5+
firstName: string;
6+
lastName: string;
7+
}
8+
const people: Person[] = [];
9+
let found: Person;
10+
11+
Given('les personnes suivantes:', (dataTable: TableDefinition) => {
12+
dataTable.hashes().forEach((row: any) => {
13+
people.push({
14+
firstName: row.Prénom,
15+
lastName: row.Nom,
16+
});
17+
});
18+
});
19+
20+
When('je recherche le nom de {string}', (firstNameLookedFor) => {
21+
found = people.find((p) => p.firstName === firstNameLookedFor);
22+
});
23+
24+
Then('j\'ai {string}', (expectedLastName) => {
25+
expect(found.lastName).to.equal(expectedLastName);
26+
});

Diff for: features/steps/dragndrop_steps.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { expect } from 'chai';
2+
import { Given, Then, When } from 'cucumber';
3+
import { By } from 'selenium-webdriver';
4+
import { WebTestingWorld } from '../support/world';
5+
6+
Given('je vais sur le site {string}', async function(url) {
7+
const world = this as WebTestingWorld;
8+
await world.driver.get(url);
9+
});
10+
11+
When('je déplace {string} vers {string}', async function(from_id, to_id) {
12+
const world = this as WebTestingWorld;
13+
const fromElement = await world.driver.findElement(By.id(from_id));
14+
const toElement = await world.driver.findElement(By.id(to_id));
15+
16+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/28464
17+
// @ts-ignore
18+
const actions = world.driver.actions({bridge: true});
19+
20+
// const actions = world.driver.actions();
21+
await actions.dragAndDrop(fromElement, toElement).perform();
22+
});
23+
24+
Then('je ne vois plus {string}', async function(element_id) {
25+
const world = this as WebTestingWorld;
26+
const results = await world.driver.findElements(By.id(element_id));
27+
expect(results).to.be.empty;
28+
});

Diff for: features/steps/google_steps.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// tslint:disable:no-unused-expression
2+
import { expect } from 'chai';
3+
import { Given, Then, When } from 'cucumber';
4+
import { By, Key, until } from 'selenium-webdriver';
5+
import { WebTestingWorld } from '../support/world';
6+
7+
Given('je vais sur Google', { timeout: 10000 }, async function() {
8+
const world = this as WebTestingWorld;
9+
world.driver.get('https://www.google.fr');
10+
await world.driver.wait(until.elementLocated(By.name('q')), 10000);
11+
});
12+
13+
When('je recherche {string}', async function(searchTerm) {
14+
const world = this as WebTestingWorld;
15+
await world.driver.findElement(By.name('q')).sendKeys(searchTerm, Key.RETURN);
16+
});
17+
18+
Then(/je vois une liste de (\d+) résultats?/, async function(nbResults) {
19+
const world = this as WebTestingWorld;
20+
await world.driver.wait(until.titleContains('Recherche Google'));
21+
const results = await world.driver.findElements(By.css('h3.LC20lb'));
22+
expect(results.length).to.equal(nbResults);
23+
});
24+
25+
Then('{string} fait partie de la liste des résultats', async function(searchResult: string) {
26+
const world = this as WebTestingWorld;
27+
const results = await world.driver.findElements(By.css('h3.LC20lb'));
28+
const results_text = await Promise.all(results.map((r) => r.getText()));
29+
expect(results_text.some((t) => t.includes(searchResult))).to.be.true;
30+
});
31+
32+
// https://www.npmjs.com/package/selenium-webdriver

Diff for: features/support/global.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { setDefaultTimeout } from 'cucumber';
2+
3+
setDefaultTimeout(10 * 1000);

Diff for: features/support/hooks.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { After, Status } from 'cucumber';
2+
import { WebTestingWorld } from './world';
3+
4+
After(async function(scenario) {
5+
const world = this as WebTestingWorld;
6+
const _this = this;
7+
8+
if (scenario.result.status === Status.FAILED) {
9+
await world.driver.takeScreenshot().then((buffer) => {
10+
_this.attach(buffer, 'image/png');
11+
});
12+
}
13+
14+
await world.driver.quit();
15+
});

Diff for: features/support/world.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// tslint:disable:ban-types
2+
import { setWorldConstructor, World } from 'cucumber';
3+
import { Builder, WebDriver } from 'selenium-webdriver';
4+
5+
export class WebTestingWorld implements World {
6+
7+
public driver: WebDriver;
8+
public attach: Function;
9+
public parameters: {[key: string]: any};
10+
11+
constructor({attach, parameters}: {attach: Function, parameters: {[key: string]: any}}) {
12+
this.attach = attach;
13+
this.parameters = parameters;
14+
15+
this.driver = new Builder().forBrowser('chrome').build();
16+
// this.driver = new Builder().forBrowser('firefox').build();
17+
}
18+
}
19+
20+
setWorldConstructor(WebTestingWorld);

Diff for: package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "cucumber-typescript-selenium",
3+
"version": "0.0.1",
4+
"description": "Testing web application with Cucumber",
5+
"author": "Sylvain Desvé <[email protected]>",
6+
"homepage": "https://github.com/sylvaindesve/clean-todo/blob/master/README.md",
7+
"license" : "GPL-3.0-or-later",
8+
"repository": "github:sylvaindesve/cucumber-typescript-selenium",
9+
"scripts": {
10+
"clean": "rm -Rf ./reports/*",
11+
"report:build": "node ./scripts/html-report.js",
12+
"features": "npm-run-all features:all",
13+
"features:all": "cucumber-js -p default",
14+
"features:selected": "cucumber-js -p selected",
15+
"lint": "tslint -c tslint.json \"src/**/*.ts\"",
16+
"lint:fix": "tslint --fix -c tslint.json \"src/**/*.ts\""
17+
},
18+
"dependencies": {
19+
"@types/chai": "^4.1.7",
20+
"@types/cucumber": "^4.0.5",
21+
"@types/mocha": "^5.2.6",
22+
"@types/selenium-webdriver": "^3.0.15",
23+
"chai": "^4.2.0",
24+
"chromedriver": "^2.46.0",
25+
"cucumber": "^5.1.0",
26+
"cucumber-html-reporter": "^4.0.4",
27+
"mocha": "^5.2.0",
28+
"npm-run-all": "^4.1.5",
29+
"selenium-webdriver": "^4.0.0-alpha.1",
30+
"ts-node": "^8.0.2",
31+
"tslint": "^5.12.1",
32+
"tslint-eslint-rules": "^5.4.0",
33+
"typescript": "^3.3.3"
34+
}
35+
}

Diff for: scripts/html-report.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var reporter = require('cucumber-html-reporter');
2+
3+
var options = {
4+
theme: 'bootstrap',
5+
jsonFile: './reports/report.json',
6+
output: './reports/report.html',
7+
reportSuiteAsScenarios: true,
8+
launchReport: false
9+
};
10+
11+
reporter.generate(options);

Diff for: tsconfig.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"removeComments": true,
4+
"preserveConstEnums": true,
5+
"sourceMap": true,
6+
"strictFunctionTypes": true,
7+
"noImplicitAny": true,
8+
"noImplicitReturns": true,
9+
"noImplicitThis": true,
10+
"suppressImplicitAnyIndexErrors": true,
11+
"moduleResolution": "node",
12+
"stripInternal": false,
13+
"target": "es5",
14+
"outDir": "./.out",
15+
"lib": [
16+
"es7"
17+
]
18+
},
19+
"formatCodeOptions": {
20+
"indentSize": 2,
21+
"tabSize": 2
22+
}
23+
}

Diff for: tslint.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"defaultSeverity": "warning",
3+
"extends": [
4+
"tslint:recommended",
5+
"tslint-eslint-rules"
6+
],
7+
"jsRules": {},
8+
"rules": {
9+
"interface-name": ["never-prefix"],
10+
"quotemark": [true, "single", "avoid-escape"],
11+
"variable-name": [true, "allow-leading-underscore", "ban-keywords"]
12+
},
13+
"rulesDirectory": []
14+
}

0 commit comments

Comments
 (0)