webship-js 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintignore ADDED
@@ -0,0 +1,4 @@
1
+ node_modules
2
+ ./node_modules
3
+ */node_modules
4
+ nightwatch.conf.js
package/.eslintrc.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "extends": [
3
+ "airbnb-base"
4
+ ],
5
+ "root": true,
6
+ "env": {
7
+ "browser": true,
8
+ "node": true
9
+ },
10
+ "globals": {
11
+ "loadjs": true
12
+ },
13
+ "rules": {
14
+ "consistent-return": ["off"],
15
+ "no-underscore-dangle": ["off"],
16
+ "max-nested-callbacks": ["warn", 5],
17
+ "import/no-mutable-exports": ["warn"],
18
+ "no-console": ["off"],
19
+ "no-plusplus": ["warn", {
20
+ "allowForLoopAfterthoughts": true
21
+ }],
22
+ "no-param-reassign": ["off"],
23
+ "no-prototype-builtins": ["off"],
24
+ "valid-jsdoc": ["warn", {
25
+ "prefer": {
26
+ "returns": "return",
27
+ "property": "prop"
28
+ },
29
+ "requireReturn": false
30
+ }],
31
+ "no-unused-vars": ["warn"],
32
+ "operator-linebreak": ["error", "after", { "overrides": { "?": "ignore", ":": "ignore" } }]
33
+ }
34
+ }
package/README.md CHANGED
@@ -7,26 +7,14 @@
7
7
  Webship JS has a ready step definitions for automated functional testing.
8
8
 
9
9
  ### Using:
