webship-js 1.0.32 → 1.0.33

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,13 +1,31 @@
1
- const request = require("request");
1
+ const axios = require('axios');
2
2
 
3
3
  module.exports.assertion = function (negativeCase, expectedStatusCode) {
4
4
 
5
- return browser.url(function (currentURL) {
5
+ browser.url(function (currentURL) {
6
6
  request(currentURL.value, (error, response, body) => {
7
7
  if (negativeCase) {
8
- return browser.assert.not.equal(response.statusCode, expectedStatusCode).end();
8
+ return axios.get(currentURL.value)
9
+ .then(function (response) {
10
+ browser.assert.equal(response.status, expectedStatusCode);
11
+ })
12
+ .catch(function (error) {
13
+ browser.assert.equal(error.status, expectedStatusCode);
14
+ })
15
+ .finally(function () {
16
+ // always executed
17
+ });
9
18
  }
10
- return browser.assert.equal(response.statusCode, expectedStatusCode).end();
19
+ return axios.get(currentURL.value)
20
+ .then(function (response) {
21
+ browser.assert.equal(response.status, expectedStatusCode);
22
+ })
23
+ .catch(function (error) {
24
+ browser.assert.equal(error.status, expectedStatusCode);
25
+ })
26
+ .finally(function () {
27
+ // always executed
28
+ });
11
29
  });
12
30
  });
13
- }
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -42,7 +42,7 @@
42
42
  "geckodriver": "*",
43
43
  "webpack-cli": "~5",
44
44
  "webpack-dev-server": "~4",
45
- "request": "~2"
45
+ "axios": "~1"
46
46
  },
47
47
  "bin": {
48
48
  "steplist": "./steplist.js"
@@ -6,4 +6,4 @@ Feature: An example to test if the element contains a certain expected CSS prope
6
6
  Given I am on "/test--then--the-element-should_not-contain-cssproperty.html"
7
7
  Then I should see a "body" element by attr
8
8
  When I press "Submit"
9
- Then the "body" element should contain "background-color:white;" css style
9
+ Then the "body" element should contain "background-color:white;"
@@ -6,5 +6,5 @@ Feature: An example to test if the element does not contain a certain expected C
6
6
  Given I am on "/test--then--the-element-should_not-contain-cssproperty.html"
7
7
  Then I should see a "body" element by attr
8
8
  When I press "Submit"
9
- Then the "#uname" element should not contain "border:solid 5px red;" css style
10
- And the "pword" element should not contain "font-size: 28px;" css style
9
+ Then the "#uname" element should not contain "border:solid 5px red;"
10
+ And the "pword" element should not contain "font-size: 28px;"
@@ -1,11 +1,11 @@
1
- Feature: An example to test if the field contains certain value
1
+ Feature: An example to test if the field contains certain value by element label
2
2
  As a tester
3
- I want to be able to check field if has a certain value or not
3
+ I want to be able to check field if has a certain value by element label
4
4
 
5
- Scenario: Check field if has a particular value or not
5
+ Scenario: Check field if has a particular value by element label
6
6
  Given I am on "/test--then--i-should--not--see-text-in-element.html"
7
7
  And I fill in "Username" with "user1"
8
- Then the "#uname" field should contain "user1"
8
+ Then the "Username" field should contain "user1"
9
9
  When I press "Reset" by attr
10
10
  And I fill in "Username" with "user2"
11
- Then the "#uname" field should not contain "user1"
11
+ Then the "Username" field should contain "user2"
@@ -2,7 +2,7 @@ const { Given} = require('@cucumber/cucumber');
2
2
  const { When, Before} = require('@cucumber/cucumber');
3
3
  const { Then} = require('@cucumber/cucumber');
4
4
 
5
- const request = require('request');
5
+ const axios = require('axios');
6
6
 
7
7
  /**
8
8
  * Opens homepage.
@@ -696,20 +696,7 @@ Then(/^(I|we)* should not see (a|an) "([^"]*)?" element by( its)*( "([^"]*)?")*
696
696
  * Example: Then the "body" element should contain "color:white;"
697
697
  *
698
698
  */
699
- Then(/^the "([^"]*)?" element should contain "([^"]*)?" css style$/, function (attrValue, elementCss) {
700
-
701
- const hasASpace = attrValue.indexOf(' ');
702
-
703
- var selector = '';
704
- if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
705
- selector = attrValue;
706
- }
707
- else if (hasASpace == -1){
708
- selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
709
- }
710
- else if (hasASpace > -1){
711
- selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
712
- }
699
+ Then(/^the "([^"]*)?" element should contain "([^"]*)?"$/, function (selector, elementCss) {
713
700
 
714
701
  elementCss = elementCss.replace(";", '');
715
702
  const cssPropertyArr = elementCss.split(":");
@@ -724,24 +711,11 @@ Then(/^the "([^"]*)?" element should contain "([^"]*)?" css style$/, function (a
724
711
 
725
712
  /**
726
713
  * Assert, that element contains a specific CSS style
727
- * Example: Then the "body" element should not contain "color:white;" css style
728
- * Example: Then the "#uname" element should not contain "border:solid 5px red;" css style
729
- * Example: Then the "pword" element should not contain "font-size: 26px;" css style
714
+ * Example: Then the "body" element should not contain "color:white;"
715
+ * Example: Then the "#uname" element should not contain "border:solid 5px red;"
716
+ * Example: Then the "pword" element should not contain "font-size: 26px;"
730
717
  */
731
- Then(/^the "([^"]*)?" element should not contain "([^"]*)?" css style$/, function (attrValue, elementCss) {
732
-
733
- const hasASpace = attrValue.indexOf(' ');
734
-
735
- var selector = '';
736
- if((attrValue.startsWith('#') || attrValue.startsWith('.')) && hasASpace == -1){
737
- selector = attrValue;
738
- }
739
- else if (hasASpace == -1){
740
- selector = attrValue + ',#' + attrValue + ',.' + attrValue + ',[name=' + attrValue + "]," + '[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
741
- }
742
- else if (hasASpace > -1){
743
- selector ='[value="' + attrValue + '"],[placeholder="' + attrValue + '"]';
744
- }
718
+ Then(/^the "([^"]*)?" element should not contain "([^"]*)?"$/, function (selector, elementCss) {
745
719
 
746
720
  elementCss = elementCss.replace(";", '');
747
721
  const cssPropertyArr = elementCss.split(":");
@@ -760,19 +734,22 @@ Then(/^the "([^"]*)?" element should not contain "([^"]*)?" css style$/, functio
760
734
  *
761
735
  */
762
736
  When(/^(I|we)* attach the file "([^"]*)?" to "([^"]*)?"$/, function (pronoundCase, fileUrl, element) {
763
- // browser.setValue(element, require('path').resolve(__dirname + fileUrl));
737
+
764
738
  });
765
739
 
766
740
  /**
767
741
  * Assert, that field contain a specific text
768
- * Example: Then the "#username" field should contain "John Smith"
742
+ * Example: Then the "Username" field should contain "John Smith"
769
743
  *
770
744
  */
771
745
  Then(/^the "([^"]*)?" field should contain "([^"]*)?"$/, function (field, expectedText) {
772
746
 
773
- return this.shouldSee = function (browser) {
774
- browser.assert.textContains(field, expectedText);
775
- };
747
+ const elementField = browser.element.findByText(field);
748
+ browser.getAttribute(elementField, 'for', function (eleAttribute) {
749
+ return this.shouldSee = function (browser) {
750
+ browser.assert.textContains('#' + eleAttribute.value, expectedText);
751
+ };
752
+ });
776
753
  });
777
754
 
778
755
  /**
@@ -908,8 +885,15 @@ When(/^(I|we)* wait max of (\d*) minute(s)*$/, function (pronoundCase, number, w
908
885
  */
909
886
  Then(/^the response status code should be (\d+)$/, function (expectedStatusCode) {
910
887
  return browser.url(function (currentURL) {
911
- request(currentURL.value, (error, response, body) => {
912
- browser.assert.equal(response.statusCode, expectedStatusCode);
888
+ axios.get(currentURL.value)
889
+ .then(function (response) {
890
+ browser.assert.equal(response.status, expectedStatusCode);
891
+ })
892
+ .catch(function (error) {
893
+ browser.assert.equal(error.status, expectedStatusCode);
894
+ })
895
+ .finally(function () {
896
+ // always executed
913
897
  });
914
898
  });
915
899
  });
@@ -921,8 +905,15 @@ Then(/^the response status code should be (\d+)$/, function (expectedStatusCode)
921
905
  */
922
906
  Then(/^the response status code should not be (\d+)$/, function ( expectedStatusCode) {
923
907
  return browser.url(function (currentURL) {
924
- request(currentURL.value, (error, response, body) => {
925
- browser.assert.not.equal(response.statusCode, expectedStatusCode);
908
+ axios.get(currentURL.value)
909
+ .then(function (response) {
910
+ browser.assert.not.equal(response.status, expectedStatusCode);
911
+ })
912
+ .catch(function (error) {
913
+ browser.assert.not.equal(error.status, expectedStatusCode);
914
+ })
915
+ .finally(function () {
916
+ // always executed
926
917
  });
927
918
  });
928
919
  });
@@ -960,13 +951,9 @@ Then(/^(I|we)* should not see text matching "([^"]*)?"$/, function (pronoundCase
960
951
  *
961
952
  */
962
953
  Then(/^(I|we)* should see text matching "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, textPattern, element) {
963
- // return browser.elements('css selector', element, function (elements) {
964
- // elements.value.forEach(function (elementsObj) {
965
954
  return this.shouldSeePattern = function (browser) {
966
955
  browser.assert.textMatches(element, textPattern);
967
956
  };
968
- // });
969
- // });
970
957
  });
971
958
 
972
959
  /**
@@ -976,15 +963,9 @@ Then(/^(I|we)* should see text matching "([^"]*)?" in the "([^"]*)?" element$/,
976
963
  *
977
964
  */
978
965
  Then(/^(I|we)* should not see text matching "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, textPattern, element) {
979
-
980
- // return browser.elements('css selector', element, function (elements) {
981
- // elements.value.forEach(function (elementsObj) {
982
966
  return this.shouldSeePattern = function (browser) {
983
967
  browser.assert.not.textMatches(element, textPattern);
984
968
  };
985
- // browser.assert.not.textMatches(elementsObj, textPattern);
986
- // });
987
- // });
988
969
  });
989
970
 
990
971
  /**