webship-js 1.0.7 → 1.0.9

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.
@@ -1,8 +1,59 @@
1
1
  #!/usr/bin/env node
2
+ 'use strict';
2
3
 
3
4
  const fs = require('fs');
4
5
  const conf = require('../nightwatch.conf.js');
5
6
 
7
+ /**
8
+ * -----------------------------------------------------
9
+ * Parse arguments
10
+ * -----------------------------------------------------
11
+ */
12
+ const { ArgumentParser } = require('argparse');
13
+ const { version } = require('../package.json');
14
+
15
+ const parser = new ArgumentParser({
16
+ description: 'Argparse example'
17
+ });
18
+
19
+ parser.add_argument('-v', '--version', { action: 'version', version });
20
+ parser.add_argument('-l', '--list',
21
+ {
22
+ help: 'Display step definitions list without information.',
23
+ action: 'store_true',
24
+ default: true,
25
+ });
26
+
27
+ parser.add_argument('-i', '--information',
28
+ {
29
+ help: 'Display step definitions list with information.',
30
+ action: 'store_true',
31
+ });
32
+
33
+ parser.add_argument('-c', '--config',
34
+ {
35
+ help: 'Add your nightwatch config file, Example: -c="config.js" OR -c=config.js OR -c config.js',
36
+ default: '../nightwatch.conf.js',
37
+ });
38
+
39
+ parser.add_argument('-s', '--src_folders',
40
+ {
41
+ help: 'Add your step definitions folder/s path, Example: -s="path/to/folder1" OR -s="path/to/folder1 path/to/folder2", You can add as much as you want of folder paths',
42
+ default: "tests/step-definitions",
43
+ });
44
+
45
+ parser.add_argument('-f', '--format',
46
+ {
47
+ help: 'Choose step definitions list format style, just add a number. (1) stdout-space. (2) stdout-dashes. Example: -f=1 OR -f 2',
48
+ default: "1",
49
+ });
50
+
51
+ var argsParse = parser.parse_args();
52
+
53
+ /**
54
+ * -----------------------------------------------------
55
+ */
56
+
6
57
  /**
7
58
  * Folders Path Array variable
8
59
  *
@@ -35,12 +86,19 @@ function setOutputFormat(value) { outputFormat = value; }
35
86
  * @return {array} The array has only lines startsWith words chosen.
36
87
  */
37
88
  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('*/'));
89
+ if(argsParse.information == true){
90
+ return (stepsList.startsWith('Given') ||
91
+ stepsList.startsWith('Then') ||
92
+ stepsList.startsWith('When') ||
93
+ stepsList.startsWith('/**') ||
94
+ stepsList.startsWith('* ') ||
95
+ stepsList.startsWith('*/'));
96
+ }
97
+ else if(argsParse.list == true){
98
+ return (stepsList.startsWith('Given') ||
99
+ stepsList.startsWith('Then') ||
100
+ stepsList.startsWith('When'));
101
+ }
44
102
  }
45
103
 
46
104
  /**
@@ -89,9 +147,7 @@ function stepsCleanList(stepsList) {
89
147
  }
90
148
 
91
149
  function srcFolderPaths(path) {
92
- const splitConfig = path.split('=');
93
- const pathsLine = splitConfig[1];
94
- const paths = pathsLine.split(' ');
150
+ const paths = path.split(' ');
95
151
 
96
152
  setFoldersPath(paths);
97
153
  }
@@ -103,24 +159,18 @@ function srcFolderPaths(path) {
103
159
  * all folders contain step definitions js files.
104
160
  */
105
161
 
