feat: Support to generator JavaScript code from a HTTP testCase.#400
feat: Support to generator JavaScript code from a HTTP testCase.#400LinuxSuRen merged 2 commits intoLinuxSuRen:masterfrom
Conversation
In browsers or Node.js, sending an HTTP GET request with a body is not allowed, and it will be blocked by the browser. However, I've still generated code for this situation. When using a GET request in this manner, I've added a comment: Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET Update: On browsers, when |
This is ok to me. How about adding comment in line 24 and 25? So, those source code can work well. Even we can add a console output, for example: |
|
This looks better! I will implement it later.
|
|
|
Now, the new code generator looks like this: async function makeRequest() {
const headers = new Headers();
headers.append("User-Agent", "atest");
const cookieHeader = [
"name=value",
].join("; ");
headers.append("Cookie", cookieHeader);
const requestOptions = {
method: "GET",
headers: headers,
redirect: "follow"
};
console.log('the body is ignored because this is a GET request')
/*
let body = `{"key": "value"}`;
requestOptions.body = body;
*/
try {
const response = await fetch("https://www.baidu.com", requestOptions);
if (response.ok) { // Check if HTTP status code is 200/OK
const text = await response.text();
console.log(text);
} else {
throw new Error('Network response was not ok. Status code: ' + response.status);
}
} catch (error) {
console.error('Fetch error:', error);
}
}
makeRequest(); |







add javascript generator.
add javascript code generator test data.
What type of PR is this?
feat: Support to generator JavaScript code from a HTTP testCase.
Which issue(s) this PR fixes:
Fixes #395