webship-js 1.0.10 → 1.0.12

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.
Files changed (36) hide show
  1. package/.circleci/config.yml +15 -8
  2. package/.github/workflows/github-actions.yml +13 -10
  3. package/.gitlab-ci.yml +1 -0
  4. package/.travis-ci.yml +0 -0
  5. package/README.md +1 -1
  6. package/assets/config_templates/circleci-linux-chrome.conf.js +100 -0
  7. package/assets/config_templates/github-linux-chrome.conf.js +111 -0
  8. package/{bitbucket-pipelines.yml → bitbucket-pipelines-test.yml} +0 -0
  9. package/examples/about-us.html +10 -0
  10. package/examples/contact-us.html +10 -0
  11. package/examples/index.html +26 -0
  12. package/examples/main.js +17 -0
  13. package/examples/test--when--i-fill-in.html +48 -0
  14. package/examples/test--when--i-follow-link.html +18 -0
  15. package/examples/test--when--i-press-button.html +27 -0
  16. package/examples/test--when--i-reload-page.html +27 -0
  17. package/examples/test--when--i-select-option-from-selectbox.html +35 -0
  18. package/lib/custom-commands/smartSelectOption.js +15 -0
  19. package/lib/get-element.js +65 -0
  20. package/nightwatch.conf.js +24 -259
  21. package/package.json +11 -4
  22. package/src/index.js +10 -0
  23. package/steplist.js +101 -64
  24. package/tests/features/test--given--i-am-on-homepage.feature +12 -0
  25. package/tests/features/test--when--i-fill-in.feature +36 -0
  26. package/tests/features/test--when--i-follow-link.feature +11 -0
  27. package/tests/features/test--when--i-move-forward-backward-one-page.feature +14 -0
  28. package/tests/features/test--when--i-press-button.feature +11 -0
  29. package/tests/features/test--when--i-reload-page.feature +14 -0
  30. package/tests/features/test--when--i-select-option-from-selectbox.feature +13 -0
  31. package/tests/reports/cucumber-report.html +0 -0
  32. package/tests/reports/cucumber-report.json +0 -0
  33. package/tests/step-definitions/webship.js +156 -10
  34. package/webpack.config.js +17 -0
  35. package/webship-init.js +75 -0
  36. package/tests/features/check-webshipco-site.feature +0 -8
@@ -40,6 +40,7 @@ commands:
40
40
  - run:
41
41
  name: Install/Update Google Chrome browser
42
42
  command: |
43
+ sudo apt install libu2f-udev
43
44
  sudo apt-get install libappindicator1 fonts-liberation libgbm1 libgtk-3-0 xdg-utils
44
45
  export CHROME_BIN=/usr/bin/google-chrome
45
46
  wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
@@ -57,11 +58,6 @@ commands:
57
58
  sudo mv -f chromedriver /usr/bin/
58
59
  rm chromedriver_linux64.zip
59
60
 
60
- ## Setup Apache2
61
- - run:
62
- name: Setup Apache2
63
- command: |
64
- sudo apt install -yqq apache2
65
61
  ## Run Selenium Standalone server.
66
62
  - run:
67
63
  name: Run Selenium Standalone server
@@ -70,7 +66,7 @@ commands:
70
66
  cd /home/circleci/
71
67
  java -jar selenium-server-standalone-3.141.59.jar -port 4444
72
68
  background: true
73
-
69
+
74
70
  jobs:
75
71
  webship-js-testing:
76
72
  <<: *defaults
@@ -78,10 +74,21 @@ jobs:
78
74
  - webship-js-build
79
75
  ## Automated Functional Acceptance Testing
80
76
  - run:
81
- name: Automated Functional Acceptance Testing
82
- no_output_timeout: 30m
77
+ name: Install yarn
83
78
  command: |
84
79
  yarn install
80
+ - run:
81
+ name: Configure nightwatch.conf.js for Circle CI
82
+ command: |
83
+ node webship-init -ci circleci -os linux -b chrome
84
+ - run:
85
+ name: Start virtual server
86
+ command: |
87
+ yarn start
88
+ background: true
89
+ - run:
90
+ name: Test
91
+ command: |
85
92
  yarn test
86
93
  workflows:
87
94
  version: 2
@@ -8,21 +8,24 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
 
10
10
  env:
11
- TEST_BASE_URL: https://webship.co
11
+ TEST_BASE_URL: http://localhost:8080/
12
12
  SELENIUM_HOST: http://selenium:4444/wd/hub
