-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support to generator JavaScript code from a HTTP testCase. #400
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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