10
- * Nightwatch.js
11
- * Cucumber-js
10
+ * [Cucumber-js](https://github.com/cucumber/cucumber-js)
11
+ * [Nightwatch.js](https://github.com/nightwatchjs/nightwatch)
12
12
 
13
13
 
14
14
  ### Webship-js Documentations
15
15
  All you need to know about [webship-js Docs](https://webship.gitbook.io/webship-js-docs/).
16
16
 
17
17
 
18
- ## How to install using NPM
19
-
20
- ```
21
- npm i webship-js
22
- ```
23
-
24
- ## How to install using Yarn
25
-
26
- ```
27
- yarn i webship-js
28
- ```
29
-
30
18
  ## How to configure your project to test using webship-js steps
31
19
 
32
20
  ### Install node js and yarn
@@ -70,5 +58,32 @@ google-chrome --version
70
58
 
71
59
  ### Run selenium standalone server
72
60
 
61
+ ```
62
+ cd ~
63
+ wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-3.141.59/selenium-server-standalone-3.141.59.jar
64
+ java -jar selenium-server-standalone-3.141.59.jar -port 4444
65
+ ```
73
66
 
67
+ ## How to install using Yarn
74
68
 
69
+ ```
70
+ yarn add webship-js
71
+ ```
72
+
73
+ ## How to install using NPM
74
+
75
+ ```
76
+ npm install webship-js
77
+ ```
78
+
79
+ ## Automated Functional Acceptance Testing
80
+
81
+ ```
82
+ yarn test
83
+ ```
84
+
85
+ Or
86
+
87
+ ```
88
+ npm test
89
+ ```
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const conf = require('../nightwatch.conf.js');
5
+
6
+ /**
7
+ * Folders Path Array variable
8
+ *
9
+ * Set and Get folders path exist in (--config) tag and
10
+ * (--src_folder) tag added in nodejs command line
11
+ */
12
+ let foldersPath = [];
13
+ function setFoldersPath(value) {
14
+ value.forEach((element) => {
15
+ foldersPath.push(element);
16
+ });
17
+ }
18
+
19
+ /**
20
+ * Output Format name variable
21
+ *
22
+ * Set and Get Output Format exist in (--format) tag added
23
+ * in nodejs command line
24
+ */
25
+ let outputFormat = 'stdout-spaces';
26
+ function setOutputFormat(value) { outputFormat = value; }
27
+
28
+ /**
29
+ * Start with Function.
30
+ *
31
+ * Return list of array items that start with
32
+ * (Given, Then, When, /** ,* , *\).
33
+ *
34
+ * @param {array} stepsList The full step-definitions file lines list
35
+ * @return {array} The array has only lines startsWith words chosen
36
+ */
37
+ function startWith(stepsList) {
38
+ return (stepsList.startsWith('Given') ||
39
+ stepsList.startsWith('Then') ||
40
+ stepsList.startsWith('When') ||
41
+ stepsList.startsWith('/**') ||
42
+ stepsList.startsWith('* ') ||
43
+ stepsList.startsWith('*/'));
44
+ }
45
+
46
+ /**
47
+ * Filter Step Definitions
48
+ *
49
+ * @param {array} stepsList The step definitions array is sent to filter
50
+ * by startsWith words chosen
51
+ * @return {array} Step definitions filtered array
52
+ */
53
+ function callStartsWith(stepsList) {
54
+ return stepsList.filter(startWith);
55
+ }
56
+
57
+ /**
58
+ * Clean Steps List
59
+ *
60
+ * Return list of array items cleand from unreadable chars
61
+ *
62
+ * @param {array} stepsList The step definitions array before clean
63
+ * unreadable signs
64
+ * @return {array} The step definitions cleaned array
65
+ */
66
+ function stepsCleanList(stepsList) {
67
+ let stepComment = '';
68
+ const newStepsList = [];
69
+
70
+ stepsList.forEach((element) => {
71
+ if (element.startsWith('* ')) {
72
+ element = element.replace('* ', '');
73
+
74
+ if (stepComment === '') stepComment = element;
75
+ else stepComment = `${stepComment}\r\n${element}`;
76
+ } else if (!element.startsWith('/**') && !element.startsWith('*/')) {
77
+ const filter1 = element.split('$/');
78
+ const filter2 = filter1[0].replace('(/^', ' ');
79
+
80
+ if (stepComment !== '') {
81
+ if (outputFormat.startsWith('html')) newStepsList.push(`${filter2}\r\n<div>${stepComment}</div>`);
82
+ else newStepsList.push(`${filter2}\r\n${stepComment}`);
83
+ } else newStepsList.push(filter2);
84
+
85
+ stepComment = '';
86
+ }
87
+ });
88
+ return newStepsList;
89
+ }
90
+
91
+ function srcFolderPaths(path) {
92
+ const splitConfig = path.split('=');
93
+ const pathsLine = splitConfig[1];
94
+ const paths = pathsLine.split(' ');
95
+
96
+ setFoldersPath(paths);
97
+ }
98
+
99
+ for (let i = 2; i < process.argv.length; i++) {
100
+ if (process.argv[i].startsWith('--config')) {
101
+ const splitConfig = process.argv[i].split('=');
102
+ const path = splitConfig[1];
103
+ const configPath = require(path);
104
+
105
+ let configPathsArray = [];
106
+ configPathsArray = configPath.src_folders;
107
+
108
+ setFoldersPath(configPathsArray);
109
+ } else if (process.argv[i].startsWith('--src_folders')) {
110
+ srcFolderPaths(process.argv[i]);
111
+ } else if (process.argv[i].startsWith('--format')) {
112
+ setOutputFormat(process.argv[i].split('=')[1]);
113
+ }
114
+ }
115
+
116
+ if (foldersPath.length === 0) foldersPath = conf.src_folders;
117
+
118
+ foldersPath.forEach((folderPath) => {
119
+ fs.readdir(folderPath, (err, files) => {
120
+ if (err) {
121
+ return console.log(`Unable to scan directory: ${err}`);
122
+ }
123
+
124
+ files.forEach((file) => {
125
+ fs.readFile(`./${folderPath}/${file}`, 'utf8', (err, data) => {
126
+ if (err) {
127
+ throw new Error(err);
128
+ }
129
+ const contentLines = data.split('\n');
130
+ const contentTrimmed = contentLines.map((element) => element.trim());
131
+
132
+ const stepsStartWith = callStartsWith(contentTrimmed);
133
+ const stepsList = stepsCleanList(stepsStartWith);
134
+
135
+ stepsList.forEach((element) => {
136
+ if (outputFormat.startsWith('stdout')) {
137
+ console.log(element);
138
+ } else if (outputFormat.startsWith('html')) {
139
+ console.log(`<div>${element}</div>`);
140
+ } else { console.log(element); }
141
+ });
142
+ });
143
+ });
144
+ });
145
+ });
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const conf = require('../nightwatch.conf.js');
5
+
6
+ /**
7
+ * Folders Path Array variable
8
+ *
9
+ * Set and Get folders path exist in (--config) tag and
10
+ * (--src_folder) tag added in nodejs command line
11
+ */
12
+ let foldersPath = [];
13
+ function setFoldersPath(value) {
14
+ value.forEach((element) => {
15
+ foldersPath.push(element);
16
+ });
17
+ }
18
+
19
+ /**
20
+ * Output Format name variable
21
+ *
22
+ * Set and Get Output Format exist in (--format) tag added
23
+ * in nodejs command line
24
+ */
25
+ let outputFormat = 'stdout-spaces';
26
+ function setOutputFormat(value) { outputFormat = value; }
27
+
28
+ /**
29
+ * Start with Function.
30
+ *
31
+ * Return list of array items that start with (Given, Then, When).
32
+ *
33
+ * @param {array} stepsList The full step-definitions file lines list
34
+ * @return {array} The array has only lines startsWith words chosen
35
+ */
36
+ function startWith(stepsList) {
37
+ return (stepsList.startsWith('Given') ||
38
+ stepsList.startsWith('Then') ||
39
+ stepsList.startsWith('When'));
40
+ }
41
+
42
+ /**
43
+ * Filter Step Definitions
44
+ *
45
+ * @param {array} stepsList The step definitions array is sent to filter
46
+ * by startsWith words chosen
47
+ * @return {array} Step definitions filtered array
48
+ */
49
+ function callStartsWith(stepsList) {
50
+ return stepsList.filter(startWith);
51
+ }
52
+
53
+ /**
54
+ * Clean Steps List
55
+ *
56
+ * Return list of array items cleand from unreadable chars
57
+ *
58
+ * @param {array} stepsList The step definitions array before clean
59
+ * unreadable signs
60
+ * @return {array} The step definitions cleaned array
61
+ */
62
+ function stepsCleanList(stepsList) {
63
+ const newStepsList = [];
64
+
65
+ stepsList.forEach((element) => {
66
+ const filter1 = element.split('$/');
67
+ const filter2 = filter1[0].replace('(/^', ' ');
68
+
69
+ newStepsList.push(filter2);
70
+ });
71
+ return newStepsList;
72
+ }
73
+
74
+ function srcFolderPaths(path) {
75
+ const splitConfig = path.split('=');
76
+ const pathsLine = splitConfig[1];
77
+ const paths = pathsLine.split(' ');
78
+
79
+ setFoldersPath(paths);
80
+ }
81
+
82
+ for (let i = 2; i < process.argv.length; i++) {
83
+ if (process.argv[i].startsWith('--config')) {
84
+ const splitConfig = process.argv[i].split('=');
85
+ const path = splitConfig[1];
86
+ const configPath = require(path);
87
+
88
+ let configPathsArray = [];
89
+ configPathsArray = configPath.src_folders;
90
+
91
+ setFoldersPath(configPathsArray);
92
+ } else if (process.argv[i].startsWith('--src_folders')) {
93
+ srcFolderPaths(process.argv[i]);
94
+ } else if (process.argv[i].startsWith('--format')) {
95
+ setOutputFormat(process.argv[i].split('=')[1]);
96
+ }
97
+ }
98
+
99
+ if (foldersPath.length === 0) foldersPath = conf.src_folders;
100
+
101
+ foldersPath.forEach((folderPath) => {
102
+ fs.readdir(folderPath, (err, files) => {
103
+ if (err) {
104
+ return console.log(`Unable to scan directory: ${err}`);
105
+ }
106
+
107
+ files.forEach((file) => {
108
+ fs.readFile(`./${folderPath}/${file}`, 'utf8', (err, data) => {
109
+ if (err) {
110
+ throw new Error(err);
111
+ }
112
+ const contentLines = data.split('\n');
113
+ const contentTrimmed = contentLines.map((element) => element.trim());
114
+
115
+ const stepsStartWith = callStartsWith(contentTrimmed);
116
+ const stepsList = stepsCleanList(stepsStartWith);
117
+
118
+ stepsList.forEach((element) => {
119
+ if (outputFormat.startsWith('stdout')) {
120
+ console.log(element);
121
+ } else if (outputFormat.startsWith('html')) {
122
+ console.log(`<div>${element}</div>`);
123
+ } else { console.log(element); }
124
+ });
125
+ });
126
+ });
127
+ });
128
+ });
@@ -0,0 +1,37 @@
1
+ # Template NodeJS build
2
+
3
+ # This template allows you to validate your NodeJS code.
4
+ # The workflow allows running tests and code linting on the default branch.
5
+
6
+ image: node:16
7
+
8
+ pipelines:
9
+ default:
10
+ - parallel:
11
+ - step:
12
+ name: selenium linting
13
+ script:
14
+ - docker version
15
+ - docker pull selenium/hub:latest
16
+ - docker pull selenium/standalone-chrome
17
+ - docker run -d -p 4444:4444 --name selenium-hub selenium/hub
18
+ - docker run --link selenium-hub:hub selenium/node-chrome
19
+ - chmod +x $DRIVERPATH
20
+ - mvn compiler:compile test allure:report
21
+ services:
22
+ - docker
23
+ caches:
24
+ - node
25
+ - step:
26
+ name: Build and Test
27
+ max-time: 3
28
+ script:
29
+ - sleep 1m
30
+ - yarn install
31
+ - yarn run test
32
+ caches:
33
+ - node
34
+
35
+
36
+ options:
37
+ docker: true
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
6
  "directories": {
7
7
  "test": "test"
8
8
  },
9
+ "engines": {
10
+ "yarn": ">= 1.6",
11
+ "node": ">= 16.0"
12
+ },
9
13
  "scripts": {
10
-
11
- "test": "nightwatch --format @cucumber/pretty-formatter --format-options '{\"colorsEnabled\": true}' --format-options '{\"theme\": {\"feature keyword\":[\"bold\",\"blue\"],\"feature name\":[\"blue\",\"underline\"],\"feature description\":[\"blueBright\"],\"scenario keyword\":[\"bold\",\"magenta\"],\"scenario name\":[\"magenta\",\"underline\"],\"step keyword\":[\"bold\",\"green\"],\"step text\":[\"greenBright\",\"italic\"]}}' --format json:./tests/reports/cucumber-report-$( date '+%Y-%m-%d_%H-%M' ).json --format html:./tests/reports/cucumber-report-$( date '+%Y-%m-%d_%H-%M' ).html"
12
-
14
+ "test": "nightwatch --format @cucumber/pretty-formatter --format-options '{\"colorsEnabled\": true}' --format-options '{\"theme\": {\"feature keyword\":[\"bold\",\"blue\"],\"feature name\":[\"blue\",\"underline\"],\"feature description\":[\"blueBright\"],\"scenario keyword\":[\"bold\",\"magenta\"],\"scenario name\":[\"magenta\",\"underline\"],\"step keyword\":[\"bold\",\"green\"],\"step text\":[\"greenBright\",\"italic\"]}}' --format json:./tests/reports/cucumber-report-$( date '+%Y-%m-%d_%H-%M' ).json --format html:./tests/reports/cucumber-report-$( date '+%Y-%m-%d_%H-%M' ).html",
15
+ "lint:js": "node ./node_modules/eslint/bin/eslint.js --config=.eslintrc.json ."
13
16
  },
14
17
  "repository": {
15
18
  "type": "git",
@@ -23,11 +26,17 @@
23
26
  "homepage": "https://github.com/webship/webship-js",
24
27
  "dependencies": {
25
28
  "@cucumber/cucumber": "*",
26
- "chromedriver": "*",
27
29
  "@cucumber/pretty-formatter": "^1.0.0-alpha.2",
28
- "eslint": "^7.32.0",
29
- "mocha": "^9.1.3",
30
+ "chromedriver": "*",
30
31
  "geckodriver": "*",
32
+ "eslint": "~8.0",
33
+ "eslint-config-airbnb-base": "^15.0.0",
34
+ "eslint-plugin-import": "^2.25.4",
35
+ "mocha": "^9.1.3",
31
36
  "nightwatch": "^2.1.7"
32
- }
37
+ },
38
+ "bin":{
39
+ "webship-js-dl" : "./bin/webship-js-dl.js",
40
+ "webship-js-di" : "./bin/webship-js-di.js"
41
+ }
33
42
  }
@@ -1,15 +1,17 @@
1
- const {Given} = require('@cucumber/cucumber');
2
- const {When, Before} = require('@cucumber/cucumber');
3
- const {Then} = require('@cucumber/cucumber');
1
+ const { Given } = require('@cucumber/cucumber');
2
+ const { When, Before } = require('@cucumber/cucumber');
3
+ const { Then } = require('@cucumber/cucumber');
4
4
 
5
- Given(/^I go to "([^"]*)?"$/, function(url) {
6
- return browser.url(url);
7
- });
5
+ /**
6
+ * webship.js step definitions
7
+ * inside webship-js backage
8
+ */
9
+ Given(/^I go to "([^"]*)?"$/, (url) => browser.url(url));
8
10
 
