Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,8 @@ class Puppeteer extends Helper {
*
* {{> stopRecordingTraffic }}
*/
stopRecordingTraffic() {
async stopRecordingTraffic() {
await this.page.setRequestInterception(false)
stopRecordingTraffic.call(this)
}

Expand Down
6 changes: 4 additions & 2 deletions lib/helper/network/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}

Expand Down Expand Up @@ -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.');
}

Expand Down Expand Up @@ -107,6 +107,8 @@ async function grabRecordedNetworkTraffics() {
function stopRecordingTraffic() {
// @ts-ignore
this.page.removeAllListeners('request');
// @ts-ignore
this.page.removeAllListeners('requestfinished');
this.recording = false;
}

Expand Down
10 changes: 10 additions & 0 deletions test/helper/webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand Down