Skip to content

Commit

Permalink
fix: add grabTrafficUrl back
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Mar 18, 2024
1 parent aaaf634 commit 036b979
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/helpers/Playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,19 @@ let title = await I.grabTitle();

Returns **[Promise][22]<[string][9]>** title

### grabTrafficUrl

Returns full URL of request matching parameter "urlMatch".

#### Parameters

- `urlMatch` **([string][9] | [RegExp][11])** Expected URL of request in network traffic. Can be a string or a regular expression.Examples:```js
I.grabTrafficUrl('https://api.example.com/session');
I.grabTrafficUrl(/session.*start/);
```
Returns **[Promise][22]<any>**
### grabValueFrom
Retrieves a value from a form element located by CSS or XPath and returns it to test.
Expand Down
33 changes: 33 additions & 0 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -3102,6 +3102,39 @@ class Playwright extends Helper {
stopRecordingTraffic.call(this);
}

/**
* Returns full URL of request matching parameter "urlMatch".
*
* @param {string|RegExp} urlMatch Expected URL of request in network traffic. Can be a string or a regular expression.
*
* Examples:
*
* ```js
* I.grabTrafficUrl('https://api.example.com/session');
* I.grabTrafficUrl(/session.*start/);
* ```
*
* @return {Promise<*>}
*/
grabTrafficUrl(urlMatch) {
if (!this.recordedAtLeastOnce) {
throw new Error('Failure in test automation. You use "I.grabTrafficUrl", but "I.startRecordingTraffic" was never called before.');
}

for (const i in this.requests) {
// eslint-disable-next-line no-prototype-builtins
if (this.requests.hasOwnProperty(i)) {
const request = this.requests[i];

if (request.url && request.url.match(new RegExp(urlMatch))) {
return request.url;
}
}
}

assert.fail(`Method "getTrafficUrl" failed: No request found in traffic that matches ${urlMatch}`);
}

/**
*
* {{> grabRecordedNetworkTraffics }}
Expand Down

0 comments on commit 036b979

Please sign in to comment.