开发者

How to pass a random User/Pass (for Basic Authentication) with JMeter?

I'm using JMeter to stress test an API. I've got Basic Authentication set up - seems to be working great.

Now, i'm trying to randomize the credentials that JMeter passes across the wire. So, there's two ways I know I can do this.

    开发者_运维百科
  1. Add a custom HTTP Header (via an HTTP Header Manager Element) and set then value to the random fields (ie. something I've read in from a csv file)
  2. Use the HTTP Authorization Manager Element and pass in the username and password there.

Now, if I try and use method (1) above, I need to create the following header/data :-

Authorization: Basic <some Base64 encoded string in the format username:password>

eg.
Authorization: Basic OnVzZXIxOnBhc3Mx

Kewl. simple. BUT that header value is not getting passed across the wire :( I can add any other header type and it's passed across the wire..

hmm .. ok then .. lets try method (2).

Now that works .. but I can only hardcode in the username & password. I can't see how I can pass in a username VARIABLE (ie. ${usernmae} ) or a password VARIABLE (ie. ${password} ).... If it's hardcoded, then the server correctly replies with the correct page/data.

so .. can someone please help?


I would recommend trying the following:

  1. Create a HTTP Authorization Manager Element
  2. Setup the username and password to be variables, ${username} , ${password}
  3. Create a CSV file with your usernames and passwords (do not use a header row)
  4. create a CSV Data Set Config Element, with the variable names set to "username,password" (no quotes, and no space after the comma)
  5. Each thread/loop will read a different value from the CSV file.

Alternately, if you want the value to be truely random for the login, there are some functions you can use to generate random numbers or send in the time of execution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