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
36 changes: 18 additions & 18 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -2974,27 +2974,27 @@ class Playwright extends Helper {
throw new Error('Failure in test automation. You use "I.grabRecordedNetworkTraffics", but "I.startRecordingTraffic" was never called before.');
}

const requests = await this.requests;
const promises = requests.map(async (request) => request.response.then(
async (response) => {
let body;
try {
// There's no 'body' for some requests (redirect etc...)
body = JSON.parse((await response.body()).toString());
} catch (e) {
// only interested in JSON, not HTML responses.
}
const promises = this.requests.map(async (request) => {
const resp = await request.response;
let body;
try {
// There's no 'body' for some requests (redirect etc...)
body = JSON.parse((await resp.body()).toString());
} catch (e) {
// only interested in JSON, not HTML responses.
}

request.response = {
status: response.status(),
statusText: response.statusText(),
return {
url: resp.url(),
response: {
status: resp.status(),
statusText: resp.statusText(),
body,
};
},
));
await Promise.all(promises);
},
};
});

return this.requests;
return Promise.all(promises);
}

/**
Expand Down
1 change: 1 addition & 0 deletions test/helper/Playwright_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ describe('Playwright', function () {
await I.see('this was another mocked');

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