webship-js 1.0.22 → 1.0.23

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 (31) hide show
  1. package/.circleci/config.yml +8 -5
  2. package/.github/workflows/github-actions.yml +7 -4
  3. package/.gitlab-ci.yml +23 -35
  4. package/CNAME +1 -0
  5. package/examples/test--then--i-should--not--see-text-in-element.html +1 -1
  6. package/examples/test-acceptable-url-path.html +11 -0
  7. package/generate-reports.js +1 -1
  8. package/lib/custom-assertions/backToHomepage.js +15 -0
  9. package/lib/custom-assertions/{smartCheckboxChecked.js → checkboxChecked.js} +10 -10
  10. package/lib/custom-assertions/{smartElementContainsCss.js → elementContainsCss.js} +10 -10
  11. package/lib/custom-assertions/{smartElementContains.js → elementContainsText.js} +10 -10
  12. package/lib/custom-assertions/responseStatus.js +13 -0
  13. package/lib/custom-assertions/shouldVisible.js +8 -0
  14. package/lib/custom-assertions/textMatching.js +2 -2
  15. package/lib/custom-commands/{smartUploadFile.js → fileUpload.js} +0 -1
  16. package/lib/custom-commands/press.js +3 -0
  17. package/lib/custom-commands/wait.js +12 -0
  18. package/nightwatch.conf.js +1 -1
  19. package/package.json +1 -1
  20. package/tests/features/test--given--i-am-on-homepage.feature +9 -5
  21. package/tests/features/test--then--i-should--not--see-text-in-element.feature +2 -2
  22. package/tests/features/test--then--i-should--see-text-matching-pattern.feature +0 -0
  23. package/tests/features/test--then--i-should-be-on-page.feature +1 -1
  24. package/tests/features/test--then--the-url-should-match.feature +7 -0
  25. package/tests/step-definitions/webship.js +71 -130
  26. package/lib/custom-commands/smartPressButton.js +0 -12
  27. /package/lib/custom-commands/{smartCheckItem.js → checkItem.js} +0 -0
  28. /package/lib/custom-commands/{smartClickLink.js → clickLink.js} +0 -0
  29. /package/lib/custom-commands/{smartFillTextInput.js → fillTextInput.js} +0 -0
  30. /package/lib/custom-commands/{smartSelectOption.js → selectOption.js} +0 -0
  31. /package/lib/custom-commands/{smartUncheckItem.js → uncheckItem.js} +0 -0
@@ -27,7 +27,7 @@ commands:
27
27
  - run:
28
28
  name: Install node js
29
29
  command: |
30
- curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
30
+ curl -sL https://deb.nodesource.com/setup_18.x | sudo bash -
31
31
  sudo apt install -y nodejs
32
32
  sudo npm install -g yarn
33
33
  ## Install Java.
@@ -43,14 +43,16 @@ commands:
43
43
  sudo apt install libu2f-udev
44
44
  sudo apt-get install libappindicator1 fonts-liberation libgbm1 libgtk-3-0 xdg-utils
45
45
  export CHROME_BIN=/usr/bin/google-chrome
46
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
47
- sudo dpkg -i google-chrome-stable_current_amd64.deb
48
- rm google-chrome-stable_current_amd64.deb
46
+ CHROME_VERSION="115.0.5790.110-1"
47
+ wget https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb
48
+ sudo dpkg -i google-chrome-stable_${CHROME_VERSION}_amd64.deb
49
+ rm google-chrome-stable_${CHROME_VERSION}_amd64.deb
50
+
49
51
  ## Install/Update Chrome Driver.
50
52
  - run:
51
53
  name: Install/Update Chrome Driver
52
54
  command: |
53
- CHROME_DRIVER_VERSION=$(wget -qO- chromedriver.storage.googleapis.com/LATEST_RELEASE);
55
+ CHROME_DRIVER_VERSION=114.0.5735.90;
54
56
  echo $CHROME_DRIVER_VERSION;
55
57
  wget http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip
56
58
  unzip chromedriver_linux64.zip
@@ -84,6 +86,7 @@ jobs:
84
86
  - run:
85
87
  name: Start virtual server
86
88
  command: |
89
+ export NODE_OPTIONS=--openssl-legacy-provider
87
90
  yarn start
88
91
  background: true
89
92
  - run:
@@ -14,18 +14,21 @@ jobs:
14
14
  steps:
15
15
  - name: Install Chrome
16
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
17
+ CHROME_VERSION="117.0.5938.92-1"
18
+ wget https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb
19
+ sudo dpkg -i google-chrome-stable_${CHROME_VERSION}_amd64.deb
19
20
  - uses: actions/checkout@v3
20
21
  - name: Use Node.js
21
22
  uses: actions/setup-node@v3
22
23
  with:
23
- node-version: '16.x'
24
+ node-version: '18.x'
24
25
  - name: Install
25
26
  run: yarn install
26
27
  - name: Configure nightwatch.conf.js for Github
27
28
  run: node webship-init -ci github -os linux -b chrome
28
29
  - name: Start
29
- run: yarn start &
30
+ run: |
31
+ export NODE_OPTIONS=--openssl-legacy-provider
32
+ yarn start &
30
33
  - name: Test
31
34
  run: yarn test
package/.gitlab-ci.yml CHANGED
@@ -1,52 +1,40 @@
1
1
  image: node:16
2
2
 
3
3
  stages:
4
- - check
4
+ - setup
5
+ - test
5
6
 
6
7
  check:
7
- stage: check
8
+ stage: setup
8
9
  script:
9
- # Dependencies for chromedriver, https://gist.github.com/mikesmullin/2636776#gistcomment-1742414
10
- # Otherwise we get this error: "error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory"
11
- - apt-get update -q -y
12
- - apt-get --yes install libnss3
13
- - apt-get --yes install libgconf-2-4
10
+ # Install Node.js and yarn
11
+ - apt-get update -qy
12
+ - apt-get install -y nodejs yarn
14
13
 
