Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a396c5b

Browse files
Bugfix: Properly stop network traffic recording (#5127)
* fix: improve traffic recording checks and add test for stopping network recording * fix: lint * fix: make stopRecordingTraffic asynchronous and add request interception handling for pupperteer
1 parent 15a288e commit a396c5b

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

‎lib/helper/Puppeteer.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,8 @@ class Puppeteer extends Helper {
25912591
*
25922592
* {{> stopRecordingTraffic }}
25932593
*/
2594-
stopRecordingTraffic() {
2594+
async stopRecordingTraffic() {
2595+
await this.page.setRequestInterception(false)
25952596
stopRecordingTraffic.call(this)
25962597
}
25972598

‎lib/helper/network/actions.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function seeTraffic({
3030
throw new Error('Missing required key "url" in object given to "I.seeTraffic".');
3131
}
3232

33-
if (!this.recording||!this.recordedAtLeastOnce) {
33+
if (!this.recordedAtLeastOnce) {
3434
throw new Error('Failure in test automation. You use "I.seeTraffic", but "I.startRecordingTraffic" was never called before.');
3535
}
3636

@@ -66,7 +66,7 @@ async function seeTraffic({
6666
}
6767

6868
async function grabRecordedNetworkTraffics() {
69-
if (!this.recording||!this.recordedAtLeastOnce) {
69+
if (!this.recordedAtLeastOnce) {
7070
throw new Error('Failure in test automation. You use "I.grabRecordedNetworkTraffics", but "I.startRecordingTraffic" was never called before.');
7171
}
7272

@@ -107,6 +107,8 @@ async function grabRecordedNetworkTraffics() {
107107
function stopRecordingTraffic() {
108108
// @ts-ignore
109109
this.page.removeAllListeners('request');
110+
// @ts-ignore
111+
this.page.removeAllListeners('requestfinished');
110112
this.recording = false;
111113
}
112114

‎test/helper/webapi.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,16 @@ module.exports.tests = function () {
17031703
expect(traffics.length).to.equal(0)
17041704
})
17051705

1706+
it('should stop the network recording', async () => {
1707+
await I.startRecordingTraffic()
1708+
await I.amOnPage('https://codecept.io/')
1709+
await I.stopRecordingTraffic()
1710+
const traffics1 = await I.grabRecordedNetworkTraffics()
1711+
await I.amOnPage('https://codecept.io/')
1712+
const traffics2 = await I.grabRecordedNetworkTraffics()
1713+
expect(traffics2.length).to.equal(traffics1.length)
1714+
})
1715+
17061716
it('should see recording traffics', async () => {
17071717
I.startRecordingTraffic()
17081718
I.amOnPage('https://codecept.io/')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /