diff --git a/lib/helper/Puppeteer.js b/lib/helper/Puppeteer.js index 3a23b5f7f..eed4984d2 100644 --- a/lib/helper/Puppeteer.js +++ b/lib/helper/Puppeteer.js @@ -2591,7 +2591,8 @@ class Puppeteer extends Helper { * * {{> stopRecordingTraffic }} */ - stopRecordingTraffic() { + async stopRecordingTraffic() { + await this.page.setRequestInterception(false) stopRecordingTraffic.call(this) } diff --git a/lib/helper/network/actions.js b/lib/helper/network/actions.js index e89ba7ed2..6be1c1ebc 100644 --- a/lib/helper/network/actions.js +++ b/lib/helper/network/actions.js @@ -30,7 +30,7 @@ async function seeTraffic({ throw new Error('Missing required key "url" in object given to "I.seeTraffic".'); } - if (!this.recording || !this.recordedAtLeastOnce) { + if (!this.recordedAtLeastOnce) { throw new Error('Failure in test automation. You use "I.seeTraffic", but "I.startRecordingTraffic" was never called before.'); } @@ -66,7 +66,7 @@ async function seeTraffic({ } async function grabRecordedNetworkTraffics() { - if (!this.recording || !this.recordedAtLeastOnce) { + if (!this.recordedAtLeastOnce) { throw new Error('Failure in test automation. You use "I.grabRecordedNetworkTraffics", but "I.startRecordingTraffic" was never called before.'); } @@ -107,6 +107,8 @@ async function grabRecordedNetworkTraffics() { function stopRecordingTraffic() { // @ts-ignore this.page.removeAllListeners('request'); + // @ts-ignore + this.page.removeAllListeners('requestfinished'); this.recording = false; } diff --git a/test/helper/webapi.js b/test/helper/webapi.js index 4705eae67..cd9b58b39 100644 --- a/test/helper/webapi.js +++ b/test/helper/webapi.js @@ -1703,6 +1703,16 @@ module.exports.tests = function () { expect(traffics.length).to.equal(0) }) + it('should stop the network recording', async () => { + await I.startRecordingTraffic() + await I.amOnPage('https://codecept.io/') + await I.stopRecordingTraffic() + const traffics1 = await I.grabRecordedNetworkTraffics() + await I.amOnPage('https://codecept.io/') + const traffics2 = await I.grabRecordedNetworkTraffics() + expect(traffics2.length).to.equal(traffics1.length) + }) + it('should see recording traffics', async () => { I.startRecordingTraffic() I.amOnPage('https://codecept.io/')