15
- # Install chrome
16
- # Based off of
17
- # - https://gitlab.com/gitlab-org/gitlab-build-images/blob/9dadb28021f15913a49897126a0cd6ab0149e44f/scripts/install-chrome
18
- # - https://askubuntu.com/a/510186/196148
19
- #
20
- # Add key
21
- - curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
22
- # Add repo
23
- - echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
24
- - apt-get update -q -y
25
- - apt-get install -y google-chrome-stable
14
+ # Install Google Chrome and Chromedriver
15
+ - apt-get install -y wget unzip
16
+ - wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
17
+ - dpkg -i google-chrome*.deb
18
+ - apt-get -f install -y
19
+ - CHROMEDRIVER_VERSION=$(curl -sS https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
20
+ - wget -q https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip
21
+ - unzip chromedriver_linux64.zip
22
+ - mv chromedriver /usr/local/bin/
23
+ - chmod +x /usr/local/bin/chromedriver
26
24
 
27
- - npm install chromedriver -g
28
- - npm install nightwatch -g
29
- - npm install https://gitlab.com/gitlab-org/gitlab-selenium-server.git -g
30
- - which chromedriver
31
- # The `&` at the end causes it to run in the background and not block the following commands
32
- - nohup chromedriver --port=4444 --url-base=wd/hub &
33
- - nohup gitlab-selenium-server &
34
- # Install cucumber & pretty formatter .
35
- - npm i @cucumber/cucumber
36
- - npm i @cucumber/pretty-formatter
37
-
38
- # Run your tests
39
- - npm start
40
- - npm test
25
+ # Install dependencies and run Webpack
26
+ - yarn install
27
+ - yarn start
28
+ - yarn test
41
29
 
42
30
  # Show the logs for the GitLab Selenium Server service
43
- - mkdir -p selenium/ && curl -s http://localhost:4545/logs.tar.gz | tar -xvzf - -C selenium/
44
- - mkdir -p selenium/ && curl http://localhost:4545/server-log --output selenium/server-log.txt
31
+ - mkdir -p selenium/ && curl -s http://localhost:8080/logs.tar.gz | tar -xvzf - -C selenium/
32
+ - mkdir -p selenium/ && curl http://localhost:8080/server-log --output selenium/server-log.txt
45
33
  artifacts:
46
34
  when: always
47
35
  paths:
48
36
  - selenium/
49
37
  variables:
50
- SELENIUM_REMOTE_URL: http://localhost:4545/wd/hub
38
+ SELENIUM_REMOTE_URL: http://localhost:8080
51
39
  GITLAB_TARGET_SELENIUM_REMOTE_URL: http://localhost:4444/wd/hub
52
40
 
package/CNAME ADDED
@@ -0,0 +1 @@
1
+ webship.co
@@ -38,7 +38,7 @@
38
38
  <p><label for="pword"><b>Password</b></label></p>
39
39
  <p><input id="pword" class="pwordcss" type="password" placeholder="Enter Password" name="password"></p>
40
40
 
41
- <p><input id="reset" type="reset" value="Reset"><input id="btnLogin" class="btnLogin" name="btnLogin" type="button" value="Login" onclick="onClick()"></p>
41
+ <p><input id="reset" type="reset" value="Reset" /><input id="btnLogin" class="btnLogin" name="btnLogin" type="button" value="Login" onclick="onClick()" /></p>
42
42
 
43
43
  </div>
44
44
 
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <meta http-equiv='X-UA-Compatible' content='IE=edge'>
6
+ <title>Test Acceptable URL Path</title>
7
+ </head>
8
+ <body>
9
+ Example for test acceptable URL path that have "-" between words.
10
+ </body>
11
+ </html>
@@ -6,7 +6,7 @@ var options = {
6
6
  output: 'tests/reports/cucumber_report.html',
7
7
  reportSuiteAsScenarios: true,
8
8
  scenarioTimestamp: true,
9
- launchReport: true,
9
+ launchReport: false,
10
10
  brandTitle: "Test Report",
11
11
  metadata: {
12
12
  "App Version": "7.1.0",
@@ -0,0 +1,15 @@
1
+
2
+ module.exports.assertion = function (negativeCase) {
3
+
4
+ browser.getCurrentUrl(function(result) {
5
+ var homepageUrl = browser.launch_url;
6
+ if(endsWith(result.value, "/")){
7
+ homepageUrl += "/";
8
+ }
9
+
10
+ if (negativeCase) {
11
+ return browser.assert.not.urlEquals(homepageUrl).end();
12
+ }
13
+ return browser.assert.urlEquals(homepageUrl).end();
14
+ });
15
+ }
@@ -4,30 +4,30 @@ module.exports.assertion = function (checkbox, negativeCase) {
4
4
  browser.element('css selector', checkbox, function (result) {
5
5
  if (result.status === 0) {
6
6
  if (negativeCase) {
7
- return browser.expect.element(checkbox).to.not.be.selected;
7
+ return browser.expect.element(checkbox).to.not.be.selected.end();
8
8
  }
9
- return browser.expect.element(checkbox).to.be.selected;
9
+ return browser.expect.element(checkbox).to.be.selected.end();
10
10
  } else {
11
11
  browser.element('css selector', '#' + checkbox, function (result) {
12
12
  if (result.status === 0) {
13
13
  if (negativeCase) {
14
- return browser.expect.element('#' + checkbox).to.not.be.selected;
14
+ return browser.expect.element('#' + checkbox).to.not.be.selected.end();
15
15
  }
16
- return browser.expect.element('#' + checkbox).to.be.selected;
16
+ return browser.expect.element('#' + checkbox).to.be.selected.end();
17
17
  } else {
18
18
  browser.element('css selector', 'input[name="' + checkbox + '"]', function (result) {
19
19
  if (result.status === 0) {
20
20
  if (negativeCase) {
21
- return browser.expect.element('input[name="' + checkbox + '"]').to.not.be.selected;
21
+ return browser.expect.element('input[name="' + checkbox + '"]').to.not.be.selected.end();
22
22
  }
23
- return browser.expect.element('input[name="' + checkbox + '"]').to.be.selected;
23
+ return browser.expect.element('input[name="' + checkbox + '"]').to.be.selected.end();
24
24
  } else {
25
25
  browser.element('css selector', 'input[value="' + checkbox + '"]', function (result) {
26
26
  if (result.status === 0) {
27
27
  if (negativeCase) {
28
- return browser.expect.element('input[value="' + checkbox + '"]').to.not.be.selected;
28
+ return browser.expect.element('input[value="' + checkbox + '"]').to.not.be.selected.end();
29
29
  }
30
- return browser.expect.element('input[value="' + checkbox + '"]').to.be.selected;
30
+ return browser.expect.element('input[value="' + checkbox + '"]').to.be.selected.end();
31
31
  } else {
32
32
  browser.elements('css selector', 'label', function (elements) {
33
33
  elements.value.forEach(function (elementsObj) {
@@ -35,9 +35,9 @@ module.exports.assertion = function (checkbox, negativeCase) {
35
35
  if (result.value == checkbox) {
36
36
  browser.getAttribute(elementsObj, "for", function (forVal) {
37
37
  if (negativeCase) {
38
- return browser.expect.element('#' + forVal.value).to.not.be.selected;
38
+ return browser.expect.element('#' + forVal.value).to.not.be.selected.end();
39
39
  }
40
- return browser.expect.element('#' + forVal.value).to.be.selected;
40
+ return browser.expect.element('#' + forVal.value).to.be.selected.end();
41
41
  });
42
42
  }
43
43
  })
@@ -10,30 +10,30 @@ module.exports.assertion = function (element, negativeCase, elementCss) {
10
10
  browser.element('css selector', element, function (result) {
11
11
  if (result.status === 0) {
12
12
  if (negativeCase) {
13
- return browser.assert.not.cssProperty(element, cssProperty, propertyVal);
13
+ return browser.assert.not.cssProperty(element, cssProperty, propertyVal).end();
14
14
  }
15
- return browser.assert.cssProperty(element, cssProperty, propertyVal);
15
+ return browser.assert.cssProperty(element, cssProperty, propertyVal).end();
16
16
  } else {
17
17
  browser.element('css selector', '#' + element, function (result) {
18
18
  if (result.status === 0) {
19
19
  if (negativeCase) {
20
- return browser.assert.not.cssProperty(element, cssProperty, propertyVal);
20
+ return browser.assert.not.cssProperty(element, cssProperty, propertyVal).end();
21
21
  }
22
- return browser.assert.cssProperty(element, cssProperty, propertyVal);
22
+ return browser.assert.cssProperty(element, cssProperty, propertyVal).end();
23
23
  } else {
24
24
  browser.element('css selector', 'input[name="' + element + '"]', function (result) {
25
25
  if (result.status === 0) {
26
26
  if (negativeCase) {
27
- return browser.assert.not.cssProperty(element, cssProperty, propertyVal);
27
+ return browser.assert.not.cssProperty(element, cssProperty, propertyVal).end();
28
28
  }
29
- return browser.assert.cssProperty(element, cssProperty, propertyVal);
29
+ return browser.assert.cssProperty(element, cssProperty, propertyVal).end();
30
30
  } else {
31
31
  browser.element('css selector', 'input[value="' + element + '"]', function (result) {
32
32
  if (result.status === 0) {
33
33
  if (negativeCase) {
34
- return browser.assert.not.cssProperty(element, cssProperty, propertyVal);
34
+ return browser.assert.not.cssProperty(element, cssProperty, propertyVal).end();
35
35
  }
36
- return browser.assert.cssProperty(element, cssProperty, propertyVal);
36
+ return browser.assert.cssProperty(element, cssProperty, propertyVal).end();
37
37
  } else {
38
38
  browser.elements('css selector', 'label', function (elements) {
39
39
  elements.value.forEach(function (elementsObj) {
@@ -43,9 +43,9 @@ module.exports.assertion = function (element, negativeCase, elementCss) {
43
43
 
44
44
  console.log('#' + forVal.value, cssProperty, propertyVal);
45
45
  if (negativeCase) {
46
- return browser.assert.not.cssProperty('#' + forVal.value, cssProperty, propertyVal);
46
+ return browser.assert.not.cssProperty('#' + forVal.value, cssProperty, propertyVal).end();
47
47
  }
48
- return browser.assert.cssProperty('#' + forVal.value, cssProperty, propertyVal);
48
+ return browser.assert.cssProperty('#' + forVal.value, cssProperty, propertyVal).end();
49
49
  });
50
50
  }
51
51
  })
@@ -4,30 +4,30 @@ module.exports.assertion = function (negativeCase, expectedText, element) {
4
4
  browser.element('css selector', element, function (result) {
5
5
  if (result.status === 0) {
6
6
  if (negativeCase) {
7
- return browser.assert.not.textContains(element, expectedText);
7
+ return browser.assert.not.textContains(element, expectedText).end();
8
8
  }
9
- return browser.assert.textContains(element, expectedText);
9
+ return browser.assert.textContains(element, expectedText).end();
10
10
  } else {
11
11
  browser.element('css selector', '#' + element, function (result) {
12
12
  if (result.status === 0) {
13
13
  if (negativeCase) {
14
- return browser.assert.not.textContains(element, expectedText);
14
+ return browser.assert.not.textContains(element, expectedText).end();
15
15
  }
16
- return browser.assert.textContains(element, expectedText);
16
+ return browser.assert.textContains(element, expectedText).end();
17
17
  } else {
18
18
  browser.element('css selector', 'input[name="' + element + '"]', function (result) {
19
19
  if (result.status === 0) {
20
20
  if (negativeCase) {
21
- return browser.assert.not.textContains(element, expectedText);
21
+ return browser.assert.not.textContains(element, expectedText).end();
22
22
  }
23
- return browser.assert.textContains(element, expectedText);
23
+ return browser.assert.textContains(element, expectedText).end();
24
24
  } else {
25
25
  browser.element('css selector', 'input[value="' + element + '"]', function (result) {
26
26
  if (result.status === 0) {
27
27
  if (negativeCase) {
28
- return browser.assert.not.textContains(element, expectedText);
28
+ return browser.assert.not.textContains(element, expectedText).end();
29
29
  }
30
- return browser.assert.textContains(element, expectedText);
30
+ return browser.assert.textContains(element, expectedText).end();
31
31
  } else {
32
32
  browser.elements('css selector', 'label', function (elements) {
33
33
  elements.value.forEach(function (elementsObj) {
@@ -35,9 +35,9 @@ module.exports.assertion = function (negativeCase, expectedText, element) {
35
35
  if (result.value == element) {
36
36
  browser.getAttribute(elementsObj, "for", function (forVal) {
37
37
  if (negativeCase) {
38
- return browser.assert.not.textContains('#' + forVal.value, expectedText);
38
+ return browser.assert.not.textContains('#' + forVal.value, expectedText).end();
39
39
  }
40
- return browser.assert.textContains('#' + forVal.value, expectedText);
40
+ return browser.assert.textContains('#' + forVal.value, expectedText).end();
41
41
  });
42
42
  }
43
43
  })
@@ -0,0 +1,13 @@
1
+ const request = require("request");
2
+
3
+ module.exports.assertion = function (negativeCase, expectedStatusCode) {
4
+
5
+ return browser.url(function (currentURL) {
6
+ request(currentURL.value, (error, response, body) => {
7
+ if (negativeCase) {
8
+ return browser.assert.not.equal(response.statusCode, expectedStatusCode).end();
9
+ }
10
+ return browser.assert.equal(response.statusCode, expectedStatusCode).end();
11
+ });
12
+ });
13
+ }
@@ -0,0 +1,8 @@
1
+
2
+ module.exports.assertion = function (negativeCase, element) {
3
+
4
+ if (negativeCase) {
5
+ return browser.verify.not.visible(element).end();
6
+ }
7
+ return browser.verify.visible(element).end();
8
+ }
@@ -4,9 +4,9 @@ module.exports.assertion = function (negativeCase, textPattern, element) {
4
4
  browser.elements('css selector', element, function (elements) {
5
5
  elements.value.forEach(function (elementsObj) {
6
6
  if (negativeCase) {
7
- return browser.assert.not.textMatches(elementsObj, textPattern);
7
+ return browser.assert.not.textMatches(elementsObj, textPattern).end();
8
8
  }
9
- return browser.assert.textMatches(elementsObj, textPattern);
9
+ return browser.assert.textMatches(elementsObj, textPattern).end();
10
10
  });
11
11
  });
12
12
  }
@@ -1,4 +1,3 @@
1
-
2
1
  module.exports.command = function (fileUrl, element) {
3
2
  browser.element('css selector', element, function (result) {
4
3
  if (result.status === 0) {
@@ -0,0 +1,3 @@
1
+ module.exports.command = function (item) {
2
+ return browser.click("[value='" + item + "']");
3
+ }
@@ -0,0 +1,12 @@
1
+ module.exports.command = function (maxof, number, timeType) {
2
+
3
+ var waitTime = number * 1000;
4
+ if(timeType == "m"){
5
+ waitTime = waitTime * 60;
6
+ }
7
+
8
+ if (maxof) {
9
+ return browser.waitForElementPresent('body', waitTime);
10
+ }
11
+ return browser.pause(waitTime);
12
+ }
@@ -17,7 +17,7 @@ module.exports = {
17
17
  options: {
18
18
  feature_path: 'tests/features/*.feature',
19
19
  additional_config: '',
20
- parallel: 2,
20
+ parallel: 1,
21
21
  },
22
22
  },
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -2,11 +2,15 @@ Feature: An example to test for being on the homepage
2
2
  As an anonymous user
3
3
  I want to be able to navigate to the homepage
4
4
  So that I can check the welcome message at homepage
5
-
6
- Scenario: Check being on the homepage
5
+
6
+ Scenario: Check to be on (the) homepage
7
7
  Given I am on the homepage
8
- Then I should see "Welcome to the homepage of the Webship-js Examples"
8
+ Then I should see "Welcome to the homepage of the Webship-js Examples"
9
9
 
10
- Scenario: Check being on homepage
10
+ Scenario: Check to be on homepage
11
11
  Given I am on homepage
12
- Then I should see "Welcome to the homepage of the Webship-js Examples"
12
+ Then I should see "Welcome to the homepage of the Webship-js Examples"
13
+
14
+ Scenario: Check to be on homepage (useing we)
15
+ Given we are on homepage
16
+ Then we should see "Welcome to the homepage of the Webship-js Examples"
@@ -7,8 +7,8 @@ Feature: An example to test whether an element contains a certain text or not
7
7
  And I fill in "Username" with "user1"
8
8
  And I fill in "Password" with "1234"
9
9
  Then I should see "user1" in the "Username" element
10
- When I press "Reset"
11
- And I fill in "Username" with "user2"
10
+ When I fill in "Username" with:
11
+ And I fill in "Password" with:
12
12
  Then I should not see "user1" in the "Username" element
13
13
 
14
14
  Scenario: Check an element if it does not contain a specific text
@@ -7,4 +7,4 @@ Feature: An example to test being on a specific page
7
7
  When I go to "/about-us.html"
8
8
  Then I should be on "/about-us.html"
9
9
  When I move backward one page
10
- Then I should be on "/"
10
+ Then I should be on homepage
@@ -0,0 +1,7 @@
1
+ Feature: An example of testing for matching URLs for a particular expression
2
+ As a tester
3
+ I want to be able to be sure that current page PATH matches regular expression
4
+
5
+ Scenario: Check the current page path matchs URL expression with dashes between words
6
+ Given I am on "/test-acceptable-url-path.html"
7
+ Then the url should match "(https?:\/\/)?([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^?#\s_]+)?(\?[^#\s_]+)?(#.*)?"
@@ -1,13 +1,7 @@
1
- const {
2
- Given
3
- } = require('@cucumber/cucumber');
4
- const {
5
- When,
6
- Before
7
- } = require('@cucumber/cucumber');
8
- const {
9
- Then
10
- } = require('@cucumber/cucumber');
1
+ const { Given } = require('@cucumber/cucumber');
2
+ const { When, Before } = require('@cucumber/cucumber');
3
+ const { Then } = require('@cucumber/cucumber');
4
+ const { endsWith } = require('lodash');
11
5
 
12
6
  const request = require('request');
13
7
 
@@ -16,9 +10,8 @@ const request = require('request');
16
10
  * Example: Given I am on homepage
17
11
  * Example: Given I am on the homepage
18
12
  *
19
- * @Given /^I am on( the)* homepage$/
20
13
  */
21
- Given(/^I am on( the)* homepage$/, function (url) {
14
+ Given(/^(I am|we are) on( the)* homepage$/, function (pronoundCase, theCase) {
22
15
  return browser.url(browser.launch_url);
23
16
  });
24
17
 
@@ -26,9 +19,8 @@ Given(/^I am on( the)* homepage$/, function (url) {
26
19
  * Open specific page
27
20
  * Example: Given I am on "about-us.html"
28
21
  *
29
- * @Given /^I am on "([^"]*)?"$/
30
22
  */
31
- Given(/^I am on "([^"]*)?"$/, function (url) {
23
+ Given(/^(I am|we are) on "([^"]*)?"$/, function (pronoundCase, url) {
32
24
  return browser.url(browser.launch_url + url);
33
25
  });
34
26
 
@@ -37,9 +29,8 @@ Given(/^I am on "([^"]*)?"$/, function (url) {
37
29
  * Example: When I go to the homepage
38
30
  * Example: And I go to "/"
39
31
  *
40
- * @When /^I go to( the)* homepage$/
41
32
  */
42
- When(/^I go to( the)* homepage$/, function () {
33
+ When(/^(I|we)* go to( the)* homepage$/, function (pronoundCase, theCase) {
43
34
  return browser.url(browser.launch_url);
44
35
  });
45
36
 
@@ -47,9 +38,8 @@ When(/^I go to( the)* homepage$/, function () {
47
38
  * Go to specific page
48
39
  * Example: When I go to "contact-us.html"
49
40
  *
50
- * @When /^I go to "([^"]*)?"$/
51
41
  */
52
- When(/^I go to "([^"]*)?"$/, function (url) {
42
+ When(/^(I|we)* go to "([^"]*)?"$/, function (pronoundCase, url) {
53
43
  return browser.url(browser.launch_url + url);
54
44
  });
55
45
 
@@ -60,23 +50,17 @@ When(/^I go to "([^"]*)?"$/, function (url) {
60
50
  * - Then I should see "Welcome"
61
51
  * - Then I should not see "Access denied"
62
52
  *
63
- * @Then /^I should( not)* see "([^"]*)?"$/
64
53
  */
65
- Then(/^I should( not)* see "([^"]*)?"$/, function (negativeCase, expectedText) {
66
- if (negativeCase) {
67
- return browser.assert.not.textContains('html', expectedText);
68
- }
69
-
70
- return browser.assert.textContains('html', expectedText);
54
+ Then(/^(I|we)* should( not)* see "([^"]*)?"$/, function (pronoundCase, negativeCase, expectedText) {
55
+ return browser.assert.elementContainsText(negativeCase, expectedText, "html");
71
56
  });
72
57
 
73
58
  /**
74
59
  * Moves forward one page in history
75
60
  * Example: When I move forward one page
76
61
  *
77
- * @When /^I move forward one page$/
78
62
  */
79
- When(/^I move forward one page$/, function () {
63
+ When(/^(I|we)* move forward one page$/, function (pronoundCase) {
80
64
  return browser.forward();
81
65
  });
82
66
 
@@ -84,9 +68,8 @@ When(/^I move forward one page$/, function () {
84
68
  * Moves backward one page in history
85
69
  * Example: When I move backward one page
86
70
  *
87
- * @When /^I move backward one page$/
88
71
  */
89
- When(/^I move backward one page$/, function () {
72
+ When(/^(I|we)* move backward one page$/, function (pronoundCase) {
90
73
  return browser.back();
91
74
  });
92
75
 
@@ -95,11 +78,9 @@ When(/^I move backward one page$/, function () {
95
78
  * Example: When I press "Log In"
96
79
  * Example: And I press "Log In"
97
80
  *
98
- * @When /^I press "([^"]*)?"$/
99
81
  */
100
- When(/^I press "([^"]*)?"$/, function (elementValue) {
101
- return browser.click("[value='" + elementValue + "']");
102
- // return browser.smartPressButton(elementValue);
82
+ When(/^(I|we)* press "([^"]*)?"$/, function (pronoundCase, elementValue) {
83
+ return browser.press(elementValue);
103
84
  });
104
85
 
105
86
  /**
@@ -107,10 +88,9 @@ When(/^I press "([^"]*)?"$/, function (elementValue) {
107
88
  * Example: When I click "Contact Us"
108
89
  * Example: And I click "aboutUs"
109
90
  *
110
- * @When /^I click "([^"]*)?"$/
111
91
  */
112
- When(/^I click "([^"]*)?"$/, function (item) {
113
- browser.smartClickLink(item);
92
+ When(/^(I|we)* click "([^"]*)?"$/, function (pronoundCase, item) {
93
+ browser.clickLink(item);
114
94
  });
115
95
 
116
96
  /**
@@ -118,9 +98,8 @@ When(/^I click "([^"]*)?"$/, function (item) {
118
98
  * Example: When I reload the page
119
99
  * Example: And I reload the page
120
100
  *
121
- * @When /^I reload( the)* page$/
122
101
  */
123
- When(/^I reload( the)* page$/, function (url) {
102
+ When(/^(I|we)* reload( the)* page$/, function (pronoundCase, theCase) {
124
103
  return browser.refresh(browser.getCurrentUrl());
125
104
  });
126
105
 
@@ -128,30 +107,27 @@ When(/^I reload( the)* page$/, function (url) {
128
107
  * Define the step of filling values in the form field specified by id|class|name|label.
129
108
  * Example: When I fill in "Username" with "John Smith"
130
109
  *
131
- * @When /^I fill in "([^"]*)?" with "([^"]*)?"$/
132
110
  */
133
- When(/^I fill in "([^"]*)?" with "([^"]*)?"$/, function (field, value) {
134
- browser.smartFillTextInput(field, value);
111
+ When(/^(I|we)* fill in "([^"]*)?" with "([^"]*)?"$/, function (pronoundCase, field, value) {
112
+ browser.fillTextInput(field, value);
135
113
  });
136
114
 
137
115
  /**
138
116
  * Fills in form field with specified id|class|name|label
139
117
  * Example: When I fill in "username" with:
140
118
  *
141
- * @When /^I fill in "([^"]*)?" with:$/
142
119
  */
143
- When(/^I fill in "([^"]*)?" with:$/, function (field) {
144
- browser.smartFillTextInput(field, '');
120
+ When(/^(I|we)* fill in "([^"]*)?" with:$/, function (pronoundCase, field) {
121
+ browser.fillTextInput(field, '');
145
122
  });
146
123
 
147
124
  /**
148
125
  * Fills in form field with specified id|class|name|label
149
126
  * Example: And I fill in "webshipco" for "username"
150
127
  *
151
- * @When /^I fill in "([^"]*)?" for "([^"]*)?"$/
152
128
  */
153
- When(/^I fill in "([^"]*)?" for "([^"]*)?"$/, function (value, field) {
154
- browser.smartFillTextInput(field, value);
129
+ When(/^(I|we)* fill in "([^"]*)?" for "([^"]*)?"$/, function (pronoundCase, value, field) {
130
+ browser.fillTextInput(field, value);
155
131
  });
156
132
 
157
133
  /**
@@ -163,13 +139,12 @@ When(/^I fill in "([^"]*)?" for "([^"]*)?"$/, function (value, field) {
163
139
  * | username | webshipco |
164
140
  * | password | 1234 |
165
141
  *
166
- * @When /^I fill in the following:$/
167
142
  */
168
- When(/^I fill in the following:$/, function (table) {
143
+ When(/^(I|we)* fill in the following:$/, function (pronoundCase, table) {
169
144
 
170
- browser.smartFillTextInput(table.rawTable[0][0], table.rawTable[0][1]);
145
+ browser.fillTextInput(table.rawTable[0][0], table.rawTable[0][1]);
171
146
  table.rows().forEach(row => {
172
- browser.smartFillTextInput(row[0], row[1]);
147
+ browser.fillTextInput(row[0], row[1]);
173
148
  });
174
149
  });
175
150
 
@@ -177,40 +152,36 @@ When(/^I fill in the following:$/, function (table) {
177
152
  * Selects option in select field with specified id|class|name|label
178
153
  * Example: When I select "mercedes" from "Cars"
179
154
  *
180
- * @When /^I select "([^"]*)?" from "([^"]*)?"$/
181
155
  */
182
- When(/^I select "([^"]*)?" from "([^"]*)?"$/, function (option, dropdownlist) {
183
- browser.smartSelectOption(option, dropdownlist);
156
+ When(/^(I|we)* select "([^"]*)?" from "([^"]*)?"$/, function (pronoundCase, option, dropdownlist) {
157
+ browser.selectOption(option, dropdownlist);
184
158
  });
185
159
 
186
160
  /**
187
161
  * Checks checkbox specified by id|class|name|label
188
162
  * Example: When I check "Remember me"
189
163
  *
190
- * @When /^I check "([^"]*)?"$/
191
164
  */
192
- When(/^I check "([^"]*)?"$/, function (item) {
193
- browser.smartCheckItem(item);
165
+ When(/^(I|we)* check "([^"]*)?"$/, function (pronoundCase, item) {
166
+ browser.checkItem(item);
194
167
  });
195
168
 
196
169
  /**
197
170
  * Unchecks checkbox specified by id|class|name|label
198
171
  * Example: When I uncheck "Remember me"
199
172
  *
200
- * @When /^I uncheck "([^"]*)?"$/
201
173
  */
202
- When(/^I uncheck "([^"]*)?"$/, function (item) {
203
- browser.smartUncheckItem(item);
174
+ When(/^(I|we)* uncheck "([^"]*)?"$/, function (pronoundCase, item) {
175
+ browser.uncheckItem(item);
204
176
  });
205
177
 
206
178
  /**
207
179
  * Verify, that current page is the homepage
208
180
  * Example: Then I should be on the homepage
209
181
  *
210
- * @Then /^I should be on( the)* homepage$/
211
182
  */
212
- Then(/^I should be on( the)* homepage$/, function (url) {
213
- return browser.assert.urlEquals(browser.launch_url);
183
+ Then(/^(I|we)* should( not)* be on( the)* homepage$/, function (pronoundCase, negativeCase, theCase) {
184
+ return browser.assert.backToHomepage(negativeCase);
214
185
  });
215
186
 
216
187
  /**
@@ -219,9 +190,8 @@ Then(/^I should be on( the)* homepage$/, function (url) {
219
190
  * Example: And I should be on "/user/login"
220
191
  * Example: And I should be on "http://google.com"
221
192
  *
222
- * @Then /^I should be on "([^"]*)?"$/
223
193
  */
224
- Then(/^I should be on "([^"]*)?"$/, function (url) {
194
+ Then(/^(I|we)* should be on "([^"]*)?"$/, function (pronoundCase, url) {
225
195
  return browser.assert.urlContains(url);
226
196
  });
227
197
 
@@ -230,14 +200,9 @@ Then(/^I should be on "([^"]*)?"$/, function (url) {
230
200
  * Example: Then the response should contain "Welcome visitor, How can I help you?"
231
201
  * Example: Then the response should not contain "Error: Ambiguous messages that are unclear"
232
202
  *
233
- * @Then /^the response should contain "([^"]*)?"$/
234
203
  */
235
204
  Then(/^the response should( not)* contain "([^"]*)?"$/, function (negativeCase, expectedText) {
236
- if (negativeCase) {
237
- return browser.assert.not.textContains('html', expectedText);
238
- }
239
-
240
- return browser.assert.textContains('html', expectedText);
205
+ return browser.assert.elementContainsText(negativeCase, expectedText, 'html');
241
206
  });
242
207
 
243
208
  /**
@@ -245,10 +210,9 @@ Then(/^the response should( not)* contain "([^"]*)?"$/, function (negativeCase,
245
210
  * Example: Then I should see "John Smith" in the "Username" element
246
211
  * Example: Then I should see "Joe Smith" in the "Username" element
247
212
  *
248
- * @Then /^I should( not)* see "([^"]*)?" in the "([^"]*)?" element$/
249
213
  */
250
- Then(/^I should( not)* see "([^"]*)?" in the "([^"]*)?" element$/, function (negativeCase, expectedText, element) {
251
- return browser.assert.smartElementContains(negativeCase, expectedText, element);
214
+ Then(/^(I|we)* should( not)* see "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, negativeCase, expectedText, element) {
215
+ return browser.assert.elementContainsText(negativeCase, expectedText, element);
252
216
  });
253
217
 
254
218
  /**
@@ -258,65 +222,55 @@ Then(/^I should( not)* see "([^"]*)?" in the "([^"]*)?" element$/, function (neg
258
222
  * Example: Then I should not see a "Username" element
259
223
  * Example: Then I should not see an "img" element
260
224
  *
261
- * @Then /^I should( not)* see a(n)* "([^"]*)?" element$/
262
225
  */
263
- Then(/^I should( not)* see a(n)* "([^"]*)?" element$/, function (negativeCase, identification, element) {
264
- if (negativeCase) {
265
- return browser.verify.not.visible(element);
266
- }
267
- return browser.verify.visible(element);
226
+ Then(/^(I|we)* should( not)* see a(n)* "([^"]*)?" element$/, function (pronoundCase, negativeCase, identification, element) {
227
+ return browser.assert.shouldVisible(negativeCase, element);
268
228
  });
269
229
 
270
230
  /**
271
231
  * Assert, that element contains a specific CSS style specified by id|class|name|label|tag.
272
232
  * Example: Then the "body" element should contain "color:white;"
273
233
  *
274
- * @Then /^the "([^"]*)?" element should( not)* contain "([^"]*)?"$/
275
234
  */
276
235
  Then(/^the "([^"]*)?" element should( not)* contain "([^"]*)?"$/, function (element, negativeCase, elementCss) {
277
- return browser.assert.smartElementContainsCss(element, negativeCase, elementCss);
236
+ return browser.assert.elementContainsCss(element, negativeCase, elementCss);
278
237
  });
279
238
 
280
239
  /**
281
240
  * Attaches file to field with specified id|class|name|label
282
241
  * Example: When I attach the file "profileIcon.jpg" to "profileIconUpload"
283
242
  *
284
- * @When /^I attach the file "([^"]*)?" to "([^"]*)?"$/
285
243
  */
286
- When(/^I attach the file "([^"]*)?" to "([^"]*)?"$/, function (fileUrl, element) {
287
- browser.smartUploadFile("../../../tests/assets/" + fileUrl, element);
244
+ When(/^(I|we)* attach the file "([^"]*)?" to "([^"]*)?"$/, function (pronoundCase, fileUrl, element) {
245
+ browser.fileUpload("../../../tests/assets/" + fileUrl, element);
288
246
  });
289
247
 
290
248
  /**
291
249
  * Assert, that form field with specified id|class|name|label has specified value
292
250
  * Example: Then the "username" field should contain "John Smith"
293
251
  *
294
- * @Then /^the "([^"]*)?" field should( not)* contain "([^"]*)?"$/
295
252
  */
296
253
  Then(/^the "([^"]*)?" field should( not)* contain "([^"]*)?"$/, function (field, negativeCase, expectedText) {
297
- return browser.assert.smartElementContains(negativeCase, expectedText, field);
254
+ return browser.assert.elementContainsText(negativeCase, expectedText, field);
298
255
  });
299
256
 
300
257
  /**
301
258
  * Assert, that checkbox with specified id|class|name|label is should be checked
302
259
  * Example: Then the "PrivacyPolicy" checkbox should be checked
303
- *
304
- * @Then /^the "([^"]*)?" checkbox should(not)* be checked$/
305
260
  *
306
261
  */
307
262
  Then(/^the "([^"]*)?" checkbox should( not)* be checked$/, function (checkbox, negativeCase) {
308
- return browser.assert.smartCheckboxChecked(checkbox, negativeCase);
263
+ return browser.assert.checkboxChecked(checkbox, negativeCase);
309
264
  });
310
265
 
311
266
  /**
312
267
  * Check, whether the checkbox specified by id|class|name|label is checked or not.
313
268
  * Example: Then the "Remember Me" checkbox is checked
314
269
  *
315
- * @Then /^the "([^"]*)?" checkbox is( not)* checked$/
316
270
  *
317
271
  */
318
272
  Then(/^the "([^"]*)?" checkbox is( not)* checked$/, function (checkbox, negativeCase) {
319
- return browser.assert.smartCheckboxChecked(checkbox, negativeCase);
273
+ return browser.assert.checkboxChecked(checkbox, negativeCase);
320
274
  });
321
275
 
322
276
  /**
@@ -324,11 +278,9 @@ Then(/^the "([^"]*)?" checkbox is( not)* checked$/, function (checkbox, negative
324
278
  * Example: Then the checkbox "PrivacyPolicy" should be checked
325
279
  * Example: Then the checkbox "PrivacyPolicy" should not be checked
326
280
  *
327
- * @Then /^the checkbox "([^"]*)?" should(not)* be checked$/
328
- *
329
281
  */
330
282
  Then(/^the checkbox "([^"]*)?" should( not)* be checked$/, function (checkbox, negativeCase) {
331
- return browser.assert.smartCheckboxChecked(checkbox, negativeCase);
283
+ return browser.assert.checkboxChecked(checkbox, negativeCase);
332
284
  });
333
285
 
334
286
  /**
@@ -336,11 +288,9 @@ Then(/^the checkbox "([^"]*)?" should( not)* be checked$/, function (checkbox, n
336
288
  * Example: Then the checkbox "Remember Me" is checked
337
289
  * Example: And the checkbox "Remember Me" is not checked
338
290
  *
339
- * @Then /^the checkbox "([^"]*)?" is( not)* checked$/
340
- *
341
291
  */
342
292
  Then(/^the checkbox "([^"]*)?" is( not)* checked$/, function (checkbox, negativeCase) {
343
- return browser.assert.smartCheckboxChecked(checkbox, negativeCase);
293
+ return browser.assert.checkboxChecked(checkbox, negativeCase);
344
294
  });
345
295
 
346
296
  /**
@@ -349,15 +299,9 @@ Then(/^the checkbox "([^"]*)?" is( not)* checked$/, function (checkbox, negative
349
299
  * Example: When I wait 5 seconds
350
300
  * Example: When I wait max of 6 seconds
351
301
  *
352
- * @When /^I wait( max of)* "([^"]*)?" second(s)*$/
353
- *
354
302
  */
355
- When(/^I wait( max of)* (\d*) second(s)*$/, function (maxof, number, withS) {
356
- var waitTime = number * 1000;
357
- if (maxof) {
358
- return browser.waitForElementPresent('body', waitTime);
359
- }
360
- return browser.pause(waitTime);
303
+ When(/^(I|we)* wait( max of)* (\d*) second(s)*$/, function (pronoundCase, maxof, number, withS) {
304
+ return browser.wait(maxof, number, "s");
361
305
  });
362
306
 
363
307
  /**
@@ -366,15 +310,9 @@ When(/^I wait( max of)* (\d*) second(s)*$/, function (maxof, number, withS) {
366
310
  * Example: When I wait 5 minutes
367
311
  * Example: When I wait max of 6 minutes
368
312
  *
369
- * @When /^I wait( max of)* "([^"]*)?" minute(s)*$/
370
- *
371
313
  */
372
- When(/^I wait( max of)* (\d*) minute(s)*$/, function (maxof, number, withS) {
373
- var waitTime = number * 60 * 1000;
374
- if (maxof) {
375
- return browser.waitForElementPresent('body', waitTime);
376
- }
377
- return browser.pause(waitTime);
314
+ When(/^(I|we)* wait( max of)* (\d*) minute(s)*$/, function (pronoundCase, maxof, number, withS) {
315
+ return browser.wait(maxof, number, "m");
378
316
  });
379
317
 
380
318
  /**
@@ -382,29 +320,18 @@ When(/^I wait( max of)* (\d*) minute(s)*$/, function (maxof, number, withS) {
382
320
  * Example: Then the response status code should be 200
383
321
  * Example: And the response status code should not be 404
384
322
  *
385
- * @Then /^the response status code should( not)* be (?P<code>\d+)$/
386
323
  */
387
324
  Then(/^the response status code should( not)* be (\d+)$/, function (negativeCase, expectedStatusCode) {
388
-
389
- browser.url(function (currentURL) {
390
- request(currentURL.value, (error, response, body) => {
391
- if (negativeCase) {
392
- return browser.assert.not.equal(response.statusCode, expectedStatusCode).end();
393
- }
394
- return browser.assert.equal(response.statusCode, expectedStatusCode).end();
395
-
396
- });
397
- });
325
+ return browser.assert.responseStatus(negativeCase, expectedStatusCode);
398
326
  });
399
327
 
400
328
  /**
401
329
  * Checks, that page contains text matching specified pattern
402
330
  * Example: Then I should see text matching "^T\w+" //pattern of word start with 'T'
403
331
  *
404
- * @Then /^I should see( not)* text matching "([^"]*)?" in the "([^"]*)?" element$/
405
332
  */
406
- Then(/^I should( not)* see text matching "([^"]*)?"$/, function (negativeCase, textPattern) {
407
- // return browser.assert.smartTextMatching(negativeCase, textPattern);
333
+ Then(/^(I|we)* should( not)* see text matching "([^"]*)?"$/, function (pronoundCase, negativeCase, textPattern) {
334
+ // return browser.assert.textMatching(negativeCase, textPattern);
408
335
  browser.elements('css selector', 'body', function (elements) {
409
336
  elements.value.forEach(function (elementsObj) {
410
337
  if (negativeCase) {
@@ -419,9 +346,8 @@ Then(/^I should( not)* see text matching "([^"]*)?"$/, function (negativeCase, t
419
346
  * Checks, that page contains text matching specified pattern
420
347
  * Example: Then I should see text matching "(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}" in the "#date" element //pattern of DD/MM/YYYY or DD-MM-YYYY
421
348
  *
422
- * @Then /^I should see( not)* text matching "([^"]*)?" in the "([^"]*)?" element$/
423
349
  */
424
- Then(/^I should( not)* see text matching "([^"]*)?" in the "([^"]*)?" element$/, function (negativeCase, textPattern, element) {
350
+ Then(/^(I|we)* should( not)* see text matching "([^"]*)?" in the "([^"]*)?" element$/, function (pronoundCase, negativeCase, textPattern, element) {
425
351
  browser.elements('css selector', element, function (elements) {
426
352
  elements.value.forEach(function (elementsObj) {
427
353
  if (negativeCase) {
@@ -430,4 +356,19 @@ Then(/^I should( not)* see text matching "([^"]*)?" in the "([^"]*)?" element$/,
430
356
  return browser.assert.textMatches(elementsObj, textPattern);
431
357
  });
432
358
  });
359
+ });
360
+
361
+
362
+ /**
363
+ * Checks, that current URL Path matches regular expression
364
+ * Example: Then the url should match "/contact-us.html"
365
+ *
366
+ */
367
+ Then(/^the url should( not)* match "([^"]*)?"$/, function (negativeCase, pattern) {
368
+
369
+ if (negativeCase) {
370
+ return browser.assert.not.urlMatches(pattern);
371
+ }
372
+ return browser.assert.urlMatches(pattern);
373
+
433
374
  });
@@ -1,12 +0,0 @@
1
-
2
- module.exports.command = function (elementValue) {
3
-
4
- browser.element('css selector', elementValue, function (result) {
5
- if (result.status === 0) {
6
- return browser.click(elementValue);
7
- }
8
- else {
9
- return browser.click("[value='" + elementValue + "']");
10
- }
11
- });
12
- }