webship-js 2.0.7 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/global-settings.md +1 -1
- package/docs/step-definitions/given-i-am-specific-page.md +4 -0
- package/docs/step-definitions/when-i-go-specific-page.md +4 -0
- package/package.json +1 -1
- package/tests/features/absolute-url.feature +51 -0
- package/tests/step-definitions/file-download.steps.js +2 -2
- package/tests/step-definitions/navigation.steps.js +8 -5
- package/tests/step-definitions/rest.steps.js +3 -2
- package/tests/step-definitions/webship.js +16 -0
package/docs/global-settings.md
CHANGED
|
@@ -42,7 +42,7 @@ on the command line).
|
|
|
42
42
|
| --- | --- | --- |
|
|
43
43
|
| string | `http://localhost:8080` | `LAUNCH_URL` |
|
|
44
44
|
|
|
45
|
-
Base URL prepended to every relative path in `Given I am on "/path"`.
|
|
45
|
+
Base URL prepended to every relative path in `Given I am on "/path"`. An absolute `http://` or `https://` URL is opened as written.
|
|
46
46
|
|
|
47
47
|
### `assetsFolder`
|
|
48
48
|
|
|
@@ -25,8 +25,12 @@ Given we are on the "/about-us" page
|
|
|
25
25
|
Given on "/about-us"
|
|
26
26
|
|
|
27
27
|
Given on the "/about-us" page
|
|
28
|
+
|
|
29
|
+
Given I am on "https://un.org"
|
|
28
30
|
```
|
|
29
31
|
|
|
32
|
+
A path is opened under the `launchUrl`; an absolute `http://` or `https://` URL is opened as written.
|
|
33
|
+
|
|
30
34
|
## Key Information
|
|
31
35
|
|
|
32
36
|
This step definition is part of the Webship JS 2.0.x documentation's Step Definitions section. It supports flexible phrasing patterns, allowing users to specify page locations using various grammatical structures. The pattern accepts optional articles ("the") and the word "page," accommodating different natural language preferences while directing the test to navigate to the specified URL or page identifier.
|
|
@@ -27,8 +27,12 @@ When navigating to "/products"
|
|
|
27
27
|
When we go to "/products"
|
|
28
28
|
|
|
29
29
|
When we navigate to "/terms"
|
|
30
|
+
|
|
31
|
+
When I go to "https://un.org"
|
|
30
32
|
```
|
|
31
33
|
|
|
34
|
+
A path is opened under the `launchUrl`; an absolute `http://` or `https://` URL is opened as written.
|
|
35
|
+
|
|
32
36
|
## Key Details
|
|
33
37
|
|
|
34
38
|
This step accepts flexible phrasing with multiple variations including "go," "navigate," and collective pronouns ("we"). The page identifier is captured as a parameter in quotation marks and can represent either a page name or a complete URL path.
|
package/package.json
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Feature: Steps that take a URL accept a path or an absolute URL
|
|
2
|
+
As a tester,
|
|
3
|
+
I want a step given "/page" to open it under the launch URL,
|
|
4
|
+
and a step given "http://host/page" to open that URL as written,
|
|
5
|
+
so that a scenario can leave the site under test and come back.
|
|
6
|
+
|
|
7
|
+
Scenario: A path is joined to the launch URL
|
|
8
|
+
Given I am on "/about-us.html"
|
|
9
|
+
Then the path should be "/about-us.html"
|
|
10
|
+
And I should see "About Us"
|
|
11
|
+
|
|
12
|
+
Scenario: An absolute URL is opened as written
|
|
13
|
+
Given I am on "http://localhost:8080/contact-us.html"
|
|
14
|
+
Then the path should be "/contact-us.html"
|
|
15
|
+
And I should see "Contact Us"
|
|
16
|
+
|
|
17
|
+
Scenario: An absolute URL is opened as written, with the page phrasing
|
|
18
|
+
Given I am on the "http://localhost:8080/path.html?lang=en" page
|
|
19
|
+
Then the path should be "/path.html"
|
|
20
|
+
And current url should have the "lang" parameter with the "en" value
|
|
21
|
+
|
|
22
|
+
Scenario: Go to a path, then to an absolute URL
|
|
23
|
+
Given I am on the homepage
|
|
24
|
+
When I go to "/about-us.html"
|
|
25
|
+
Then the path should be "/about-us.html"
|
|
26
|
+
When I navigate to "http://localhost:8080/contact-us.html"
|
|
27
|
+
Then the path should be "/contact-us.html"
|
|
28
|
+
And I should see "Contact Us"
|
|
29
|
+
|
|
30
|
+
Scenario: Go to an absolute URL with the other phrasings
|
|
31
|
+
Given I am on the homepage
|
|
32
|
+
When we go to "http://localhost:8080/path.html"
|
|
33
|
+
Then the path should be "/path.html"
|
|
34
|
+
When navigating to "http://localhost:8080/element.html"
|
|
35
|
+
Then the path should be "/element.html"
|
|
36
|
+
|
|
37
|
+
Scenario: An absolute URL is case-insensitive in its scheme
|
|
38
|
+
Given I am on "HTTP://localhost:8080/path.html"
|
|
39
|
+
Then the path should be "/path.html"
|
|
40
|
+
|
|
41
|
+
Scenario: A REST request takes a path or an absolute URL
|
|
42
|
+
When I send a REST "GET" request to "/example-api.json"
|
|
43
|
+
Then the REST response status code should be 200
|
|
44
|
+
When I send a REST "GET" request to "http://localhost:8080/example-api.json"
|
|
45
|
+
Then the REST response status code should be 200
|
|
46
|
+
|
|
47
|
+
Scenario: A download takes a path or an absolute URL
|
|
48
|
+
When I download the file from the URL "/example-api.json"
|
|
49
|
+
Then the downloaded file name should be "example-api.json"
|
|
50
|
+
When I download the file from the URL "http://localhost:8080/example-api.json"
|
|
51
|
+
Then the downloaded file name should be "example-api.json"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { friendly } = require('./webship');
|
|
3
|
+
const { friendly, resolveUrl } = require('./webship');
|
|
4
4
|
|
|
5
5
|
// Validate file downloads triggered via URL or link click.
|
|
6
6
|
|
|
@@ -31,7 +31,7 @@ function tmpDownloadDir() {
|
|
|
31
31
|
*
|
|
32
32
|
*/
|
|
33
33
|
When(/^(I |we )*download the file from the URL "([^"]*)"$/, async function (pronoun, url) {
|
|
34
|
-
const target =
|
|
34
|
+
const target = resolveUrl(this.launchUrl, url);
|
|
35
35
|
try {
|
|
36
36
|
const resp = await this.page.request.get(target);
|
|
37
37
|
assert.strictEqual(resp.status(), 200, `Download failed with status ${resp.status()}.`);
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
8
8
|
const assert = require('assert');
|
|
9
|
-
const { gotoUrl, waitForPageLoad, smartSettle } = require('./webship');
|
|
9
|
+
const { gotoUrl, resolveUrl, waitForPageLoad, smartSettle } = require('./webship');
|
|
10
10
|
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
// Sessions / visits
|
|
@@ -49,7 +49,8 @@ Given(/^(I am |we are )?on( the)* (homepage|frontpage)$/, async function (pronou
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
* Open a specific page under the launch URL
|
|
52
|
+
* Open a specific page: a path is opened under the launch URL, an absolute
|
|
53
|
+
* `http://` or `https://` URL is opened as written.
|
|
53
54
|
*
|
|
54
55
|
* Example #1: Given I am on "/about-us.html"
|
|
55
56
|
* Example #2: Given I am on the "/about-us.html" page
|
|
@@ -61,7 +62,7 @@ Given(/^(I am |we are )?on( the)* (homepage|frontpage)$/, async function (pronou
|
|
|
61
62
|
*
|
|
62
63
|
*/
|
|
63
64
|
Given(/^(I am |we are )*on( the)* "([^"]*)?"( page)*$/, async function (pronounCase, theCase, url, pageCase) {
|
|
64
|
-
await gotoUrl(this.page, this.launchUrl
|
|
65
|
+
await gotoUrl(this.page, resolveUrl(this.launchUrl, url));
|
|
65
66
|
await this.page.waitForSelector('body', { state: 'attached', timeout: 10000 });
|
|
66
67
|
await waitForPageLoad(this.page);
|
|
67
68
|
});
|
|
@@ -87,7 +88,8 @@ When(/^(I go |I navigate |we go |we navigate |navigating )?to( the)* (homepage|f
|
|
|
87
88
|
});
|
|
88
89
|
|
|
89
90
|
/**
|
|
90
|
-
* Navigate to a specific page
|
|
91
|
+
* Navigate to a specific page: a path is opened under the launch URL, an
|
|
92
|
+
* absolute `http://` or `https://` URL is opened as written.
|
|
91
93
|
*
|
|
92
94
|
* Example #1: When I go to "/contact-us.html"
|
|
93
95
|
* Example #2: When I go to "/user/login"
|
|
@@ -95,11 +97,12 @@ When(/^(I go |I navigate |we go |we navigate |navigating )?to( the)* (homepage|f
|
|
|
95
97
|
* Example #4: When navigating to "/products"
|
|
96
98
|
* Example #5: When we go to "/products"
|
|
97
99
|
* Example #6: When we navigate to "/terms"
|
|
100
|
+
* Example #7: When I go to "https://un.org"
|
|
98
101
|
*
|
|
99
102
|
*/
|
|
100
103
|
When(/^(I go |I navigate |we go |we navigate |navigating )?to "([^"]*)?"$/, async function (pronounCase, url) {
|
|
101
104
|
const defaultTime = this.minWaitTime.page || 3000;
|
|
102
|
-
await gotoUrl(this.page, this.launchUrl
|
|
105
|
+
await gotoUrl(this.page, resolveUrl(this.launchUrl, url));
|
|
103
106
|
await this.page.waitForSelector('body', { state: 'attached', timeout: defaultTime });
|
|
104
107
|
await waitForPageLoad(this.page, defaultTime);
|
|
105
108
|
});
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
const { Given, When, Then } = require('@cucumber/cucumber');
|
|
7
7
|
const assert = require('assert');
|
|
8
8
|
const axios = require('axios');
|
|
9
|
+
const { resolveUrl } = require('./webship');
|
|
9
10
|
|
|
10
11
|
function ensureState(world) {
|
|
11
12
|
if (!world._rest) world._rest = { headers: {}, response: null };
|
|
@@ -38,7 +39,7 @@ Given('a REST header {string} with value {string}', async function (name, value)
|
|
|
38
39
|
*/
|
|
39
40
|
When(/^(I |we )*send a REST "([^"]*)" request to "([^"]*)"$/, async function (pronoun, method, url) {
|
|
40
41
|
const s = ensureState(this);
|
|
41
|
-
const target =
|
|
42
|
+
const target = resolveUrl(this.launchUrl, url);
|
|
42
43
|
s.response = await axios.request({
|
|
43
44
|
method, url: target, headers: s.headers, validateStatus: () => true,
|
|
44
45
|
});
|
|
@@ -71,7 +72,7 @@ When(/^(I |we )*send a REST "([^"]*)" request to "([^"]*)"$/, async function (pr
|
|
|
71
72
|
*/
|
|
72
73
|
When(/^(I |we )*send a REST "([^"]*)" request to "([^"]*)" with body:$/, async function (pronoun, method, url, body) {
|
|
73
74
|
const s = ensureState(this);
|
|
74
|
-
const target =
|
|
75
|
+
const target = resolveUrl(this.launchUrl, url);
|
|
75
76
|
s.response = await axios.request({
|
|
76
77
|
method, url: target, headers: s.headers, data: body, validateStatus: () => true,
|
|
77
78
|
});
|
|
@@ -293,6 +293,21 @@ function buildSelector(attrValue, attr) {
|
|
|
293
293
|
// empty-response edge cases so a redirect to about:blank or a 204 does
|
|
294
294
|
// not crash the suite. All other failures rethrow with extra context
|
|
295
295
|
// (URL + likely cause).
|
|
296
|
+
/**
|
|
297
|
+
* Resolve the value a step was given into the URL to request: an absolute
|
|
298
|
+
* `http://` or `https://` URL is returned as written, anything else is a
|
|
299
|
+
* path and is appended to the launch URL.
|
|
300
|
+
*
|
|
301
|
+
* @param {string} launchUrl
|
|
302
|
+
* @param {string} url
|
|
303
|
+
* @returns {string}
|
|
304
|
+
*/
|
|
305
|
+
function resolveUrl(launchUrl, url) {
|
|
306
|
+
const value = url === undefined || url === null ? '' : String(url);
|
|
307
|
+
if (/^https?:\/\//i.test(value)) return value;
|
|
308
|
+
return (launchUrl || '') + value;
|
|
309
|
+
}
|
|
310
|
+
|
|
296
311
|
/**
|
|
297
312
|
* Navigate to a URL with friendly error messages for common failures
|
|
298
313
|
* (server down, DNS, empty response). All other errors rethrow with
|
|
@@ -613,6 +628,7 @@ module.exports = {
|
|
|
613
628
|
isAnyModalVisible,
|
|
614
629
|
buildSelector,
|
|
615
630
|
gotoUrl,
|
|
631
|
+
resolveUrl,
|
|
616
632
|
fillField,
|
|
617
633
|
getLocatorText,
|
|
618
634
|
pad,
|