Skip to content

Commit 76b51b5

Browse files
committed
Gherkin Example
1 parent 5e3d725 commit 76b51b5

File tree

10 files changed

+310
-8
lines changed

10 files changed

+310
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ typings/
5858
.env
5959

6060
dist/
61+
62+
report/

html-report.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
var reporter = require('cucumber-html-reporter');
3+
4+
var options = {
5+
theme: 'bootstrap',
6+
jsonFile: 'report/cucumber.json',
7+
output: 'report/cucumber.html',
8+
reportSuiteAsScenarios: true,
9+
scenarioTimestamp: true,
10+
launchReport: true,
11+
metadata: {}
12+
};
13+
14+
reporter.generate(options);

karma-gherkin.conf.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = function(config) {
2+
"use strict";
3+
4+
require("./karma.conf")(config);
5+
config.set({
6+
7+
ui5: {
8+
logAssertions: true,
9+
logHTMLFilePath: true,
10+
testpage: "webapp/test/gherkin/gherkinTests.qunit.html"
11+
},
12+
13+
cucumberReporter: {
14+
out: "report/cucumber.json"
15+
},
16+
17+
reporters: ["progress", "cucumber"],
18+
19+
browsers: ["CustomChromeHeadless"],
20+
21+
singleRun: true
22+
23+
});
24+
};

package-lock.json

Lines changed: 128 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"lint": "eslint webapp",
99
"karma": "karma start",
1010
"karma-ci": "rimraf coverage && karma start karma-ci.conf.js",
11+
"karma-gherkin": "rimraf report && karma start karma-gherkin.conf.js && node html-report.js",
1112
"watch": "npm run karma",
1213
"test": "npm run lint && npm run karma-ci",
1314
"build": "ui5 build -a --clean-dest",
@@ -17,10 +18,12 @@
1718
"dependencies": {},
1819
"devDependencies": {
1920
"@ui5/cli": "^2.4.1",
21+
"cucumber-html-reporter": "^5.2.0",
2022
"eslint": "^7.7.0",
2123
"karma": "^4.4.1",
2224
"karma-chrome-launcher": "^3.1.0",
2325
"karma-coverage": "^2.0.3",
26+
"karma-cucumber-reporter": "^1.0.4",
2427
"karma-ui5": "^2.2.0",
2528
"local-web-server": "^4.2.1",
2629
"rimraf": "^3.0.2"

webapp/test/gherkin/Filter.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Feature: Filtering
2+
Lorem ipsum
3+
4+
Background:
5+
Given I have started the app
6+
And I can see 2 items in the list
7+
8+
Scenario: Filtering for 'Active' items
9+
When I filter for active items
10+
Then I can see 1 item in the list
11+
12+
Scenario: Filtering for 'Completed' items
13+
When I filter for completed items
14+
Then I can see 1 item in the list

webapp/test/gherkin/Steps.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
sap.ui.define([
2+
"sap/base/Log",
3+
"sap/ui/test/gherkin/StepDefinitions",
4+
"sap/ui/test/Opa5",
5+
"sap/ui/test/matchers/AggregationLengthEquals",
6+
"sap/ui/test/matchers/PropertyStrictEquals",
7+
"sap/ui/test/matchers/Properties",
8+
"sap/ui/test/actions/EnterText",
9+
"sap/ui/test/actions/Press"
10+
], function(
11+
Log, StepDefinitions, Opa5,
12+
AggregationLengthEquals, PropertyStrictEquals, Properties, EnterText, Press
13+
) {
14+
"use strict";
15+
16+
var sViewName = "sap.ui.demo.todo.view.App";
17+
// var sAddToItemInputId = "addTodoItemInput";
18+
// var sSearchTodoItemsInputId = "searchTodoItemsInput";
19+
var sItemListId = "todoList";
20+
// var sClearCompletedId = "clearCompleted";
21+
22+
var oOpa5 = new Opa5();
23+
24+
var Steps = StepDefinitions.extend("sap.ui.demo.todo.test.gherkin.Steps", {
25+
init: function() {
26+
27+
this.register(/^I have started the app$/i, function() {
28+
oOpa5.iStartMyUIComponent({
29+
componentConfig: {
30+
name: "sap.ui.demo.todo",
31+
async: true,
32+
manifest: true
33+
}
34+
});
35+
});
36+
37+
this.register(/^I can see ([0-9]+) items? in the list$/i, function(sItemCount) {
38+
var iItemCount = parseInt(sItemCount, 10);
39+
oOpa5.waitFor({
40+
id: sItemListId,
41+
viewName: sViewName,
42+
matchers: [new AggregationLengthEquals({
43+
name: "items",
44+
length: iItemCount
45+
})],
46+
success: function() {
47+
Opa5.assert.ok(true, "The list has " + iItemCount + " item(s)");
48+
},
49+
errorMessage: "List does not have expected number of items '" + iItemCount + "'."
50+
});
51+
});
52+
53+
this.register(/^I filter for (active|completed) items$/i, function(filterKey) {
54+
oOpa5.waitFor({
55+
viewName: sViewName,
56+
controlType: "sap.m.SegmentedButtonItem",
57+
matchers: [
58+
new Properties({ key: filterKey })
59+
],
60+
actions: [new Press()],
61+
errorMessage: "SegmentedButton can not be pressed"
62+
});
63+
});
64+
65+
},
66+
67+
closeApplication: function() {
68+
Log.info("Closing application");
69+
}
70+
});
71+
72+
return Steps;
73+
74+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Gherkin tests for Todo App</title>
6+
7+
<script id="sap-ui-bootstrap"
8+
src="../../resources/sap-ui-core.js"
9+
data-sap-ui-theme="sap_fiori_3"
10+
data-sap-ui-resourceroots='{
11+
"sap.ui.demo.todo": "../../"
12+
}'
13+
data-sap-ui-language="EN"
14+
data-sap-ui-animation="false"
15+
data-sap-ui-compatVersion="edge"
16+
data-sap-ui-async="true">
17+
</script>
18+
19+
<link rel="stylesheet" type="text/css" href="../../resources/sap/ui/thirdparty/qunit-2.css">
20+
21+
<script src="../../resources/sap/ui/thirdparty/qunit-2.js"></script>
22+
<script src="../../resources/sap/ui/qunit/qunit-junit.js"></script>
23+
24+
<script src="gherkinTests.qunit.js"></script>
25+
</head>
26+
<body>
27+
<div id="qunit"></div>
28+
<div id="qunit-fixture"></div>
29+
</body>
30+
</html>

0 commit comments

Comments
 (0)