2

I am trying to simulate a logged in user activity for stress testing a WordPress site using this script:

import http from "k6/http";
import { sleep } from "k6";

export default function() {
  var url = "http://example.com.com/wp-login.php";
  var payload = JSON.stringify({ user_login: "admin", user_pass: "adminpass" });
  var params =  { headers: { "Content-Type": "application/json" } }
  http.post(url, payload, params);

  console.log(payload);

  http.get("http://example.com/wp-admin/post-new.php")

  sleep(1)
};

This doesn't work and I am redirected to the login page. What am I doing wrong?

1 Answers1

1

I'm not very familiar with Wordpress internals, but looking at a few random installations' wp-login.php page, it doesn't look like it accepts a JSON string as the POST data, but rather a plain application/x-www-form-urlencoded POST request: http.post("http://example.com.com/wp-login.php", { user_login: "admin", user_pass: "adminpass" }) (though the field names were different).

To be sure, you can log in with a browser and then export the HAR file with the HTTP requests it made and convert it to a k6 script with the HAR converter in k6 by running k6 convert exported.har. You can find more information about that here

na--
  • 1,016
  • 7
  • 9