本文整理汇总了TypeScript中k6.check函数的典型用法代码示例。如果您正苦于以下问题:TypeScript check函数的具体用法?TypeScript check怎么用?TypeScript check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test3
function test3() {
const res = http.get("http://httpbin.org");
check(res, {
"response code was 200": (res) => res.status === 200,
"body size was 1234 bytes": (res) => res.body.length === 1234,
});
}
示例2: group
group("features page", () => {
const res = http.get("https://loadimpact.com/features");
check(res, {
"status code is 200": (res) => res.status === 200,
"h1 message is correct": (res) => res.html("h1").text().startsWith("Simple yet realistic load testing"),
});
});
示例3: httpTest5
function httpTest5() {
const options = { maxRedirects: 10 };
const baseURL = "https://dev-li-david.pantheonsite.io";
// Fetch the login page, with the login HTML form
const res1 = http.get(baseURL + "/user/login");
// Extract hidden value needed to POST form
const formBuildID = (res1.body.match('name="form_build_id" value="(.*)"') || [])[1];
// Create an Object containing the form data
const formdata = {
name: "testuser1",
pass: "testuser1",
form_build_id: formBuildID,
form_id: "user_login",
op: "Log in",
};
const headers = { "Content-Type": "application/x-www-form-urlencoded" };
// Send login request
const res2 = http.post(baseURL + "/user/login", formdata, { headers });
// Verify that we ended up on the user page
check(res2, {
"login succeeded": (res2) => res2.url === `${baseURL}/users/testuser1`,
}) || fail("login failed");
}
示例4: httpTest1
function httpTest1() {
const responses = http.batch([
"http://test.loadimpact.com",
"http://test.loadimpact.com/style.css",
"http://test.loadimpact.com/images/logo.png",
]);
check(responses[0], {
"main page status was 200": res => res.status === 200,
});
}
示例5: httpTest8
function httpTest8() {
// Passing username and password as part of URL plus the auth option will authenticate using HTTP Digest authentication
const res = http.get("http://user:passwd@httpbin.org/digest-auth/auth/user/passwd", {auth: "digest"});
// Verify response
check(res, {
"status is 200": (r) => r.status === 200,
"is authenticated": (r) => r.json().authenticated === true,
"is correct user": (r) => r.json().user === "user"
});
}
示例6: httpTest9
function httpTest9() {
const res = http.get("https://loadimpact.com");
for (const p in res.headers) {
if (res.headers.hasOwnProperty(p)) {
console.log(`${p} : ${res.headers[p]}`);
}
}
check(res, {
"status is 200": (r) => r.status === 200,
"caption is correct": (r) => r.html("h1").text() === "Example Domain",
});
}
示例7: httpTest2
function httpTest2() {
const req1 = {
method: "GET",
url: "http://httpbin.org/get",
};
const req2 = {
method: "GET",
url: "http://test.loadimpact.com",
};
const req3 = {
method: "POST",
url: "http://httpbin.org/post",
body: {
hello: "world!",
},
params: { headers: { "Content-Type": "application/x-www-form-urlencoded" } }
};
const responses = http.batch([req1, req2, req3]);
// httpbin.org should return our POST data in the response body, so
// we check the third response object to see that the POST worked.
check(responses[2], {
"form data OK": (res) => JSON.parse(res.body)["form"]["hello"] === "world!",
});
}
示例8: test4
function test4() {
const res = http.get("https://loadimpact.com");
check(res, {
"status code MUST be 200": (res) => res.status === 200,
}) || fail("status code was *not* 200");
}