Skip to content

Commit dcd974e

Browse files
authored
fixed empty body error with Wait For Response (MarketSquare#2971)
Signed-off-by: René <[email protected]>
1 parent 5843530 commit dcd974e

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

atest/test/02_Content_Keywords/tab.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Tab Button With Options
2727

2828
Tab Button With Modifiers
2929
[Setup] Open Page With Touch Enabled
30-
Tap \#clickWithOptions Shift Alt
30+
Tap \#clickWithOptions Shift Alt
3131
Get Text text=Please input your user name and password and click the login button.
3232

3333
*** Keywords ***

atest/test/03_Waiting/wait_for_http.robot

+11
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ Wait For Response Async
5656
Click \#delayed_request
5757
${body} = Wait For ${promise}
5858

59+
Wait For Response With OPTIONS Request
60+
Go To ${ROOT_URL}
61+
${prom} = Promise To Wait For Response /.*options/ # ΔT: 0.028s
62+
${res} = Evaluate JavaScript
63+
... ${None}
64+
... () => fetch('api/options', {method: 'OPTIONS'}).then(resp => resp.status)
65+
${res2} = Wait For ${prom}
66+
Should Be Equal As Numbers ${res} 204
67+
Should Be Equal As Numbers ${res2.status} 204
68+
Should Be Equal ${res2.body} ${None}
69+
5970
Wait Until Network Is Idle Works
6071
[Tags] slow
6172
Go To ${ROOT_URL}delayed-load.html

node/dynamic-test-app/src/server.ts

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ app.get('/api/get/json', (req, res) => {
2121
res.send(JSON.stringify({ greeting: 'HELLO' }));
2222
});
2323

24+
app.options('/api/options', (req, res) => {
25+
res.header('Access-Control-Allow-Origin', '*');
26+
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
27+
res.status(204);
28+
res.send();
29+
});
30+
2431
app.get('/api/get/text', (req, res) => {
2532
res.send('HELLO');
2633
});

node/playwright-wrapper/network.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ export async function waitForResponse(request: pb.Request.HttpCapture, page: Pag
7171
const urlOrPredicate = deserializeUrlOrPredicate(request.getUrlorpredicate());
7272
const timeout = request.getTimeout();
7373
const data = await page.waitForResponse(urlOrPredicate, { timeout });
74+
let body = null;
75+
try {
76+
body = await data.text();
77+
} catch (e) {}
7478
return jsonResponse(
7579
JSON.stringify({
7680
status: data.status(),
77-
body: await data.text(),
81+
body: body,
7882
headers: JSON.stringify(data.headers()),
7983
statusText: data.statusText(),
8084
url: data.url(),

0 commit comments

Comments
 (0)