webship-js 1.0.16 → 1.0.17

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/README.md CHANGED
@@ -12,78 +12,25 @@ 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://github.com/webship/webship-js/wiki/).
15
+ All you need to know about [webship-js Docs](https://webship.co/documentation/webship-js).
16
16
 
17
17
 
18
18
  ## How to configure your project to test using webship-js steps
19
19
 
20
20
  ### Install node js and yarn
21
21
 
22
- ```
23
- sudo apt install nodejs
24
- sudo npm install yarn
25
- ```
26
-
27
- ### Install Java
28
-
29
- ```
30
- sudo apt install java
31
- ```
32
-
33
- ### Download Latest Chrome Driver
34
-
35
- ```
36
- CHROME_DRIVER_VERSION=$(wget -qO- chromedriver.storage.googleapis.com/LATEST_RELEASE);
37
- echo $CHROME_DRIVER_VERSION;
38
- wget http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
39
- unzip chromedriver_linux64.zip
40
- chmod +x chromedriver
41
- mkdir -p $HOME/.composer/vendor/bin
42
- mv -f chromedriver $HOME/.composer/vendor/bin/
43
- rm chromedriver_linux64.zip
44
- ```
45
-
46
- ### Install/Update Chrome Driver
47
-
48
- ```
49
- export CHROME_BIN=/usr/bin/google-chrome
50
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
51
- sudo apt-get clean
52
- sudo apt-get update
53
- sudo apt-get install dpkg
54
- sudo dpkg -i google-chrome-stable_current_amd64.deb
55
- rm google-chrome-stable_current_amd64.deb
56
- google-chrome --version
57
- ```
22
+ ### Install Latest Chrome Driver
58
23
 
59
24
  ### Run selenium standalone server
60
25
 
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
- ```
66
-
67
- ## How to install using Yarn
26
+ ## Install webship-js using Yarn
68
27
 
69
28
  ```
70
29
  yarn add webship-js
71
- ```
72
-
73
- ## How to install using NPM
74
-
75
- ```
76
- npm install webship-js
77
30
  ```
78
31
 
79
32
  ## Automated Functional Acceptance Testing
80
33
 
81
34
  ```
82
35
  yarn test
83
- ```
84
-
85
- Or
86
-
87
- ```
88
- npm test
89
- ```
36
+ ```
@@ -22,6 +22,7 @@
22
22
  <li><a href="test--when--i-select-option-from-selectbox.html">When I select option from select box</a></li>
23
23
  <li><a href="test--then--i-should--not--see-text-in-element.html">Then I sould (not) see test in element</a></li>
24
24
  <li><a href="test--then--the-element-should_not-contain-cssproperty.html">Then the element should (not) contain css property</a></li>
25
+ <li><a href="test--then--the-checkbox-checked.html">Then the checkbox (is/should be) (not) checked</a></li>
25
26
  </ul>
26
27
  <script src="main.js"></script>
27
28
  </body>
@@ -0,0 +1,68 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset='utf-8'>
6
+ <title>Item should be checked</title>
7
+ <style>
8
+ .container,
9
+ .container input,
10
+ .container button {
11
+ font-size: 22px;
12
+ }
13
+
14
+ .style {
15
+ width: 400px;
16
+ height: 50px;
17
+ font-size: 22px;
18
+ line-height: 50px;
19
+ text-align: center;
20
+ }
21
+ </style>
22
+
23
+ <script>
24
+ function onClick() {
25
+ const element = document.getElementById("result");
26
+ const PrivacyPolicy = document.getElementById("PrivacyPolicy");
27
+ if (PrivacyPolicy.checked) {
28
+ element.innerText = "Registration Done Successfully";
29
+ } else {
30
+ element.innerText = "Please check Agree to Privacy Policy";
31
+ }
32
+
33
+ }
34
+ </script>
35
+
36
+ </head>
37
+
38
+ <body>
39
+ <h1>Registration</h1>
40
+
41
+ <div class="container">
42
+ <p>
43
+ <label for="email">Email</label><br/>
44
+ <input type="text" placeholder="Enter Email" name="email" id="email" required>
45
+ </p>
46
+ <p>
47
+ <label for="psw">Password</label><br/>
48
+ <input type="password" placeholder="Enter Password" name="psw" id="psw" required>
49
+ </p>
50
+ <p>
51
+ <label for="psw-repeat">Repeat Password</label><br/>
52
+ <input type="password" placeholder="Repeat Password" name="psw-repeat" id="psw-repeat" required>
53
+ </p>
54
+ <hr>
55
+
56
+ <p><input type="checkbox" value="lsRememberMe" id="rememberMe"> <label for="rememberMe">Remember me</label></p>
57
+ <p><input type="checkbox" value="lsPrivacyPolicy" id="PrivacyPolicy"> <label for="PrivacyPolicy">I Agree to Privacy Policy</label></p>
58
+
59
+ <p><input id="registerbtn" class="registerbtn" name="registerbtn" type="button" value="Register"
60
+ onclick="onClick()"></p>
61
+
62
+ </div>
63
+
64
+ <div id="result" class="style"></div><br />
65
+
66
+ </body>
67
+
68
+ </html>
@@ -0,0 +1,32 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset='utf-8'>
6
+ <title>Press Button</title>
7
+ <style>
8
+ .style {
9
+ font-size: 26px;
10
+ }
11
+ </style>
12
+ <script>
13
+ function onClick() {
14
+ const myfile = document.getElementById("fileUpload");
15
+ const element = document.getElementById("result");
16
+ const img = document.getElementById("img");
17
+ const filePathArr = myfile.value.split('\\');
18
+ element.innerText = filePathArr[filePathArr.length - 1];
19
+
20
+ }
21
+ </script>
22
+ </head>
23
+
24
+ <body>
25
+ <label for="myfile">Select a file:</label>
26
+ <input type="file" id="fileUpload" name="fileUpload"><br><br>
27
+ <div id="result" class="style"></div><br />
28
+ <input type="submit" value="Submit" onclick="onClick()">
29
+
30
+ </body>
31
+
32
+ </html>
@@ -0,0 +1,21 @@
1
+ var reporter = require('cucumber-html-reporter');
2
+
3
+ var options = {
4
+ theme: 'bootstrap',
5
+ jsonFile: 'tests/reports/cucumber_report.json',
6
+ output: 'tests/reports/cucumber_report.html',
7
+ reportSuiteAsScenarios: true,
8
+ scenarioTimestamp: true,
9
+ launchReport: true,
10
+ metadata: {
11
+ "App Version": "7.1.0",
12
+ "Test Environment": "development",
13
+ "Browser": "Google Chrome",
14
+ "Platform": "Linux",
15
+ "Parallel": "Scenarios",
16
+ "Executed": "Remote"
17
+ },
18
+ failedSummaryReport: true,
19
+ };
20
+
21
+ reporter.generate(options);
@@ -0,0 +1,54 @@
1
+
2
+ module.exports.assertion = function (checkbox, negativeCase) {
3
+
4
+ browser.element('css selector', checkbox, function (result) {
5
+ if (result.status === 0) {
6
+ if (negativeCase) {
7
+ return browser.expect.element(checkbox).to.not.be.selected;
8
+ }
9
+ return browser.expect.element(checkbox).to.be.selected;
10
+ } else {
11
+ browser.element('css selector', '#' + checkbox, function (result) {
12
+ if (result.status === 0) {
13
+ if (negativeCase) {
14
+ return browser.expect.element('#' + checkbox).to.not.be.selected;
15
+ }
16
+ return browser.expect.element('#' + checkbox).to.be.selected;
17
+ } else {
18
+ browser.element('css selector', 'input[name="' + checkbox + '"]', function (result) {
19
+ if (result.status === 0) {
20
+ if (negativeCase) {
21
+ return browser.expect.element('input[name="' + checkbox + '"]').to.not.be.selected;
22
+ }
23
+ return browser.expect.element('input[name="' + checkbox + '"]').to.be.selected;
24
+ } else {
25
+ browser.element('css selector', 'input[value="' + checkbox + '"]', function (result) {
26
+ if (result.status === 0) {
27
+ if (negativeCase) {
28
+ return browser.expect.element('input[value="' + checkbox + '"]').to.not.be.selected;
29
+ }
30
+ return browser.expect.element('input[value="' + checkbox + '"]').to.be.selected;
31
+ } else {
32
+ browser.elements('css selector', 'label', function (elements) {
33
+ elements.value.forEach(function (elementsObj) {
34
+ browser.elementIdText(elementsObj.ELEMENT, function (result) {
35
+ if (result.value == checkbox) {
36
+ browser.getAttribute(elementsObj, "for", function (forVal) {
37
+ if (negativeCase) {
38
+ return browser.expect.element('#' + forVal.value).to.not.be.selected;
39
+ }
40
+ return browser.expect.element('#' + forVal.value).to.be.selected;
41
+ });
42
+ }
43
+ })
44
+ });
45
+ });
46
+ }
47
+ });
48
+ }
49
+ });
50
+ }
51
+ });
52
+ }
53
+ });
54
+ }
@@ -0,0 +1,38 @@
1
+
2
+ module.exports.command = function (fileUrl, element) {
3
+ browser.element('css selector', element, function (result) {
4
+ if (result.status === 0) {
5
+ browser.setValue(element, require('path').resolve(__dirname + fileUrl));
6
+ } else {
7
+ browser.element('css selector', '#' + element, function (result) {
8
+ if (result.status === 0) {
9
+ browser.setValue('#' + element, require('path').resolve(__dirname + fileUrl))
10
+ } else {
11
+ browser.element('css selector', '.' + element, function (result) {
12
+ if (result.status === 0) {
13
+ browser.setValue('.' + element, require('path').resolve(__dirname + fileUrl))
14
+ } else {
15
+ browser.element('css selector', 'input[name="' + element + '"]', function (result) {
16
+ if (result.status === 0) {
17
+ browser.setValue('input[name="' + element + '"]', require('path').resolve(__dirname + fileUrl))
18
+ } else {
19
+ browser.elements('css selector', 'label', function (elements) {
20
+ elements.value.forEach(function (elementsObj) {
21
+ browser.elementIdText(elementsObj.ELEMENT, function (result) {
22
+ if (result.value == element) {
23
+ browser.getAttribute(elementsObj, "for", function (forVal) {
24
+ browser.setValue(forVal.value, require('path').resolve(__dirname + fileUrl))
25
+ });
26
+ }
27
+ })
28
+ });
29
+ });
30
+ }
31
+ });
32
+ }
33
+ });
34
+ }
35
+ });
36
+ }
37
+ });
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -11,7 +11,8 @@
11
11
  "node": ">= 16.0"
12
12
  },
13
13
  "scripts": {
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",
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.json",
15
+ "report":"node generate-reports.js",
15
16
  "lint:js": "node ./node_modules/eslint/bin/eslint.js --config=.eslintrc.json .",
16
17
  "build": "webpack",
17
18
  "start": "npm run devServer",
@@ -32,6 +33,7 @@
32
33
  "@cucumber/cucumber": "*",
33
34
  "@cucumber/pretty-formatter": "^1.0.0-alpha.2",
34
35
  "args-parser": "~1.0",
36
+ "cucumber-html-reporter": "^7.1.0",
35
37
  "eslint": "~8.0",
36
38
  "eslint-config-airbnb-base": "~15.0",
37
39
  "eslint-plugin-import": "~2.25",
@@ -0,0 +1,16 @@
1
+ Feature: Example test the checkbox if checked or not
2
+ As a tester
3
+ I want to be able to test uncheck a checkbox item
4
+
5
+ Scenario: Check the "Then checkbox is/should be checked" step definitions
6
+ Given I am on "test--then--the-checkbox-checked.html"
7
+ When I press "Register"
8
+ Then the "PrivacyPolicy" checkbox should not be checked
9
+ And the "rememberMe" checkbox is not checked
10
+ And I should see "Please check Agree to Privacy Policy"
11
+ When I check "PrivacyPolicy"
12
+ And I press "Register"
13
+ Then the checkbox "PrivacyPolicy" should be checked
14
+ And I should see "Registration Done Successfully"
15
+ When I check "rememberMe"
16
+ Then the checkbox "Remember me" is checked
@@ -0,0 +1,12 @@
1
+ Feature: Example test for: Then the "filed" should contain "value"
2
+ As a tester
3
+ I want to be able to check field if has a particular value or not
4
+
5
+ Scenario: Check field if has a particular value or not
6
+ Given I am on homepage
7
+ When I go to "test--then--i-should--not--see-text-in-element.html"
8
+ And I fill in "Username" with "user1"
9
+ Then the "Username" field should contain "user1"
10
+ When I press "Reset"
11
+ And I fill in "Username" with "user2"
12
+ Then the "Username" field should not contain "user1"
@@ -0,0 +1,10 @@
1
+ Feature: Example test for "When I attach file to field"
2
+
3
+ As a tester
4
+ I want to be able to attach file (images) to feild
5
+
6
+ Scenario: Check the "When I attach file to feild" step definitions
7
+ Given I am on "test--when--i-attach-file-to-feild.html"
8
+ When I attach the file "../../../tests/upload/webshipco.png" to "#fileUpload"
9
+ When I press "Submit"
10
+ Then I should see "webshipco.png"
@@ -4,7 +4,6 @@ const { Then } = require('@cucumber/cucumber');
4
4
 
5
5
  /**
6
6
  * Opens homepage.
7
- *
8
7
  * Example: Given I am on homepage
9
8
  * Example: Given I am on the homepage
10
9
  *
@@ -286,4 +285,74 @@ Then(/^I should( not)* see a(n)* "([^"]*)?" element$/, function (negativeCase, i
286
285
  */
287
286
  Then(/^the "([^"]*)?" element should( not)* contain "([^"]*)?"$/, function (element, negativeCase, elementCss) {
288
287
  return browser.assert.smartElementContainsCss(element, negativeCase, elementCss);
288
+ });
289
+
290
+ /**
291
+ * Attaches file to field with specified id|name|label|value
292
+ * Example: When I attach the file "bwayne_profile.png" to "profileImageUpload"
293
+ * Example: And I attach the file "bwayne_profile.png" to "profileImageUpload"
294
+ *
295
+ * @When /^I attach the file "([^"]*)?" to "([^"]*)?"$/
296
+ */
297
+ When(/^I attach the file "([^"]*)?" to "([^"]*)?"$/, function (fileUrl, element) {
298
+ browser.smartUploadFile(fileUrl, element);
299
+ });
300
+
301
+ /**
302
+ * Checks, that form field with specified id|name|label|value has specified value
303
+ * Example: Then the "username" field should contain "bwayne"
304
+ * Example: And the "username" field should not contain "bwayne"
305
+ *
306
+ * @Then /^the "([^"]*)?" field should( not)* contain "([^"]*)?"$/
307
+ */
308
+ Then(/^the "([^"]*)?" field should( not)* contain "([^"]*)?"$/, function (field, negativeCase, expectedText) {
309
+ return browser.assert.smartElementContains(negativeCase, expectedText, field);
310
+ });
311
+
312
+ /**
313
+ * Checks, that checkbox with specified id|name|label|value is checked
314
+ * Example: Then the "PrivacyPolicy" checkbox should be checked
315
+ * Example: And the "PrivacyPolicy" checkbox should not be checked
316
+ *
317
+ * @Then /^the "([^"]*)?" checkbox should(not)* be checked$/
318
+ *
319
+ */
320
+ Then(/^the "([^"]*)?" checkbox should( not)* be checked$/, function (checkbox, negativeCase) {
321
+ return browser.assert.smartCheckboxChecked(checkbox, negativeCase);
322
+ });
323
+
324
+ /**
325
+ * Checks, that checkbox with specified id|name|label|value is checked
326
+ * Example: Then the "Remember Me" checkbox is checked
327
+ * Example: And the "Remember Me" checkbox is not checked
328
+ *
329
+ * @Then /^the "([^"]*)?" checkbox is( not)* checked$/
330
+ *
331
+ */
332
+ Then(/^the "([^"]*)?" checkbox is( not)* checked$/, function (checkbox, negativeCase) {
333
+ return browser.assert.smartCheckboxChecked(checkbox, negativeCase);
334
+ });
335
+
336
+ /**
337
+ * Checks, that checkbox with specified id|name|label|value is checked
338
+ * Example: Then the checkbox "PrivacyPolicy" should be checked
339
+ * Example: Then the checkbox "PrivacyPolicy" should not be checked
340
+ *
341
+ * @Then /^the checkbox "([^"]*)?" should(not)* be checked$/
342
+ *
343
+ */
344
+ Then(/^the checkbox "([^"]*)?" should( not)* be checked$/, function (checkbox, negativeCase) {
345
+ return browser.assert.smartCheckboxChecked(checkbox, negativeCase);
346
+ });
347
+
348
+ /**
349
+ * Checks, that checkbox with specified id|name|label|value is checked
350
+ * Example: Then the checkbox "Remember Me" is checked
351
+ * Example: And the checkbox "Remember Me" is not checked
352
+ *
353
+ * @Then /^the checkbox "([^"]*)?" is( not)* checked$/
354
+ *
355
+ */
356
+ Then(/^the checkbox "([^"]*)?" is( not)* checked$/, function (checkbox, negativeCase) {
357
+ return browser.assert.smartCheckboxChecked(checkbox, negativeCase);
289
358
  });