13
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
14
  steps:
15
+ - name: Install Chrome
16
+ run: |
17
+ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
18
+ sudo dpkg -i google-chrome-stable_current_amd64.deb
22
19
  - uses: actions/checkout@v3
23
20
  - name: Use Node.js
24
21
  uses: actions/setup-node@v3
25
22
  with:
26
23
  node-version: '16.x'
27
- - run: yarn install
28
- - run: yarn test
24
+ - name: Install
25
+ run: yarn install
26
+ - name: Configure nightwatch.conf.js for Github
27
+ run: node webship-init -ci github -os linux -b chrome
28
+ - name: Start
29
+ run: yarn start &
30
+ - name: Test
31
+ run: yarn test
package/.gitlab-ci.yml CHANGED
@@ -36,6 +36,7 @@ check:
36
36
  - npm i @cucumber/pretty-formatter
37
37
 
38
38
  # Run your tests
39
+ - npm start
39
40
  - npm test
40
41
 
41
42
  # Show the logs for the GitLab Selenium Server service
package/.travis-ci.yml CHANGED
File without changes
package/README.md CHANGED
@@ -12,7 +12,7 @@ Webship JS has a ready step definitions for automated functional testing.
12
12
 
13
13
 
14
14
  ### Webship-js Documentations
15
- All you need to know about [webship-js Docs](https://webship.gitbook.io/webship-js-docs/).
15
+ All you need to know about [webship-js Docs](https://github.com/webship/webship-js/wiki/).
16
16
 
17
17
 
18
18
  ## How to configure your project to test using webship-js steps
@@ -0,0 +1,100 @@
1
+ const Services = {}; loadServices();
2
+
3
+ module.exports = {
4
+ // An array of folders (excluding subfolders) where your tests are located;
5
+ // if this is not specified, the test source must be passed as the second argument to the test runner.
6
+ src_folders: ['tests/step-definitions'],
7
+
8
+ // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
9
+ custom_commands_path: './lib/custom-commands',
10
+
11
+ test_runner: {
12
+ type: 'cucumber',
13
+ options: {
14
+ feature_path: 'tests/features/*.feature',
15
+ additional_config: '',
16
+ parallel: 2,
17
+ },
18
+ },
19
+
20
+ test_settings: {
21
+ default: {
22
+ launch_url: 'http://localhost:8080/',
23
+ selenium_port: 4444,
24
+ selenium_host: '127.0.0.1',
25
+ silent: true,
26
+ screenshots: {
27
+ enabled: true,
28
+ path: './reports/screenshots',
29
+ },
30
+
31
+ desiredCapabilities: {
32
+ browserName: 'chrome',
33
+ 'goog:chromeOptions': {
34
+ // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
35
+ //
36
+ // w3c:false tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78)
37
+ w3c: false,
38
+ args: [
39
+ '--headless',
40
+ '--start-maximized',
41
+ '--disable-gpu',
42
+ '--window-size=1600,1200',
43
+ '--no-sandbox',
44
+ '--disable-dev-shm-usage',
45
+ '--disable-setuid-sandbox',
46
+ '--disable-web-security',
47
+ '--DNS-prefetch-disable',
48
+ '--disable-translate',
49
+ '--ignore-certificate-errors',
50
+ '--test-type',
51
+ '--disable-extensions',
52
+ '--incognito',
53
+ '--disable-infobars',
54
+ '--remote-debugging-port=9222',
55
+ '--allowed-ips=*',
56
+ '--whitelisted-ips=*',
57
+ '--allow-insecure-localhost',
58
+ ],
59
+ },
60
+ },
61
+ },
62
+ },
63
+
64
+ selenium_server: {
65
+ // Selenium Server is running locally and is managed by Nightwatch
66
+ selenium: {
67
+ start_process: true,
68
+ port: 4444,
69
+ server_path: (Services.seleniumServer ? Services.seleniumServer.path : ''),
70
+ cli_args: {
71
+ 'webdriver.gecko.driver': (Services.geckodriver ? Services.geckodriver.path : ''),
72
+ 'webdriver.chrome.driver': (Services.chromedriver ? Services.chromedriver.path : ''),
73
+ },
74
+ },
75
+ },
76
+
77
+ 'selenium.chrome': {
78
+ extends: 'selenium_server',
79
+ desiredCapabilities: {
80
+ browserName: 'chrome',
81
+ chromeOptions: {
82
+ w3c: true,
83
+ },
84
+ },
85
+ }
86
+ };
87
+
88
+ function loadServices() {
89
+ try {
90
+ Services.seleniumServer = require('selenium-server');
91
+ } catch (err) {}
92
+
93
+ try {
94
+ Services.chromedriver = require('chromedriver');
95
+ } catch (err) {}
96
+
97
+ try {
98
+ Services.geckodriver = require('geckodriver');
99
+ } catch (err) {}
100
+ }
@@ -0,0 +1,111 @@
1
+ const Services = {}; loadServices();
2
+
3
+ module.exports = {
4
+ // An array of folders (excluding subfolders) where your tests are located;
5
+ // if this is not specified, the test source must be passed as the second argument to the test runner.
6
+ src_folders: ['tests/step-definitions'],
7
+
8
+ // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
9
+ custom_commands_path: './lib/custom-commands',
10
+
11
+ webdriver: {
12
+ start_process: true,
13
+ port: 4444,
14
+ server_path: require('chromedriver').path,
15
+ cli_args: [
16
+ // very verbose geckodriver logs
17
+ // '-vv'
18
+ ]
19
+ },
20
+
21
+ test_runner: {
22
+ type: 'cucumber',
23
+ options: {
24
+ feature_path: 'tests/features/*.feature',
25
+ additional_config: '',
26
+ parallel: 2,
27
+ },
28
+
29
+ },
30
+
31
+ test_settings: {
32
+ default: {
33
+ launch_url: 'http://localhost:8080/',
34
+ selenium_port: 4444,
35
+ selenium_host: '127.0.0.1',
36
+ silent: true,
37
+ screenshots: {
38
+ enabled: true,
39
+ path: './reports/screenshots',
40
+ },
41
+
42
+ desiredCapabilities: {
43
+ browserName: 'chrome',
44
+ 'goog:chromeOptions': {
45
+ // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/
46
+ //
47
+ // w3c:false tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78)
48
+ w3c: false,
49
+ args: [
50
+ '--headless',
51
+ '--start-maximized',
52
+ '--disable-gpu',
53
+ '--window-size=1600,1200',
54
+ '--no-sandbox',
55
+ '--disable-dev-shm-usage',
56
+ '--disable-setuid-sandbox',
57
+ '--disable-web-security',
58
+ '--DNS-prefetch-disable',
59
+ '--disable-translate',
60
+ '--ignore-certificate-errors',
61
+ '--test-type',
62
+ '--disable-extensions',
63
+ '--incognito',
64
+ '--disable-infobars',
65
+ '--remote-debugging-port=9222',
66
+ '--allowed-ips=*',
67
+ '--whitelisted-ips=*',
68
+ '--allow-insecure-localhost',
69
+ ],
70
+ },
71
+ },
72
+ },
73
+ },
74
+
75
+ selenium_server: {
76
+ // Selenium Server is running locally and is managed by Nightwatch
77
+ selenium: {
78
+ start_process: true,
79
+ port: 4444,
80
+ server_path: (Services.seleniumServer ? Services.seleniumServer.path : ''),
81
+ cli_args: {
82
+ 'webdriver.gecko.driver': (Services.geckodriver ? Services.geckodriver.path : ''),
83
+ 'webdriver.chrome.driver': (Services.chromedriver ? Services.chromedriver.path : ''),
84
+ },
85
+ },
86
+ },
87
+
88
+ 'selenium.chrome': {
89
+ extends: 'selenium_server',
90
+ desiredCapabilities: {
91
+ browserName: 'chrome',
92
+ chromeOptions: {
93
+ w3c: true,
94
+ },
95
+ },
96
+ }
97
+ };
98
+
99
+ function loadServices() {
100
+ try {
101
+ Services.seleniumServer = require('selenium-server');
102
+ } catch (err) {}
103
+
104
+ try {
105
+ Services.chromedriver = require('chromedriver');
106
+ } catch (err) {}
107
+
108
+ try {
109
+ Services.geckodriver = require('geckodriver');
110
+ } catch (err) {}
111
+ }
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>About Us</title>
6
+ </head>
7
+ <body>
8
+ <h1>About Us</h1>
9
+ </body>
10
+ </html>
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Contact Us</title>
6
+ </head>
7
+ <body>
8
+ <h1>Contact Us</h1>
9
+ </body>
10
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Webship-js Examples</title>
6
+ <style>
7
+ a:link{font-size: 30px; text-decoration: none;}
8
+ a:active {color: blue;}
9
+ a:visited {color: blue;}
10
+ </style>
11
+ </head>
12
+ <body>
13
+ <h1>Step Definitions Examples:</h1>
14
+ <h3>Welcome to the homepage of the Webship-js Examples</h3>
15
+ <ul>
16
+ <li><a href="/">Given I go to homepage</a></li>
17
+ <li><a href="about-us.html">When I move forward/backward one page</a></li>
18
+ <li><a href="test--when--i-press-button.html">When I press "Button"</a></li>
19
+ <li><a href="test--when--i-reload-page.html">When I go reload page</a></li>
20
+ <li><a href="test--when--i-follow-link.html">When I go follow "link"</a></li>
21
+ <li><a href="test--when--i-fill-in.html">When I fill in input text with value</a></li>
22
+ <li><a href="test--when--i-select-option-from-select.box.html">When I select option from select box</a></li>
23
+ </ul>
24
+ <script src="main.js"></script>
25
+ </body>
26
+ </html>
@@ -0,0 +1,17 @@
1
+ /*
2
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
3
+ * This devtool is not neither made for production nor for readable output files.
4
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
5
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
6
+ * or disable the default devtool with "devtool: false".
7
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
8
+ */
9
+ /******/ (() => { // webpackBootstrap
10
+ /*!**********************!*\
11
+ !*** ./src/index.js ***!
12
+ \**********************/
13
+ /*! unknown exports (runtime-defined) */
14
+ /*! runtime requirements: */
15
+ eval("function component() {\n const element = document.createElement('div');\n\n //Lodash, now imported by this script\n element.innerHTML = _.join(['Hello', 'webpack'], ' ');\n\n return element;\n}\n\ndocument.body.appendChild(component());\n\n//# sourceURL=webpack://webship-js/./src/index.js?");
16
+ /******/ })()
17
+ ;
@@ -0,0 +1,48 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Press Button</title>
6
+ <style>
7
+ .container,
8
+ .container input,
9
+ .container button{
10
+ font-size: 26px;
11
+ }
12
+ .style{
13
+ width: 400px;
14
+ height: 50px;
15
+ font-size: 18px;
16
+ line-height: 50px;
17
+ text-align: center;
18
+ }
19
+ </style>
20
+
21
+ <script>
22
+ function onClick(){
23
+ const username = document.getElementById("uname");
24
+ const password = document.getElementById("pword");
25
+ const element = document.getElementById("result");
26
+ element.innerText = "You enter Username: " + username.value + " and Password: " + password.value;
27
+ }
28
+ </script>
29
+
30
+ </head>
31
+ <body>
32
+ <h1>Login</h1>
33
+
34
+ <div class="container">
35
+ <p><label for="uname"><b>Username</b></label></p>
36
+ <p><input id="uname" class="unamecss" type="text" placeholder="Enter Username" name="username"></p>
37
+
38
+ <p><label for="pword"><b>Password</b></label></p>
39
+ <p><input id="pword" class="pwordcss" type="password" placeholder="Enter Password" name="password"></p>
40
+
41
+ <p><input id="btnLogin" class="btnLogin" name="btnLogin" type="button" value="Login" onclick="onClick()"></p>
42
+
43
+ </div>
44
+
45
+ <div id="result" class="style"></div><br/>
46
+
47
+ </body>
48
+ </html>
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Follow Link</title>
6
+ <style>
7
+ .style{
8
+ font-size: 26px;
9
+ }
10
+ </style>
11
+ </head>
12
+ <body>
13
+ <h1>Follow Link</h1>
14
+ <div id="result" class="style">
15
+ Please click <a href="about-us.html">About us link</a> for more information.
16
+ </div>
17
+ </body>
18
+ </html>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Press Button</title>
6
+ <style>
7
+ .style{
8
+ width: 400px;
9
+ height: 50px;
10
+ font-size: 26px;
11
+ line-height: 50px;
12
+ text-align: center;
13
+ }
14
+ </style>
15
+ <script>
16
+ function onClick(){
17
+ const element = document.getElementById("result");
18
+ element.innerText = "Button Pressed Successfully";
19
+ }
20
+ </script>
21
+ </head>
22
+ <body>
23
+ <h1>Press Button</h1>
24
+ <div id="result" class="style"></div><br/>
25
+ <input id="btnClick" class="btnClick" name="btnClick" type="button" value="Click Button" onclick="onClick()">
26
+ </body>
27
+ </html>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Press Button</title>
6
+ <style>
7
+ .style{
8
+ width: 400px;
9
+ height: 50px;
10
+ font-size: 26px;
11
+ line-height: 50px;
12
+ text-align: center;
13
+ }
14
+ </style>
15
+ <script>
16
+ function onClick(){
17
+ const element = document.getElementById("result");
18
+ element.innerText = "Button Pressed Successfully";
19
+ }
20
+ </script>
21
+ </head>
22
+ <body>
23
+ <h1>Press Button</h1>
24
+ <div id="result" class="style"></div><br/>
25
+ <input id="btnClick" class="btnClick" name="btnClick" type="button" value="Click Button" onclick="onClick()">
26
+ </body>
27
+ </html>
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <title>Select Option</title>
6
+ <style>
7
+ .style{
8
+ height: 50px;
9
+ font-size: 26px;
10
+ line-height: 50px;
11
+ }
12
+ </style>
13
+ <script>
14
+ function onClick(){
15
+ const cars = document.getElementById("cars");
16
+ const selectedOption = cars.options[cars.selectedIndex].text;
17
+ const element = document.getElementById("result");
18
+ element.innerText = "Option ( " + selectedOption + " ) has been selected successfully";
19
+ }
20
+ </script>
21
+ </head>
22
+ <body>
23
+ <h1>Select Option</h1>
24
+ <label for="cars">Choose a car:</label>
25
+
26
+ <select name="cars" id="cars">
27
+ <option value="volvo">Volvo</option>
28
+ <option value="saab">Saab</option>
29
+ <option value="mercedes">Mercedes</option>
30
+ <option value="audi">Audi</option>
31
+ </select>
32
+ <input id="btnClick" class="btnClick" name="btnClick" type="button" value="Check select" onclick="onClick()">
33
+ <div id="result" class="style"></div><br/>
34
+ </body>
35
+ </html>
@@ -0,0 +1,15 @@
1
+
2
+ module.exports.command = function (option, selectBox) {
3
+
4
+ browser.element('css selector', selectBox, function (result) {
5
+ if (result.status === 0) {
6
+ return browser.click(selectBox + ' option[value=' + option + ']');
7
+ } else {
8
+ browser.element('css selector', '#' + selectBox, function (result) {
9
+ if (result.status === 0) {
10
+ return browser.click('#' + selectBox + ' option[value=' + option + ']');
11
+ }
12
+ });
13
+ }
14
+ });
15
+ }
@@ -0,0 +1,65 @@
1
+ module.exports = {
2
+ /**
3
+ * Fill the Input Box With the Value
4
+ *
5
+ * Function to find input by
6
+ * id|class|name|placeholder|label
7
+ * and fill it with sent value
8
+ */
9
+ fillInputWithValue: function (field, value) {
10
+ let element = null;
11
+ let selector = field;
12
+
13
+ browser.element('css selector', selector, function(result){
14
+ if(result.status == 0){
15
+ return browser.setValue(selector, value);
16
+ }
17
+ else{
18
+ selector = '#' + field;
19
+ browser.element('css selector', selector, function(result){
20
+ if(result.status == 0){
21
+ return browser.setValue(selector, value);
22
+ }
23
+ else{
24
+ selector = '.' + field;
25
+ browser.element('css selector', selector, function(result){
26
+ if(result.status == 0){
27
+ return browser.setValue(selector, value);
28
+ }
29
+ else{
30
+ selector = 'input[name=' + field + ']';
31
+ browser.element('css selector', selector, function(result){
32
+ if(result.status == 0){
33
+ return browser.setValue(selector, value);
34
+ }
35
+ else{
36
+ selector = "input[placeholder='" + field + "']";
37
+ browser.element('css selector', selector, function(result){
38
+ if(result.status == 0){
39
+ return browser.setValue(selector, value);
40
+ }
41
+ else{
42
+ browser.elements('css selector', 'label', function (elements) {
43
+ for (let i = 0; i < elements.value.length; i++) {
44
+ this.elementIdText(elements.value[i].ELEMENT, function (result) {
45
+ if (result.value === field) {
46
+ element = elements.value[i].ELEMENT;
47
+ browser.elementIdAttribute(element, 'for', function(eleAttribute){
48
+ return browser.setValue('#' + eleAttribute.value, value);
49
+ });
50
+ }
51
+ });
52
+ }
53
+ });
54
+ }
55
+ });
56
+ }
57
+ });
58
+ }
59
+ });
60
+ }
61
+ });
62
+ }
63
+ });
64
+ }
65
+ };