samples/pantheon.js
function doLogin() {
	// Request the login page.
	let res = http.get(baseURL + "/user/login");
	check(res, {
		"title is correct": (res) => res.html("title").text() == "User account | David li commerce-test",
	});

	// TODO: Add attr() to k6/html!
	// Extract hidden input fields.
	let formBuildID = res.body.match('name="form_build_id" value="(.*)"')[1];

	group("login", function() {
		// Pick a random set of credentials.
		let creds = credentials[Math.floor(Math.random()*credentials.length)];

		// Create login request.
		let formdata = {
			name: creds.username,
			pass: creds.password,
			form_build_id: formBuildID,
			form_id: "user_login",
			op: "Log in",
		};
		let headers = { "Content-Type": "application/x-www-form-urlencoded" };
		// Send login request
		let res = http.post(baseURL + "/user/login", formdata, { headers: headers });
		// Verify that we ended up on the user page
		check(res, {
			"login succeeded": (res) => res.url == `${baseURL}/users/${creds.username}`,
		}) || fail("login failed");
	});
}
function doLogin() {
	// Request the login page.
	let res = http.get(baseURL + "/user/login");
	check(res, {
		"title is correct": (res) => res.html("title").text() == "User account | David li commerce-test",
	});

	// TODO: Add attr() to k6/html!
	// Extract hidden input fields.
	let formBuildID = res.body.match('name="form_build_id" value="(.*)"')[1];

	group("login", function() {
		// Pick a random set of credentials.
		let creds = credentials[Math.floor(Math.random()*credentials.length)];

		// Create login request.
		let formdata = {
			name: creds.username,
			pass: creds.password,
			form_build_id: formBuildID,
			form_id: "user_login",
			op: "Log in",
		};
		let headers = { "Content-Type": "application/x-www-form-urlencoded" };
		// Send login request
		let res = http.post(baseURL + "/user/login", formdata, { headers: headers });
		// Verify that we ended up on the user page
		check(res, {
			"login succeeded": (res) => res.url == `${baseURL}/users/${creds.username}`,
		}) || fail("login failed");
	});
}
function doLogin ( ) { // Request the login page. let res = http . get ( baseURL + "/user/login" ) ; check ( res , { "title is correct" : ( res ) => res . html ( "title" ) . text ( ) == "User account | David li commerce-test" , } ) ; // TODO: Add attr() to k6/html! // Extract hidden input fields. let formBuildID = res . body . match ( 'name="form_build_id" value="(.*)"' ) [ 1 ] ; group ( "login" , function ( ) { // Pick a random set of credentials. let creds = credentials [ Math . floor ( Math . random ( ) * credentials . length ) ] ; // Create login request. let formdata = { name : creds . username , pass : creds . password , form_build_id : formBuildID , form_id : "user_login" , op : "Log in" , } ; let headers = { "Content-Type" : "application/x-www-form-urlencoded" } ; // Send login request let res = http . post ( baseURL + "/user/login" , formdata , { headers : headers } ) ; // Verify that we ended up on the user page check ( res , { "login succeeded" : ( res ) => res . url == ` ${ baseURL } ${ creds . username } ` , } ) || fail ( "login failed" ) ; } ) ; }
Request the login page and perform a user login
Request the login page and perform a user login