webship-js 1.0.11 → 1.0.13

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 (46) 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 +103 -0
  7. package/assets/config_templates/github-linux-chrome.conf.js +114 -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 +27 -0
  12. package/examples/main.js +17 -0
  13. package/examples/test--then--i-should--not--see-text-in-element.html +48 -0
  14. package/examples/test--when--i-check-uncheck-checkbox.html +45 -0
  15. package/examples/test--when--i-fill-in.html +48 -0
  16. package/examples/test--when--i-follow-link.html +18 -0
  17. package/examples/test--when--i-press-button.html +27 -0
  18. package/examples/test--when--i-reload-page.html +27 -0
  19. package/examples/test--when--i-select-option-from-selectbox.html +35 -0
  20. package/lib/custom-assertions/smartElementContains.js +54 -0
  21. package/lib/custom-commands/smartCheckItem.js +39 -0
  22. package/lib/custom-commands/smartSelectOption.js +33 -0
  23. package/lib/custom-commands/smartUncheckItem.js +45 -0
  24. package/lib/get-element.js +65 -0
  25. package/nightwatch.conf.js +27 -259
  26. package/package.json +11 -4
  27. package/src/index.js +10 -0
  28. package/tests/features/test--given--i-am-on-homepage.feature +12 -0
  29. package/tests/features/test--then--i-should--not--see-text-in-element.feature +13 -0
  30. package/tests/features/test--then--i-should-be-on-page.feature +10 -0
  31. package/tests/features/test--then--i-should-be-on-the-homepage.feature +9 -0
  32. package/tests/features/test--then--the-response-should-contain.feature +12 -0
  33. package/tests/features/test--when--i-check-checkbox.feature +17 -0
  34. package/tests/features/test--when--i-fill-in.feature +36 -0
  35. package/tests/features/test--when--i-follow-link.feature +11 -0
  36. package/tests/features/test--when--i-move-forward-backward-one-page.feature +14 -0
  37. package/tests/features/test--when--i-press-button.feature +11 -0
  38. package/tests/features/test--when--i-reload-page.feature +14 -0
  39. package/tests/features/test--when--i-select-option-from-selectbox.feature +13 -0
  40. package/tests/features/test--when--i-uncheck-checkbox.feature +20 -0
  41. package/tests/reports/cucumber-report.html +0 -0
  42. package/tests/reports/cucumber-report.json +0 -0
  43. package/tests/step-definitions/webship.js +232 -11
  44. package/webpack.config.js +17 -0
  45. package/webship-init.js +75 -0
  46. package/tests/features/check-webshipco-site.feature +0 -8