9
- Then(/^I should( not)* see "([^"]*)?"$/, function(negativeCase, expectedText) {
11
+ Then(/^I should( not)* see "([^"]*)?"$/, (negativeCase, expectedText) => {
10
12
  if (negativeCase) {
11
13
  return browser.assert.not.textContains('body', expectedText);
12
14
  }
13
-
15
+
14
16
  return browser.assert.textContains('body', expectedText);
15
17
  });
@@ -1,36 +0,0 @@
1
- image: node:16
2
- pipelines:
3
- branches:
4
- 1.0.x:
5
- - step:
6
- name: "Webship-js CI"
7
- caches:
8
- - node
9
- script:
10
- - npm install
11
- - npm run http://selenium:4444/wd/hub --host=selenium__standalone-chrome
12
- - yarn install
13
- - yarn test
14
- - parallel:
15
- - step:
16
- name: "Selenium Tests"
17
- caches:
18
- - node
19
- services:
20
- - hub
21
- - chrome
22
- script:
23
- - ./vendor/bin/phpunit --testsuite=selenium --cache-result-file=app/cache/.phpunit.result.cache
24
- definitions:
25
- caches:
26
- - node
27
- services:
28
- hub:
29
- image: selenium/hub
30
- environment:
31
- BROWSER: chrome
32
- chrome:
33
- image: selenium/node-chrome:3.141.5
34
- environment:
35
- HUB_PORT_4444_TCP_ADDR: 127.0.0.1
36
- HUB_PORT_4444_TCP_PORT: "4444"