Skip to content

Commit 9a7991b

Browse files
authored
fix: grabRecordedNetworkTraffics throws error when being called twice (#4143)
1 parent 4201c4f commit 9a7991b

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

lib/helper/Playwright.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,27 +2974,27 @@ class Playwright extends Helper {
29742974
throw new Error('Failure in test automation. You use "I.grabRecordedNetworkTraffics", but "I.startRecordingTraffic" was never called before.');
29752975
}
29762976

2977-
const requests = await this.requests;
2978-
const promises = requests.map(async (request) => request.response.then(
2979-
async (response) => {
2980-
let body;
2981-
try {
2982-
// There's no 'body' for some requests (redirect etc...)
2983-
body = JSON.parse((await response.body()).toString());
2984-
} catch (e) {
2985-
// only interested in JSON, not HTML responses.
2986-
}
2977+
const promises = this.requests.map(async (request) => {
2978+
const resp = await request.response;
2979+
let body;
2980+
try {
2981+
// There's no 'body' for some requests (redirect etc...)
2982+
body = JSON.parse((await resp.body()).toString());
2983+
} catch (e) {
2984+
// only interested in JSON, not HTML responses.
2985+
}
29872986

2988-
request.response = {
2989-
status: response.status(),
2990-
statusText: response.statusText(),
2987+
return {
2988+
url: resp.url(),
2989+
response: {
2990+
status: resp.status(),
2991+
statusText: resp.statusText(),
29912992
body,
2992-
};
2993-
},
2994-
));
2995-
await Promise.all(promises);
2993+
},
2994+
};
2995+
});
29962996

2997-
return this.requests;
2997+
return Promise.all(promises);
29982998
}
29992999

30003000
/**

test/helper/Playwright_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ describe('Playwright', function () {
983983
await I.see('this was another mocked');
984984

985985
const traffics = await I.grabRecordedNetworkTraffics();
986+
await I.grabRecordedNetworkTraffics();
986987
expect(traffics[0].url).to.equal('https://reqres.in/api/comments/1');
987988
expect(traffics[0].response.status).to.equal(200);
988989
expect(traffics[0].response.body).to.contain({ name: 'this was mocked' });

0 commit comments

Comments
 (0)