@@ -0,0 +1,12 @@
1
+ Feature: Example test for Then the response should contain "text"
2
+ As a tester,
3
+ I want to be able to navigate to a page
4
+ So that I can check if this page contains a specific text
5
+
6
+ Scenario: Check the response should contain "text"
7
+ Given I am on the homepage
8
+ Then the response should contain "Welcome to the homepage"
9
+
10
+ Scenario: Check the response should not contain "text"
11
+ Given I am on the homepage
12
+ Then the response should not contain "Access denied"
@@ -0,0 +1,17 @@
1
+ Feature: Example test for "When I check 'item'"
2
+
3
+ As a tester
4
+ I want to be able to test check a checkbox item
5
+
6
+ Scenario: Check the "When I check 'item'" step definitions
7
+ Given I am on "test--when--i-check-uncheck-checkbox.html"
8
+ When I check "vehicle1"
9
+ And I press "Submit"
10
+ Then I should see "You have a Bike"
11
+ When I check "Car"
12
+ And I press "Submit"
13
+ Then I should see "You have a Bike Car"
14
+ When I check "I have a boat"
15
+ And I press "Submit"
16
+ Then I should see "You have a Bike Car Boat"
17
+
@@ -0,0 +1,36 @@
1
+ Feature: Example test for filling text with value
2
+ As a developer
3
+ I want to be able to test when fill input text with value,
4
+ with empty value, value for text, and fill in table
5
+
6
+ Scenario: Check fill in input field with value
7
+ Given I am on homepage
8
+ When I go to "test--when--i-fill-in.html"
9
+ When I fill in "Username" with "webshipco"
10
+ When I fill in "Password" with "1234"
11
+ When I press "Login"
12
+ Then I should see "You enter Username: webshipco and Password: 1234"
13
+
14
+ Scenario: Check fill in input field with empty value
15
+ Given I am on homepage
16
+ When I go to "test--when--i-fill-in.html"
17
+ When I fill in "Username" with:
18
+ When I press "Login"
19
+ Then I should see "You enter Username: "
20
+
21
+ Scenario: Check fill in value for input field
22
+ Given I am on homepage
23
+ When I go to "test--when--i-fill-in.html"
24
+ When I fill in "webshipco" for "Username"
25
+ When I fill in "1234" for "Password"
26
+ When I press "Login"
27
+ Then I should see "You enter Username: webshipco and Password: 1234"
28
+
29
+ Scenario: Check fill in table of input fields
30
+ Given I am on homepage
31
+ When I go to "test--when--i-fill-in.html"
32
+ When I fill in the following:
33
+ | username | webshipco |
34
+ | password | 1234 |
35
+ When I press "Login"
36
+ Then I should see "You enter Username: webshipco and Password: 1234"
@@ -0,0 +1,11 @@
1
+ Feature: Example test for "When I follow 'link'"
2
+
3
+ As a tester
4
+ I want to be able to test when a link is clicked,
5
+ it will go to the link path page
6
+
7
+ Scenario: Check the "When I follow link" step definitions
8
+ Given I am on "test--when--i-follow-link.html"
9
+ When I follow "About us link"
10
+ Then I should see "About Us"
11
+
@@ -0,0 +1,14 @@
1
+ Feature: Example test for "I move forword one page",and "I move backword one page"
2
+
3
+ As a tester
4
+ I want to be able to test the navigate forward and backward in the browser history
5
+ So that I know it is working
6
+
7
+ Scenario: Check the "Navigate forward and backward" step definitions
8
+ Given I am on the homepage
9
+ When I go to "about-us.html"
10
+ When I move backward one page
11
+ When I move forward one page
12
+ Then I should see "About Us"
13
+ When I move backward one page
14
+ Then I should see "Welcome to the homepage of the Webship-js Examples"
@@ -0,0 +1,11 @@
1
+ Feature: Example test for "When I press button"
2
+
3
+ As a tester
4
+ I want to be able to test button press event
5
+ So that I know it is working
6
+
7
+ Scenario: Check the "When I press button" step definitions
8
+ Given I am on the homepage
9
+ When I go to "test--when--i-press-button.html"
10
+ When I press "Click Button"
11
+ Then I should see "Button Pressed Successfully"
@@ -0,0 +1,14 @@
1
+ Feature: Example test for "When I reload page"
2
+
3
+ As a tester
4
+ I want to be able to test page reload
5
+ So that I know it is working
6
+
7
+ Scenario: Check the "When I reload page" step definitions
8
+ Given I am on the homepage
9
+ When I go to "test--when--i-reload-page.html"
10
+ When I press "Click Button"
11
+ Then I should see "Button Pressed Successfully"
12
+ When I reload the page
13
+ Then I should not see "Button Pressed Successfully"
14
+
@@ -0,0 +1,13 @@
1
+ Feature: Example test for "When I select option from select list"
2
+
3
+ As a tester
4
+ I want to be able to test select option from selectbox
5
+
6
+ Scenario: Check the "When I select 'option' from 'select list'" step definitions
7
+ Given I am on homepage
8
+ When I go to "test--when--i-select-option-from-selectbox.html"
9
+ When I select "saab" from "cars"
10
+ When I press "Check select"
11
+ Then I should see "Option ( Saab ) has been selected successfully"
12
+
13
+
@@ -0,0 +1,20 @@
1
+ Feature: Example test for "When I uncheck 'item'"
2
+
3
+ As a tester
4
+ I want to be able to test uncheck a checkbox item
5
+
6
+ Scenario: Check the "When I uncheck 'item'" step definitions
7
+ Given I am on "test--when--i-check-uncheck-checkbox.html"
8
+ When I check "I have a bike"
9
+ And I press "Submit"
10
+ Then I should see "You have a Bike"
11
+ When I check "vehicle2"
12
+ And I press "Submit"
13
+ Then I should see "You have a Bike Car"
14
+ When I uncheck "Bike"
15
+ And I press "Submit"
16
+ Then I should see "You have a Car"
17
+ When I uncheck "Car"
18
+ And I press "Submit"
19
+ Then I should see "You have a"
20
+
File without changes
File without changes
@@ -2,27 +2,248 @@ const { Given } = require('@cucumber/cucumber');
2
2
  const { When, Before } = require('@cucumber/cucumber');
