webship-js 1.0.12 → 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.
@@ -5,9 +5,12 @@ module.exports = {
5
5
  // if this is not specified, the test source must be passed as the second argument to the test runner.
6
6
  src_folders: ['tests/step-definitions'],
7
7
 
8
- // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
8
+ // See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.html
9
9
  custom_commands_path: './lib/custom-commands',
10
10
 
11
+ // See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-assertions.html
12
+ custom_assertions_path: './lib/custom-assertions',
13
+
11
14
  test_runner: {
12
15
  type: 'cucumber',
13
16
  options: {
@@ -5,8 +5,11 @@ module.exports = {
5
5
  // if this is not specified, the test source must be passed as the second argument to the test runner.
6
6
  src_folders: ['tests/step-definitions'],
7
7
 
8
- // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
9
- custom_commands_path: './lib/custom-commands',
8
+ // See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.html
9
+ custom_commands_path: './lib/custom-commands',
10
+
11
+ // See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-assertions.html
12
+ custom_assertions_path: './lib/custom-assertions',
10
13
 
11
14
  webdriver: {
12
15
  start_process: true,
@@ -99,13 +102,13 @@ module.exports = {
99
102
  function loadServices() {
100
103
  try {
101
104
  Services.seleniumServer = require('selenium-server');
102
- } catch (err) {}
105
+ } catch (err) { }
103
106
 
104
107
  try {
105
108
  Services.chromedriver = require('chromedriver');
106
- } catch (err) {}
109
+ } catch (err) { }
107
110
 
108
111
  try {
109
112
  Services.geckodriver = require('geckodriver');
110
- } catch (err) {}
113
+ } catch (err) { }
111
114
  }
@@ -20,6 +20,7 @@
20
20
  <li><a href="test--when--i-follow-link.html">When I go follow "link"</a></li>
21
21
  <li><a href="test--when--i-fill-in.html">When I fill in input text with value</a></li>
22
22
  <li><a href="test--when--i-select-option-from-select.box.html">When I select option from select box</a></li>
23
+ <li><a href="test--then--i-should--not--see-text-in-element.html">When I select option from select box</a></li>
23
24
  </ul>
24
25
  <script src="main.js"></script>
25
26
  </body>
@@ -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="reset" type="reset" value="Reset"><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,45 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset='utf-8'>
6
+ <title>Check Item</title>
7
+ <style>
8
+ .style {
9
+ height: 50px;
10
+ font-size: 26px;
11
+ line-height: 50px;
12
+ }
13
+ </style>
14
+ <script>
15
+ function onClick() {
16
+ var vehicle = document.forms[0];
17
+ var txt = "";
18
+ var i;
19
+ for (i = 0; i < vehicle.length; i++) {
20
+ if (vehicle[i].checked) {
21
+ txt = txt + vehicle[i].value + " ";
22
+ }
23
+ }
24
+ const element = document.getElementById("result");
25
+ element.innerText = "You have a " + txt;
26
+ }
27
+ </script>
28
+ </head>
29
+
30
+ <body>
31
+ <h1>Check Option</h1>
32
+ <form>
33
+ <input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
34
+ <label for="vehicle1"> I have a bike</label><br>
35
+ <input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
36
+ <label for="vehicle2"> I have a car</label><br>
37
+ <input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
38
+ <label for="vehicle3"> I have a boat</label><br>
39
+ </form>
40
+
41
+ <input id="btnClick" class="btnClick" name="btnClick" type="button" value="Submit" onclick="onClick()">
42
+ <div id="result" class="style"></div><br />
43
+ </body>
44
+
45
+ </html>
@@ -0,0 +1,54 @@
1
+
2
+ module.exports.assertion = function (negativeCase, expectedText, element) {
3
+
4
+ browser.element('css selector', element, function (result) {
5
+ if (result.status === 0) {
6
+ if (negativeCase) {
7
+ return browser.assert.not.textContains(element, expectedText);
8
+ }
9
+ return browser.assert.textContains(element, expectedText);
10
+ } else {
11
+ browser.element('css selector', '#' + element, function (result) {
12
+ if (result.status === 0) {
13
+ if (negativeCase) {
14
+ return browser.assert.not.textContains(element, expectedText);
15
+ }
16
+ return browser.assert.textContains(element, expectedText);
17
+ } else {
18
+ browser.element('css selector', 'input[name="' + element + '"]', function (result) {
19
+ if (result.status === 0) {
20
+ if (negativeCase) {
21
+ return browser.assert.not.textContains(element, expectedText);
22
+ }
23
+ return browser.assert.textContains(element, expectedText);
24
+ } else {
25
+ browser.element('css selector', 'input[value="' + element + '"]', function (result) {
26
+ if (result.status === 0) {
27
+ if (negativeCase) {
28
+ return browser.assert.not.textContains(element, expectedText);
29
+ }
30
+ return browser.assert.textContains(element, expectedText);
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 == element) {
36
+ browser.getAttribute(elementsObj, "for", function (forVal) {
37
+ if (negativeCase) {
38
+ return browser.assert.not.textContains('#' + forVal.value, expectedText);
39
+ }
40
+ return browser.assert.textContains('#' + forVal.value, expectedText);
41
+ });
42
+ }
43
+ })
44
+ });
45
+ });
46
+ }
47
+ });
48
+ }
49
+ });
50
+ }
51
+ });
52
+ }
53
+ });
54
+ }
@@ -0,0 +1,39 @@
1
+
2
+ module.exports.command = function (item) {
3
+
4
+ browser.element('css selector', item, function (result) {
5
+ if (result.status === 0) {
6
+ return browser.setAttribute(item, 'checked', true);
7
+ } else {
8
+ browser.element('css selector', '#' + item, function (result) {
9
+ if (result.status === 0) {
10
+ return browser.setAttribute('#' + item, 'checked', true);
11
+ } else {
12
+ browser.element('css selector', 'input[name="' + item + '"]', function (result) {
13
+ if (result.status === 0) {
14
+ return browser.setAttribute('input[name="' + item + '"]', 'checked', true);
15
+ } else {
16
+ browser.element('css selector', 'input[value="' + item + '"]', function (result) {
17
+ if (result.status === 0) {
18
+ return browser.setAttribute('input[value="' + item + '"]', 'checked', true);
19
+ } else {
20
+ browser.elements('css selector', 'label', function (elements) {
21
+ elements.value.forEach(function (elementsObj) {
22
+ browser.elementIdText(elementsObj.ELEMENT, function (result) {
23
+ if (result.value == item) {
24
+ browser.getAttribute(elementsObj, "for", function (forVal) {
25
+ return browser.setAttribute('#' + forVal.value, 'checked', true);
26
+ });
27
+ }
28
+ })
29
+ });
30
+ });
31
+ }
32
+ });
33
+ }
34
+ });
35
+ }
36
+ });
37
+ }
38
+ });
39
+ }
@@ -8,6 +8,24 @@ module.exports.command = function (option, selectBox) {
8
8
  browser.element('css selector', '#' + selectBox, function (result) {
9
9
  if (result.status === 0) {
10
10
  return browser.click('#' + selectBox + ' option[value=' + option + ']');
11
+ } else {
12
+ browser.element('css selector', 'select[name=' + selectBox + ']', function (result) {
13
+ if (result.status === 0) {
14
+ return browser.click('select[name=' + selectBox + ']' + ' option[value=' + option + ']');
15
+ } else {
16
+ browser.elements('css selector', 'label', function (elements) {
17
+ elements.value.forEach(function (elementsObj) {
18
+ browser.elementIdText(elementsObj.ELEMENT, function (result) {
19
+ if (result.value == selectBox) {
20
+ browser.getAttribute(elementsObj, "for", function (forVal) {
21
+ return browser.click('#' + forVal.value + ' option[value=' + option + ']');
22
+ });
23
+ }
24
+ })
25
+ });
26
+ });
27
+ }
28
+ });
11
29
  }
12
30
  });
13
31
  }