Binary file
package/webship-init.js CHANGED
@@ -9,13 +9,13 @@ var projectPath = '';
9
9
  const currentPath = process.argv[1].split("node_modules");
10
10
  basePath = currentPath[0].substring(0, currentPath[0].lastIndexOf("/")) + '/';
11
11
 
12
- if(currentPath.length > 1){
13
- projectPath = basePath + "node_modules/webship-js/";
14
- }
15
- else{
16
- projectPath = basePath;
12
+ if (currentPath.length > 1) {
13
+ projectPath = basePath + "node_modules/webship-js/";
14
+ }
15
+ else {
16
+ projectPath = basePath;
17
17
 
18
- }
18
+ }
19
19
 
20
20
  /**
21
21
  * -----------------------------------------------------
@@ -36,16 +36,16 @@ parser.add_argument('-ci', '--continuous_integration',
36
36
  });
37
37
 
38
38
  parser.add_argument('-b', '--browser',
39
- {
40
- help: 'Add your Browser (chrome, firefox), By default: -b chrome',
41
- default: 'chrome',
42
- });
39
+ {
40
+ help: 'Add your Browser (chrome, firefox), By default: -b chrome',
41
+ default: 'chrome',
42
+ });
43
43
 
44
44
  parser.add_argument('-os', '--operating_system',
45
- {
46
- help: 'Add your Operating System (linux, mac, windows), By default: -os linux',
47
- default: 'linux',
48
- });
45
+ {
46
+ help: 'Add your Operating System (linux, mac, windows), By default: -os linux',
47
+ default: 'linux',
48
+ });
49
49
 
50
50
  var argsParse = parser.parse_args();
51
51