3
3
  const { Then } = require('@cucumber/cucumber');
4
4
 
5
+ const lib = require('../../lib/get-element.js');
6
+
5
7
  /**
6
- * Navigate to a url.
8
+ * Opens homepage.
9
+ *
10
+ * Example: Given I am on homepage
11
+ * Example: Given I am on the homepage
7
12
  *
8
- * Exmaple:
9
- * - Given I go to "https://webship.co"
13
+ * @Given /^I am on( the)* homepage$/
14
+ */
15
+ Given(/^I am on( the)* homepage$/, function (url) {
16
+ return browser.url(browser.launch_url);
17
+ });
18
+
19
+ /**
20
+ * Opens specified page
21
+ * Example: Given I am on "about-us.html"
22
+ *
23
+ * @Given /^I am on "([^"]*)?"$/
24
+ */
25
+ Given(/^I am on "([^"]*)?"$/, function (url) {
26
+ return browser.url(browser.launch_url + url);
27
+ });
28
+
29
+ /**
30
+ * Opens homepage
31
+ * Example: When I go to the homepage
32
+ * Example: And I go to "/"
33
+ *
34
+ * @When /^I go to( the)* homepage$/
10
35
  */
11
- Given(/^I go to "([^"]*)?"$/, function(url) {
12
- return browser.url(url);
36
+ When(/^I go to( the)* homepage$/, function () {
37
+ return browser.url(browser.launch_url);
38
+ });
39
+
40
+ /**
41
+ * Opens specified page
42
+ * Example: When I go to "contact-us.html"
43
+ *
44
+ * @When /^I go to "([^"]*)?"$/
45
+ */
46
+ When(/^I go to "([^"]*)?"$/, function (url) {
47
+ return browser.url(browser.launch_url + url);
13
48
  });
14
49
 