@@ -0,0 +1,45 @@
1
+
2
+ module.exports.command = function (item) {
3
+
4
+ browser.element('css selector', item, function (result) {
5
+ if (result.status === 0) {
6
+ browser.setAttribute(item, 'checked', false);
7
+ return browser.click(item);
8
+ } else {
9
+ browser.element('css selector', '#' + item, function (result) {
10
+ if (result.status === 0) {
11
+ browser.setAttribute('#' + item, 'checked', false);
12
+ return browser.click('#' + item);
13
+ } else {
14
+ browser.element('css selector', 'input[name=' + item + ']', function (result) {
15
+ if (result.status === 0) {
16
+ browser.setAttribute('input[name=' + item + ']', 'checked', false);
17
+ return browser.click('input[name=' + item + ']');
18
+
19
+ } else {
20
+ browser.element('css selector', 'input[value="' + item + '"]', function (result) {
21
+ if (result.status === 0) {
22
+ browser.setAttribute('input[value="' + item + '"]', 'checked', false);
23
+ return browser.click('input[value="' + item + '"]');
24
+ } else {
25
+ browser.elements('css selector', 'label', function (elements) {
26
+ elements.value.forEach(function (elementsObj) {
27
+ browser.elementIdText(elementsObj.ELEMENT, function (result) {
28
+ if (result.value == item) {
29
+ browser.getAttribute(elementsObj, "for", function (forVal) {
30
+ browser.setAttribute('#' + forVal.value, 'checked', false);
31
+ return browser.click('#' + forVal.value);
32
+ });
33
+ }
34
+ })
35
+ });
36
+ });
37
+ }
38
+ });
39
+ }
40
+ });
41
+ }
42
+ });
43
+ }
44
+ });
45
+ }
@@ -5,9 +5,12 @@ module.exports = {
5
5
  // if this is not specified, the test source must be passed as the second argument to the test runner.
6
6
  src_folders: ['tests/step-definitions'],
7
7
 
8
- // See https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
8
+ // See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.html
9
9
  custom_commands_path: './lib/custom-commands',
10
10
 
11
+ // See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-assertions.html
12
+ custom_assertions_path: './lib/custom-assertions',
13
+
11
14
  test_runner: {
12
15
  type: 'cucumber',
13
16
  options: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -0,0 +1,13 @@
1
+ Feature: Example test for: Then I should see "text" in the "element" element
2
+ As a developer
3
+ I want to be able to check an element if it has a particular text or not
4
+
5
+ Scenario: Check an element if it has a particular text 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
+ And I fill in "Password" with "1234"
10
+ Then I should see "user1" in the "Username" element
11
+ When I press "Reset"
12
+ And I fill in "Username" with "user2"
13
+ Then I should not see "user1" in the "Username" element
@@ -0,0 +1,10 @@
1
+ Feature: Example test for "Then I should be on 'page'"
2
+ As a tester
3
+ I want to be sure I am on "page"
4
+
5
+ Scenario: Check "Then I should be on the 'page'" step definition
6
+ Given I am on the homepage
7
+ When I go to "about-us.html"
8
+ Then I should be on "about-us.html"
9
+ When I move backward one page
10
+ Then I should be on "/"
@@ -0,0 +1,9 @@
1
+ Feature: Example test for "Then I should be on the homepage"
2
+ As a tester
3
+ I want to be sure I am on the homepage
4
+
5
+ Scenario: Check "Then I should be on the homepage" step definition
6
+ Given I am on the homepage
7
+ When I go to "about-us.html"
8
+ And I move backward one page
9
+ Then I should be on the homepage
@@ -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,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
+
@@ -20,8 +20,9 @@ Given(/^I am on( the)* homepage$/, function (url) {
20
20
  * Opens specified page
21
21
  * Example: Given I am on "about-us.html"
22
22
  *
23
+ * @Given /^I am on "([^"]*)?"$/
23
24
  */
24
- Given(/^I am on "([^"]*)?"$/, function (url) {
25
+ Given(/^I am on "([^"]*)?"$/, function (url) {
25
26
  return browser.url(browser.launch_url + url);