106
- for (let i = 2; i < process.argv.length; i++) {
107
- if (process.argv[i].startsWith('--config')) {
108
- const splitConfig = process.argv[i].split('=');
109
- const path = splitConfig[1];
110
- const configPath = require(path);
162
+ const configPath = require(argsParse.config);
163
+
164
+ let configPathsArray = [];
165
+ configPathsArray = configPath.src_folders;
111
166
 
112
- let configPathsArray = [];
113
- configPathsArray = configPath.src_folders;
167
+ setFoldersPath(configPathsArray);
114
168
 
115
- setFoldersPath(configPathsArray);
116
- } else if (process.argv[i].startsWith('--src_folders')) {
117
- srcFolderPaths(process.argv[i]);
118
- } else if (process.argv[i].startsWith('--format')) {
119
- setOutputFormat(process.argv[i].split('=')[1]);
169
+ if (foldersPath.length === 0){
170
+ srcFolderPaths(argsParse.src_folders);
120
171
  }
121
- }
122
172
 
123
- if (foldersPath.length === 0) foldersPath = conf.src_folders;
173
+ setOutputFormat(argsParse.format);
124
174
 
125
175
  /**
126
176
  * Step definitions list
@@ -128,7 +178,6 @@ if (foldersPath.length === 0) foldersPath = conf.src_folders;
128
178
  * Get clear step definitions list from js
129
179
  * step definitions files.
130
180
  */
131
-
132
181
  foldersPath.forEach((folderPath) => {
133
182
  fs.readdir(folderPath, (err, files) => {
134
183
  if (err) {
@@ -147,11 +196,11 @@ foldersPath.forEach((folderPath) => {
147
196
  const stepsList = stepsCleanList(stepsStartWith);
148
197
 
149
198
  stepsList.forEach((element) => {
150
- if (outputFormat.startsWith('stdout')) {
151
- console.log(element);
152
- } else if (outputFormat.startsWith('html')) {
153
- console.log(`<div>${element}</div>`);
154
- } else { console.log(element); }
199
+ if (argsParse.format == 1) {
200
+ console.log(element + '\n');
201
+ } else if (argsParse.format == 2) {
202
+ console.log(element + '\n');
203
+ }
155
204
  });
156
205
  });
157
206
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -18,25 +18,29 @@
18
18
  "type": "git",
19
19
  "url": "git+https://github.com/webship/webship-js.git"
20
20
  },
21
- "author": "Webship.org",
21
+ "author": "Webship.co",
22
22
  "license": "MIT",
23
23
  "bugs": {
24
24
  "url": "https://github.com/webship/webship-js/issues"
25
25
  },
26
26
  "homepage": "https://github.com/webship/webship-js",
27
27
  "dependencies": {
28
+ "nightwatch": "~2.0",
28
29
  "@cucumber/cucumber": "*",
29
30
  "@cucumber/pretty-formatter": "^1.0.0-alpha.2",
30
- "chromedriver": "*",
31
- "geckodriver": "*",
31
+ "args-parser": "~1.0",
32
32
  "eslint": "~8.0",
33
- "eslint-config-airbnb-base": "^15.0.0",
34
- "eslint-plugin-import": "^2.25.4",
35
- "mocha": "^9.1.3",
36
- "nightwatch": "^2.1.7"
33
+ "eslint-config-airbnb-base": "~15.0",
34
+ "eslint-plugin-import": "~2.25"
35
+ },
36
+ "devDependencies": {
37
+ "chromedriver": "*",
38
+ "geckodriver": "*"
37
39
  },
38
- "bin":{
39
- "webship-js-dl" : "./bin/webship-js-dl.js",
40
- "webship-js-di" : "./bin/webship-js-di.js"
41
- }
40
+ "files": [
41
+ "bin/"
42
+ ],
43
+ "bin": {
44
+ "steplist": "./bin/steplist.js"
45
+ }
42
46
  }
@@ -1,102 +0,0 @@
1
- version: 2.1
2
- defaults: &defaults
3
- docker:
4
- - image: cimg/base:stable-20.04
5
- auth:
6
- username: mydockerhub-user
7
- password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
8
- commands:
9
- webship-js-build:
10
- steps:
11
- - checkout
12
- ## Usefull must have utils.
13
- - run:
14
- name: Usefull must have utils
15
- command: |
16
- sudo apt -qq update
17
- sudo apt -qqy upgrade
18
- sudo apt -yqq install vim links lynx git diffutils htop curl wget p7zip-full unzip zip sed gcc g++ make libfreetype6-dev libaio1 libaio-dev libonig-dev libpng-dev
19
- sudo apt -yqq install xvfb libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 libnss3
20
-
21
- ## Configure and run the virtual display.
22
- - run:
23
- name: Configure and run the virtual display.
24
- command: Xvfb -ac :99 -screen 0 1600x1200x24 > /dev/null 2>&1
25
- background: true
26
-
27
- ## Install node js, npm, yarn, and gulp
28
- - run:
29
- name: Install node js
30
- command: |
31
- curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
32
- sudo apt install -y nodejs
33
- sudo npm install -g yarn
34
-
35
- ## Install Java.
36
- - run:
37
- name: Install Java
38
- command: |
39
- sudo apt update
40
- sudo apt install -y openjdk-11-jre openjdk-11-jre-headless openjdk-11-jdk openjdk-11-jdk-headless
41
-
42
- ## Install/Update Google Chrome browser.
43
- - run:
44
- name: Install/Update Google Chrome browser
45
- command: |
46
- sudo apt-get install libappindicator1 fonts-liberation libgbm1 libgtk-3-0 xdg-utils
47
- export CHROME_BIN=/usr/bin/google-chrome
48
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
49
- sudo dpkg -i google-chrome-stable_current_amd64.deb
50
- rm google-chrome-stable_current_amd64.deb
51
-
52
- ## Install/Update Chrome Driver.
53
- - run:
54
- name: Install/Update Chrome Driver
55
- command: |
56
- CHROME_DRIVER_VERSION=$(wget -qO- chromedriver.storage.googleapis.com/LATEST_RELEASE);
57
- echo $CHROME_DRIVER_VERSION;
58
- wget http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
59
- unzip chromedriver_linux64.zip
60
- sudo chmod +x chromedriver
61
- sudo mv -f chromedriver /usr/bin/
62
- rm chromedriver_linux64.zip
63
-
64
- ## Setup Apache2
65
- - run:
66
- name: Setup Apache2
67
- command: |
68
- sudo apt install -yqq apache2
69
-
70
- ## Run Selenium Standalone server.
71
- - run:
72
- name: Run Selenium Standalone server
73
- command: |
74
- if [[ ! -f /home/circleci/selenium-server-standalone-3.141.59.jar ]]; then wget -O /home/circleci/selenium-server-standalone-3.141.59.jar https://github.com/SeleniumHQ/selenium/releases/download/selenium-3.141.59/selenium-server-standalone-3.141.59.jar; fi
75
- cd /home/circleci/
76
- java -jar selenium-server-standalone-3.141.59.jar -port 4444
77
- background: true
78
-
79
- jobs:
80
- webship-js-testing:
81
- <<: *defaults
82
- steps:
83
- - webship-js-build
84
- ## Automated Functional Acceptance Testing
85
- - run:
86
- name: Automated Functional Acceptance Testing
87
- no_output_timeout: 30m
88
- command: |
89
- yarn install
90
- yarn test
91
-
92
- workflows:
93
- version: 2
94
- webship-js-workflow:
95
- jobs:
96
- - webship-js-testing:
97
- filters:
98
- tags:
99
- only: /^1.0.*/
100
- branches:
101
- only: /^1.0.x/
102
-
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- node_modules
2
- nightwatch.conf.js
3
- tests_output
package/.eslintrc.json DELETED
@@ -1,34 +0,0 @@
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
- }
@@ -1,28 +0,0 @@
1
- name: Github Actions
2
-
3
- on: [push]
4
-
5
- jobs:
6
- build:
7
-
8
- runs-on: ubuntu-latest
9
-
10
- env:
11
- TEST_BASE_URL: https://webship.co
12
- SELENIUM_HOST: http://selenium:4444/wd/hub
13
-
14
- services:
15
- selenium:
16
- image: selenium/standalone-chrome
17
- # options: --health-cmd "curl http://selenium:4444" --health-interval=5s
18
- ports:
19
- - 4444:4444
20
-
21
- steps:
22
- - uses: actions/checkout@v3
23
- - name: Use Node.js
24
- uses: actions/setup-node@v3
25
- with:
26
- node-version: '16.x'
27
- - run: yarn install
28
- - run: yarn test
package/.gitlab-ci.yml DELETED
@@ -1,51 +0,0 @@
1
- image: node:16
2
-
3
- stages:
4
- - check
5
-
6
- check:
7
- stage: check
8
- script:
9
- # Dependencies for chromedriver, https://gist.github.com/mikesmullin/2636776#gistcomment-1742414
10
- # Otherwise we get this error: "error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory"
11
- - apt-get update -q -y
12
- - apt-get --yes install libnss3
13
- - apt-get --yes install libgconf-2-4
14
-
15
- # Install chrome
16
- # Based off of
17
- # - https://gitlab.com/gitlab-org/gitlab-build-images/blob/9dadb28021f15913a49897126a0cd6ab0149e44f/scripts/install-chrome
18
- # - https://askubuntu.com/a/510186/196148
19
- #
20
- # Add key
21
- - curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
22
- # Add repo
23
- - echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
24
- - apt-get update -q -y
25
- - apt-get install -y google-chrome-stable
26
-
27
- - npm install chromedriver -g
28
- - npm install nightwatch -g
29
- - npm install https://gitlab.com/gitlab-org/gitlab-selenium-server.git -g
30
- - which chromedriver
31
- # The `&` at the end causes it to run in the background and not block the following commands
32
- - nohup chromedriver --port=4444 --url-base=wd/hub &
33
- - nohup gitlab-selenium-server &
34
- # Install cucumber & pretty formatter .
35
- - npm i @cucumber/cucumber
36
- - npm i @cucumber/pretty-formatter
37
-
38
- # Run your tests
39
- - npm test
40
-
41
- # Show the logs for the GitLab Selenium Server service
42
- - mkdir -p selenium/ && curl -s http://localhost:4545/logs.tar.gz | tar -xvzf - -C selenium/
43
- - mkdir -p selenium/ && curl http://localhost:4545/server-log --output selenium/server-log.txt
44
- artifacts:
45
- when: always
46
- paths:
47
- - selenium/
48
- variables:
49
- SELENIUM_REMOTE_URL: http://localhost:4545/wd/hub
50
- GITLAB_TARGET_SELENIUM_REMOTE_URL: http://localhost:4444/wd/hub
51
-
package/.travis-ci.yml DELETED
@@ -1,27 +0,0 @@
1
- dist: trusty
2
- language: java
3
-
4
- jdk:
5
- - openjdk-11-jre
6
-
7
- before_script:
8
- - docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-firefox:4.0.0-rc-1-prerelease-20210618
9
- - docker ps
10
-
11
- script:
12
- - mvn clean install -DsuiteXmlFile=testng.xml -Dbrowser=GRID_FIREFOX -DgridHubURL=http://localhost:4444/wd/hub
13
-
14
- cache:
15
- directories:
16
- - .autoconf
17
- - $HOME/.m2
18
-
19
- deploy:
20
- provider: releases
21
- api_key: ${api_key}
22
- skip_cleanup: true
23
- file: [ "target/surefire-reports/emailable-report.html",
24
- "target/surefire-reports/index.html" ]
25
- on:
26
- all_branches: true
27
- tags: false
@@ -1,142 +0,0 @@
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
- /**
83
- * "foldersPath" array
84
- *
85
- * Fill "foldersPath" array process, that has paths of
86
- * all folders contain step definitions js files.
87
- */
88
-
89
- for (let i = 2; i < process.argv.length; i++) {
90
- if (process.argv[i].startsWith('--config')) {
91
- const splitConfig = process.argv[i].split('=');
92
- const path = splitConfig[1];
93
- const configPath = require(path);
94
-
95
- let configPathsArray = [];
96
- configPathsArray = configPath.src_folders;
97
-
98
- setFoldersPath(configPathsArray);
99
- } else if (process.argv[i].startsWith('--src_folders')) {
100
- srcFolderPaths(process.argv[i]);
101
- } else if (process.argv[i].startsWith('--format')) {
102
- setOutputFormat(process.argv[i].split('=')[1]);
103
- }
104
- }
105
-
106
- if (foldersPath.length === 0) foldersPath = conf.src_folders;
107
-
108
- /**
109
- * Step definitions list
110
- *
111
- * Get clear step definitions list from js
112
- * step definitions files.
113
- */
114
-
115
- foldersPath.forEach((folderPath) => {
116
- fs.readdir(folderPath, (err, files) => {
117
- if (err) {
118
- return console.log(`Unable to scan directory: ${err}`);
119
- }
120
-
121
- files.forEach((file) => {
122
- fs.readFile(`./${folderPath}/${file}`, 'utf8', (err, data) => {
123
- if (err) {
124
- throw new Error(err);
125
- }
126
- const contentLines = data.split('\n');
127
- const contentTrimmed = contentLines.map((element) => element.trim());
128
-
129
- const stepsStartWith = callStartsWith(contentTrimmed);
130
- const stepsList = stepsCleanList(stepsStartWith);
131
-
132
- stepsList.forEach((element) => {
133
- if (outputFormat.startsWith('stdout')) {
134
- console.log(element);
135
- } else if (outputFormat.startsWith('html')) {
136
- console.log(`<div>${element}</div>`);
137
- } else { console.log(element); }
138
- });
139
- });
140
- });
141
- });
142
- });
@@ -1,37 +0,0 @@
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