15
50
  /**
16
51
  * Asserting a text in the page.
17
52
  *
18
- * Exmaple:
53
+ * Example:
19
54
  * - Then I should see "Welcome"
20
55
  * - Then I should not see "Access denied"
56
+ *
57
+ * @Then /^I should( not)* see "([^"]*)?"$/
58
+ */
59
+ Then(/^I should( not)* see "([^"]*)?"$/, function (negativeCase, expectedText) {
60
+ if (negativeCase) {
61
+ return browser.assert.not.textContains('html', expectedText);
62
+ }
63
+
64
+ return browser.assert.textContains('html', expectedText);
65
+ });
66
+
67
+ /**
68
+ * Moves forward one page in history
69
+ * Example: And I move forward one page
70
+ *
71
+ * @When /^I move forward one page$/
72
+ */
73
+ When(/^I move forward one page$/, function () {
74
+ return browser.forward();
75
+ });
76
+
77
+ /**
78
+ * Moves backward one page in history
79
+ * Example: When I move backward one page
80
+ *
81
+ * @When /^I move backward one page$/
82
+ */
83
+ When(/^I move backward one page$/, function () {
84
+ return browser.back();
85
+ });
86
+
87
+ /**
88
+ * Presses button with specified id|name|title|alt|value
89
+ * Example: When I press "Log In"
90
+ * Example: And I press "Log In"
91
+ *
92
+ * @When /^I press "([^"]*)?"$/
93
+ */
94
+ When(/^I press "([^"]*)?"$/, function (elementValue) {
95
+ return browser.click("[value='" + elementValue + "']");
96
+ });
97
+
98
+ /**
99
+ * Clicks link with specified id|title|alt|text
100
+ * Example: When I follow "Log In"
101
+ * Example: And I follow "Log In"
102
+ *
103
+ * @When /^I follow "([^"]*)?"$/
104
+ */
105
+ When(/^I follow "([^"]*)?"$/, function (elementValue) {
106
+ return browser.click("link text", elementValue);
107
+ });
108
+
109
+ /**
110
+ * Reloads current page
111
+ * Example: When I reload the page
112
+ * Example: And I reload the page
113
+ *
114
+ * @When /^I reload( the)* page$/
115
+ */
116
+ When(/^I reload( the)* page$/, function (url) {
117
+ return browser.refresh(browser.getCurrentUrl());
118
+ });
119
+
120
+ /**
121
+ * Fills in form field with specified id|name|label|value
122
+ * Example: When I fill in "username" with "webshipco"
123
+ *
124
+ * @When /^I fill in "([^"]*)?" with "([^"]*)?"$/
125
+ */
126
+ When(/^I fill in "([^"]*)?" with "([^"]*)?"$/, function (field, value) {
127
+ lib.fillInputWithValue(field, value);
128
+ });
129
+
130
+ /**
131
+ * Fills in form field with specified id|name|label|value
132
+ * Example: When I fill in "username" with:
133
+ *
134
+ * @When /^I fill in "([^"]*)?" with:$/
135
+ */
136
+ When(/^I fill in "([^"]*)?" with:$/, function (field) {
137
+ lib.fillInputWithValue(field, '');
138
+ });
139
+
140
+ /**
141
+ * Fills in form field with specified id|name|label|value
142
+ * Example: And I fill in "webshipco" for "username"
143
+ *
144
+ * @When /^I fill in "([^"]*)?" for "([^"]*)?"$/
145
+ */
146
+ When(/^I fill in "([^"]*)?" for "([^"]*)?"$/, function (value, field) {
147
+ lib.fillInputWithValue(field, value);
148
+ });
149
+
150
+ /**
151
+ * Fills in form fields with provided table
152
+ * Example: When I fill in the following:
153
+ * | username | webshipco |
154
+ * | password | 1234 |
155
+ * Example: And I fill in the following"
156
+ * | username | webshipco |
157
+ * | password | 1234 |
158
+ *
159
+ * @When /^I fill in the following:$/
160
+ */
161
+ When(/^I fill in the following:$/, function (table) {
162
+
163
+ lib.fillInputWithValue(table.rawTable[0][0], table.rawTable[0][1]);
164
+ table.rows().forEach(row => {
165
+ lib.fillInputWithValue(row[0], row[1]);
166
+ });
167
+ });
168
+
169
+ /**
170
+ * Selects option in select field with specified id|name|label|value
171
+ * Example: When I select "saab" from "Cars"
172
+ * Example: And I select "saab" from "Cars"
173
+ *
174
+ * @When /^I select "([^"]*)?" from "([^"]*)?"$/
21
175
  */
22
- Then(/^I should( not)* see "([^"]*)?"$/, function(negativeCase, expectedText) {
176
+ When(/^I select "([^"]*)?" from "([^"]*)?"$/, function (option, selectBox) {
177
+ browser.pause(1000).smartSelectOption(option, selectBox).pause(1000);
178
+ });
179
+
180
+ /**
181
+ * Checks checkbox with specified id|name|label|value
182
+ * Example: When I check "Pearl Necklace"
183
+ * Example: And I check "Pearl Necklace"
184
+ *
185
+ * @When /^I check "([^"]*)?"$/
186
+ */
187
+ When(/^I check "([^"]*)?"$/, function (item) {
188
+ browser.smartCheckItem(item);
189
+ });
190
+
191
+ /**
192
+ * Unchecks checkbox with specified id|name|label|value
193
+ * Example: When I uncheck "Broadway Plays"
194
+ * Example: And I uncheck "Broadway Plays"
195
+ *
196
+ * @When /^I uncheck "([^"]*)?"$/
197
+ */
198
+ When(/^I uncheck "([^"]*)?"$/, function (item) {
199
+ browser.smartUncheckItem(item);
200
+ });
201
+
202
+ /**
203
+ * Checks, that current page is the homepage
204
+ * Example: Then I should be on the homepage
205
+ * Example: And I should be on the homepage
206
+ *
207
+ * @Then /^I should be on( the)* homepage$/
208
+ */
209
+ Then(/^I should be on( the)* homepage$/, function (url) {
210
+ return browser.assert.urlEquals(browser.launch_url);
211
+ });
212
+
213
+ /**
214
+ * Checks, that current page PATH is equal to specified
215
+ * Example: Then I should be on "/"
216
+ * Example: And I should be on "/bats"
217
+ * Example: And I should be on "http://google.com"
218
+ *
219
+ * @Then /^I should be on "([^"]*)?"$/
220
+ */
221
+ Then(/^I should be on "([^"]*)?"$/, function (url) {
222
+ return browser.assert.urlContains(url);
223
+ });
224
+
225
+ /**
226
+ * Checks, that HTML response contains specified string
227
+ * Example: Then the response should contain "Batman is the hero Gotham deserves."
228
+ * Example: And the response should contain "Batman is the hero Gotham deserves."
229
+ *
230
+ * @Then /^the response should contain "([^"]*)?"$/
231
+ */
232
+ Then(/^the response should( not)* contain "([^"]*)?"$/, function (negativeCase, expectedText) {
23
233
  if (negativeCase) {
24
- return browser.assert.not.textContains('body', expectedText);
234
+ return browser.assert.not.textContains('html', expectedText);
25
235
  }
