webship-js 1.0.44 → 1.0.45
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/package.json
CHANGED
|
@@ -74,9 +74,9 @@ function getNestedProperty(obj, path) {
|
|
|
74
74
|
* Adds Basic Authentication header to next request.
|
|
75
75
|
*
|
|
76
76
|
* Example #1: Given I am authenticating as "admin" with "password123" password
|
|
77
|
-
* Example #2: Given
|
|
77
|
+
* Example #2: Given We are authenticating as "user@example.com" with "secret" password
|
|
78
78
|
*/
|
|
79
|
-
Given(/^I am authenticating as "([^"]*)" with "([^"]*)" password$/, function (username, password) {
|
|
79
|
+
Given(/^(?:I am|we are) authenticating as "([^"]*)" with "([^"]*)" password$/, function (username, password) {
|
|
80
80
|
delete apiHeaders['Authorization'];
|
|
81
81
|
authorization = Buffer.from(username + ':' + password).toString('base64');
|
|
82
82
|
apiHeaders['Authorization'] = 'Basic ' + authorization;
|
|
@@ -89,7 +89,7 @@ Given(/^I am authenticating as "([^"]*)" with "([^"]*)" password$/, function (us
|
|
|
89
89
|
* Example #2: Given I set header "Authorization" with value "Bearer token123"
|
|
90
90
|
* Example #3: Given I set header "Accept" with value "application/xml"
|
|
91
91
|
*/
|
|
92
|
-
Given(/^I set header "([^"]*)" with value "([^"]*)"$/, function (name, value) {
|
|
92
|
+
Given(/^(?:I |we )?set header "([^"]*)" with value "([^"]*)"$/, function (name, value) {
|
|
93
93
|
apiHeaders[name] = replacePlaceHolder(value);
|
|
94
94
|
});
|
|
95
95
|
|
|
@@ -101,7 +101,16 @@ Given(/^I set header "([^"]*)" with value "([^"]*)"$/, function (name, value) {
|
|
|
101
101
|
* Example #3: Given the base URL is "http://localhost:3000/api"
|
|
102
102
|
*/
|
|
103
103
|
Given(/^(?:the API base URL is|I set the API base URL to|the base URL is) "([^"]*)"$/, function (url) {
|
|
104
|
-
|
|
104
|
+
// Check if the input is a full URL (contains protocol)
|
|
105
|
+
if (url.match(/^https?:\/\//)) {
|
|
106
|
+
baseURL = url.replace(/\/$/, ''); // Remove trailing slash
|
|
107
|
+
} else {
|
|
108
|
+
// If not a full URL, combine with launch_url from nightwatch.conf.js
|
|
109
|
+
const nightwatchConfig = require('../../nightwatch.conf.js');
|
|
110
|
+
const launchUrl = nightwatchConfig.test_settings.default.launch_url;
|
|
111
|
+
baseURL = (launchUrl + '/' + url).replace(/\/+/g, '/').replace(/\/$/, ''); // Normalize slashes and remove trailing slash
|
|
112
|
+
baseURL = baseURL.replace(':/', '://'); // Fix protocol separator
|
|
113
|
+
}
|
|
105
114
|
});
|
|
106
115
|
|
|
107
116
|
/**
|
|
@@ -111,7 +120,7 @@ Given(/^(?:the API base URL is|I set the API base URL to|the base URL is) "([^"]
|
|
|
111
120
|
* Example #2: Given I set the header "Authorization" to "Bearer token123"
|
|
112
121
|
* Example #3: Given the header "Accept" is "application/json"
|
|
113
122
|
*/
|
|
114
|
-
Given(/^(?:I set the header|the header) "([^"]*)" (?:to|is) "([^"]*)"$/, function (headerName, headerValue) {
|
|
123
|
+
Given(/^(?:I set the header|we set the header|the header) "([^"]*)" (?:to|is) "([^"]*)"$/, function (headerName, headerValue) {
|
|
115
124
|
apiHeaders[headerName] = replacePlaceHolder(headerValue);
|
|
116
125
|
});
|
|
117
126
|
|
|
@@ -123,7 +132,7 @@ Given(/^(?:I set the header|the header) "([^"]*)" (?:to|is) "([^"]*)"$/, functio
|
|
|
123
132
|
* | Authorization | Bearer token123 |
|
|
124
133
|
* | Accept | application/json |
|
|
125
134
|
*/
|
|
126
|
-
Given(/^I set the following headers:$/, function (table) {
|
|
135
|
+
Given(/^(?:I|we) set the following headers:$/, function (table) {
|
|
127
136
|
table.rows().forEach(row => {
|
|
128
137
|
apiHeaders[row[0]] = replacePlaceHolder(row[1]);
|
|
129
138
|
});
|
|
@@ -135,7 +144,7 @@ Given(/^I set the following headers:$/, function (table) {
|
|
|
135
144
|
* Example #1: Given I set the request body to '{"name": "John", "email": "john@example.com"}'
|
|
136
145
|
* Example #2: Given the request body is '{"title": "Test Post", "body": "This is a test"}'
|
|
137
146
|
*/
|
|
138
|
-
Given(/^(?:I set the request body to|the request body is) '([^']*)'$/, function (jsonData) {
|
|
147
|
+
Given(/^(?:I set the request body to|we set the request body to|the request body is) '([^']*)'$/, function (jsonData) {
|
|
139
148
|
try {
|
|
140
149
|
const processedData = replacePlaceHolder(jsonData);
|
|
141
150
|
apiRequestData = JSON.parse(processedData);
|
|
@@ -152,7 +161,7 @@ Given(/^(?:I set the request body to|the request body is) '([^']*)'$/, function
|
|
|
152
161
|
* | email | john@example.com |
|
|
153
162
|
* | age | 30 |
|
|
154
163
|
*/
|
|
155
|
-
Given(/^I set the request body with:$/, function (table) {
|
|
164
|
+
Given(/^(?:I|we) set the request body with:$/, function (table) {
|
|
156
165
|
apiRequestData = {};
|
|
157
166
|
table.rows().forEach(row => {
|
|
158
167
|
let value = replacePlaceHolder(row[1]);
|
|
@@ -170,11 +179,11 @@ Given(/^I set the request body with:$/, function (table) {
|
|
|
170
179
|
* Sends HTTP request to specific relative URL.
|
|
171
180
|
*
|
|
172
181
|
* Example #1: When I send a GET request to "/users"
|
|
173
|
-
* Example #2: When
|
|
182
|
+
* Example #2: When we send a POST request to "/posts"
|
|
174
183
|
* Example #3: When I send a PUT request to "/users/1"
|
|
175
|
-
* Example #4: When
|
|
184
|
+
* Example #4: When we send a DELETE request to "/posts/1"
|
|
176
185
|
*/
|
|
177
|
-
When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)"$/, async function (method, endpoint) {
|
|
186
|
+
When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)"$/, async function (method, endpoint) {
|
|
178
187
|
const url = baseURL + '/' + prepareUrl(endpoint);
|
|
179
188
|
|
|
180
189
|
try {
|
|
@@ -196,11 +205,12 @@ When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)"$/, async function (method, en
|
|
|
196
205
|
* Sends HTTP request to specific URL with field values from Table.
|
|
197
206
|
*
|
|
198
207
|
* Example: When I send a POST request to "/users" with values:
|
|
208
|
+
* When we send a POST request to "/users" with values:
|
|
199
209
|
* | name | John Doe |
|
|
200
210
|
* | email | john@example.com |
|
|
201
211
|
* | age | 30 |
|
|
202
212
|
*/
|
|
203
|
-
When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with values:$/, async function (method, endpoint, table) {
|
|
213
|
+
When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with values:$/, async function (method, endpoint, table) {
|
|
204
214
|
const url = baseURL + '/' + prepareUrl(endpoint);
|
|
205
215
|
const fields = {};
|
|
206
216
|
|
|
@@ -228,6 +238,7 @@ When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with values:$/, async functio
|
|
|
228
238
|
* Sends HTTP request to specific URL with raw body from PyString.
|
|
229
239
|
*
|
|
230
240
|
* Example: When I send a POST request to "/users" with body:
|
|
241
|
+
* When we send a POST request to "/users" with body:
|
|
231
242
|
* """
|
|
232
243
|
* {
|
|
233
244
|
* "name": "John Doe",
|
|
@@ -235,7 +246,7 @@ When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with values:$/, async functio
|
|
|
235
246
|
* }
|
|
236
247
|
* """
|
|
237
248
|
*/
|
|
238
|
-
When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with body:$/, async function (method, endpoint, docString) {
|
|
249
|
+
When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with body:$/, async function (method, endpoint, docString) {
|
|
239
250
|
const url = baseURL + '/' + prepareUrl(endpoint);
|
|
240
251
|
const body = replacePlaceHolder(docString.trim());
|
|
241
252
|
|
|
@@ -276,13 +287,14 @@ When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with body:$/, async function
|
|
|
276
287
|
* Sends HTTP request to specific URL with form data.
|
|
277
288
|
*
|
|
278
289
|
* Example: When I send a POST request to "/login" with form data:
|
|
290
|
+
* When we send a POST request to "/login" with form data:
|
|
279
291
|
* """
|
|
280
292
|
* username=admin
|
|
281
293
|
* password=secret
|
|
282
294
|
* remember=true
|
|
283
295
|
* """
|
|
284
296
|
*/
|
|
285
|
-
When(/^(?:I )?send a ([A-Z]+) request to "([^"]+)" with form data:$/, async function (method, endpoint, docString) {
|
|
297
|
+
When(/^(?:I |we )?send a ([A-Z]+) request to "([^"]+)" with form data:$/, async function (method, endpoint, docString) {
|
|
286
298
|
const url = baseURL + '/' + prepareUrl(endpoint);
|
|
287
299
|
const body = replacePlaceHolder(docString.trim());
|
|
288
300
|
|
|
@@ -530,6 +542,6 @@ Then(/^print API response$/, function () {
|
|
|
530
542
|
*
|
|
531
543
|
* Example: Given I set placeholder "{{userId}}" to "123"
|
|
532
544
|
*/
|
|
533
|
-
Given(/^I set placeholder "([^"]*)" to "([^"]*)"$/, function (placeholder, value) {
|
|
545
|
+
Given(/^(?:I|we) set placeholder "([^"]*)" to "([^"]*)"$/, function (placeholder, value) {
|
|
534
546
|
placeHolders[placeholder] = value;
|
|
535
547
|
});
|
|
@@ -14,8 +14,8 @@ const path = require('path');
|
|
|
14
14
|
* @param {string} key
|
|
15
15
|
*/
|
|
16
16
|
function safePause(key) {
|
|
17
|
-
const time = (global.browser
|
|
18
|
-
if (time > 0 && global.browser
|
|
17
|
+
const time = (global.browser && global.browser.globals && global.browser.globals.minimum_wait_time && global.browser.globals.minimum_wait_time[key]) || 0;
|
|
18
|
+
if (time > 0 && global.browser && global.browser.pause) {
|
|
19
19
|
global.browser.pause(time);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -265,71 +265,80 @@ When(/^(I |we )*click "([^"]*)?" by( its)*( "([^"]*)?")* (attribute|attr)$/, fun
|
|
|
265
265
|
*/
|
|
266
266
|
When(/^(I |we )*click "([^"]*)?" in( the)* "([^"]*)?" row$/, function (pronounCase, clickText, theCase, rowIdentifier) {
|
|
267
267
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
return browser.execute(function(rowId, targetText) {
|
|
269
|
+
// Find all tables on the page
|
|
270
|
+
const tables = document.querySelectorAll('table');
|
|
271
|
+
if (tables.length === 0) {
|
|
271
272
|
throw new Error('No tables found on the page');
|
|
272
273
|
}
|
|
273
274
|
|
|
274
275
|
// Search through each table for the row containing the identifier
|
|
275
|
-
let
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if (rowText.value && rowText.value.includes(rowIdentifier)) {
|
|
290
|
-
|
|
291
|
-
// Found the correct row, now look for the clickable text within this row
|
|
292
|
-
browser.elements('css selector', '*', row, function (cellElements) {
|
|
293
|
-
cellElements.value.forEach(function (element) {
|
|
294
|
-
if (foundElement) return; // Skip if already found
|
|
295
|
-
|
|
296
|
-
browser.getText(element, function (elementText) {
|
|
297
|
-
if (elementText.value && elementText.value.trim() === clickText) {
|
|
298
|
-
// Found the target text, click it
|
|
299
|
-
browser.click(element);
|
|
300
|
-
foundElement = true;
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
// Also check if element is a link or button with the text
|
|
306
|
-
browser.getAttribute(element, 'tagName', function (tagName) {
|
|
307
|
-
if (foundElement) return;
|
|
308
|
-
|
|
309
|
-
if (tagName.value && (tagName.value.toLowerCase() === 'a' || tagName.value.toLowerCase() === 'button')) {
|
|
310
|
-
browser.getText(element, function (linkText) {
|
|
311
|
-
if (linkText.value && linkText.value.trim() === clickText) {
|
|
312
|
-
browser.click(element);
|
|
313
|
-
foundElement = true;
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
});
|
|
276
|
+
for (let table of tables) {
|
|
277
|
+
const rows = table.querySelectorAll('tr');
|
|
278
|
+
for (let row of rows) {
|
|
279
|
+
const rowText = row.textContent || row.innerText;
|
|
280
|
+
if (rowText.includes(rowId)) {
|
|
281
|
+
// Found the correct row, now look for clickable elements with the target text
|
|
282
|
+
|
|
283
|
+
// First, try to find exact text matches in clickable elements
|
|
284
|
+
const clickableElements = row.querySelectorAll('a, button, [onclick], [role="button"], .btn, input[type="submit"], input[type="button"]');
|
|
285
|
+
for (let element of clickableElements) {
|
|
286
|
+
const elementText = (element.textContent || element.innerText || element.value || '').trim();
|
|
287
|
+
if (elementText === targetText) {
|
|
288
|
+
element.click();
|
|
289
|
+
return { success: true, element: element.tagName };
|
|
321
290
|
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// If not found in obvious clickable elements, search all elements
|
|
294
|
+
const allElements = row.querySelectorAll('*');
|
|
295
|
+
for (let element of allElements) {
|
|
296
|
+
const elementText = (element.textContent || element.innerText || '').trim();
|
|
297
|
+
if (elementText === targetText) {
|
|
298
|
+
// Check if element or parent is clickable
|
|
299
|
+
let clickableParent = element;
|
|
300
|
+
while (clickableParent && clickableParent !== row) {
|
|
301
|
+
if (clickableParent.tagName === 'A' ||
|
|
302
|
+
clickableParent.tagName === 'BUTTON' ||
|
|
303
|
+
clickableParent.onclick ||
|
|
304
|
+
clickableParent.getAttribute('role') === 'button' ||
|
|
305
|
+
clickableParent.classList.contains('btn') ||
|
|
306
|
+
clickableParent.style.cursor === 'pointer') {
|
|
307
|
+
clickableParent.click();
|
|
308
|
+
return { success: true, element: clickableParent.tagName };
|
|
309
|
+
}
|
|
310
|
+
clickableParent = clickableParent.parentElement;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// If no clickable parent found, try clicking the element itself
|
|
314
|
+
try {
|
|
315
|
+
element.click();
|
|
316
|
+
return { success: true, element: element.tagName };
|
|
317
|
+
} catch (e) {
|
|
318
|
+
// Continue searching if click failed
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Row found but target text not clickable
|
|
325
|
+
return {
|
|
326
|
+
success: false,
|
|
327
|
+
error: `Found row containing "${rowId}" but could not find clickable "${targetText}" within it. Row contains: ${rowText.substring(0, 200)}...`
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Row not found
|
|
334
|
+
return {
|
|
335
|
+
success: false,
|
|
336
|
+
error: `Could not find row containing "${rowId}". Available rows: ${Array.from(document.querySelectorAll('table tr')).map(r => (r.textContent || '').substring(0, 50)).join(', ')}`
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
}, [rowIdentifier, clickText], function(result) {
|
|
340
|
+
if (!result.value.success) {
|
|
341
|
+
throw new Error(result.value.error || `Could not find "${clickText}" in the "${rowIdentifier}" row. Please verify the table structure and text content.`);
|
|
333
342
|
}
|
|
334
343
|
});
|
|
335
344
|
});
|