26
27
  });
27
28
 
@@ -30,8 +31,9 @@ Given(/^I am on( the)* homepage$/, function (url) {
30
31
  * Example: When I go to the homepage
31
32
  * Example: And I go to "/"
32
33
  *
34
+ * @When /^I go to( the)* homepage$/
33
35
  */
34
- When(/^ I go to( the)* homepage$/, function () {
36
+ When(/^I go to( the)* homepage$/, function () {
35
37
  return browser.url(browser.launch_url);
36
38
  });
37
39
 
@@ -39,6 +41,7 @@ When(/^ I go to( the)* homepage$/, function () {
39
41
  * Opens specified page
40
42
  * Example: When I go to "contact-us.html"
41
43
  *
44
+ * @When /^I go to "([^"]*)?"$/
42
45
  */
43
46
  When(/^I go to "([^"]*)?"$/, function (url) {
44
47
  return browser.url(browser.launch_url + url);
@@ -53,7 +56,7 @@ When(/^I go to "([^"]*)?"$/, function (url) {
53
56
  *
54
57
  * @Then /^I should( not)* see "([^"]*)?"$/
55
58
  */
56
- Then(/^I should( not)* see "([^"]*)?"$/, function (negativeCase, expectedText) {
59
+ Then(/^I should( not)* see "([^"]*)?"$/, function (negativeCase, expectedText) {
57
60
  if (negativeCase) {
58
61
  return browser.assert.not.textContains('html', expectedText);
59
62
  }