26
-
27
- return browser.assert.textContains('body', expectedText);
28
- });
236
+
237
+ return browser.assert.textContains('html', expectedText);
238
+ });
239
+
240
+ /**
241
+ * Checks, that element with specified CSS contains specified text
242
+ * Example: Then I should see "Batman" in the "heroes_list" element
243
+ * Example: And I should see "Batman" in the "heroes_list" element
244
+ *
245
+ * @Then /^I should( not)* see "([^"]*)?" in the "([^"]*)?" element$/
246
+ */
247
+ Then(/^I should( not)* see "([^"]*)?" in the "([^"]*)?" element$/, function (negativeCase, expectedText, element) {
248
+ return browser.assert.smartElementContains(negativeCase, expectedText, element);
249
+ });
@@ -0,0 +1,17 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ entry: './src/index.js',
5
+ mode: 'development',
6
+ output: {
7
+ filename: 'main.js',
8
+ path: path.resolve(__dirname, 'examples'),
9
+ },
10
+ devServer: {
11
+ static: {
12
+ directory: path.join(__dirname, 'examples'),
13
+ },
14
+ compress: true,
15
+ port: 8080,
16
+ },
17
+ };
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const fs = require('fs');
5
+ var insidProject = false;
6
+ var basePath = '';
7
+ var projectPath = '';
8
+
9
+ const currentPath = process.argv[1].split("node_modules");
10
+ basePath = currentPath[0].substring(0, currentPath[0].lastIndexOf("/")) + '/';
11
+
12
+ if(currentPath.length > 1){
13
+ projectPath = basePath + "node_modules/webship-js/";
14
+ }
15
+ else{
16
+ projectPath = basePath;
17
+
18
+ }
19
+
20
+ /**
21
+ * -----------------------------------------------------
22
+ * Parse arguments
23
+ * -----------------------------------------------------
24
+ */
25
+ const { ArgumentParser } = require('argparse');
26
+ const { version } = require('./package.json');
27
+
28
+ const parser = new ArgumentParser({
29
+ description: 'Argparse example'
30
+ });
31
+
32
+ parser.add_argument('-ci', '--continuous_integration',
33
+ {
34
+ help: 'Add your CI services (circleci, github, gitlab, bitbucket), By default: -ci circleci',
35
+ default: 'circleci',
36
+ });
37
+
38
+ parser.add_argument('-b', '--browser',
39
+ {
40
+ help: 'Add your Browser (chrome, firefox), By default: -b chrome',
41
+ default: 'chrome',
42
+ });
43
+
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
+ });
49
+
50
+ var argsParse = parser.parse_args();
51
+
52
+ /**
53
+ * -----------------------------------------------------
54
+ */
55
+
56
+ /**
57
+ * Generate the appropriate nightwatch.conf.js
58
+ *
59
+ * Generate nightwatch testing configs according to the used CI
60
+ * service, operating system, and browser.
61
+ */
62
+
63
+ fs.unlink(projectPath + 'nightwatch.conf.js', (err) => {
64
+ if (err) {
65
+ throw err;
66
+ }
67
+ });
68
+
69
+ const confTemplate = projectPath + 'assets/config_templates/' + argsParse.continuous_integration + '-' + argsParse.operating_system + '-' + argsParse.browser + '.conf.js';
70
+
71
+ fs.copyFile(confTemplate, projectPath + 'nightwatch.conf.js', (err) => {
72
+ if (err) {
73
+ throw err;
74
+ }
75
+ });
@@ -1,8 +0,0 @@
1
- Feature: Example test for webship-js
2
- As a tester
3
- I want to be able to test the webship.co site
4
- So that I know it is working
5
-
6
- Scenario: Check the webship.co site
7
- Given I go to "https://webship.co"
8
- Then I should see "Webship.co"