@@ -67,10 +70,10 @@ When(/^I go to "([^"]*)?"$/, function (url) {
67
70
  *
68
71
  * @When /^I move forward one page$/
69
72
  */
70
- When(/^I move forward one page$/, function () {
73
+ When(/^I move forward one page$/, function () {
71
74
  return browser.forward();
72
75
  });
73
-
76
+
74
77
  /**
75
78
  * Moves backward one page in history
76
79
  * Example: When I move backward one page
@@ -99,7 +102,7 @@ When(/^I press "([^"]*)?"$/, function (elementValue) {
99
102
  *
100
103
  * @When /^I follow "([^"]*)?"$/
101
104
  */
102
- When(/^I follow "([^"]*)?"$/, function (elementValue) {
105
+ When(/^I follow "([^"]*)?"$/, function (elementValue) {
103
106
  return browser.click("link text", elementValue);
104
107
  });
105
108
 
@@ -108,8 +111,9 @@ When(/^I press "([^"]*)?"$/, function (elementValue) {
108
111
  * Example: When I reload the page
109
112
  * Example: And I reload the page
110
113
  *
114
+ * @When /^I reload( the)* page$/
111
115
  */
112
- When(/^I reload( the)* page$/, function (url) {
116
+ When(/^I reload( the)* page$/, function (url) {
113
117
  return browser.refresh(browser.getCurrentUrl());
114
118
  });
115
119
 
@@ -170,5 +174,76 @@ When(/^I fill in the following:$/, function (table) {
170
174
  * @When /^I select "([^"]*)?" from "([^"]*)?"$/
171
175
  */
172
176
  When(/^I select "([^"]*)?" from "([^"]*)?"$/, function (option, selectBox) {
173
- browser.smartSelectOption(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);
174
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) {
233
+ if (negativeCase) {
234
+ return browser.assert.not.textContains('html', expectedText);
235
+ }
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
+ });