2014-06-05 14 views
0

我必须使用LoadImpact来测试我的网站的不同部分,以确保他们可以处理大量的人做他们不同的事情。 LoadImpact使我可以完成创建新用户帐户并记录所有击键的过程。问题是我想反复运行相同的测试,但如果用户已经存在,我会看到错误。所以我所做的就是更改代码,为每个测试应用随机名称和随机用户名。我需要知道的是这个理论上会起作用吗?我没有使用JavaScript很多,但这看起来应该做些什么才能使它工作。试图运行一个LoadImpact JavaScript编辑代码

var first = String.fromCharCode(97 + Math.round(Math.random() * 25)); 
var second = String.fromCharCode(65 + Math.round(Math.random() * 25)); 
var firstName = first + second; 

var first2 = String.fromCharCode(97 + Math.round(Math.random() * 25)); 
var second2 = String.fromCharCode(65 + Math.round(Math.random() * 25)); 
var lastName = first2 + second2; 

http.request_batch({ 
    {"POST", "https://blah.blah.com/registration/lookup/", 
     headers = { 
      ["Content-Type"] = "application/x-www-form-urlencoded", 
     }, 
     data = "firstname="+firstName+"&lastname="+lastName+"&dob=02%2F23%2F1980&ssn=4569", 
    }, 
}) 
http.page_end("Page 5") 

回答

0

你只能用脚本的一个大问题 - 负载影响的脚本在Lua进行,而不是使用Javascript!

代码应该是这个样子:

local first = String.char(97 + Math.random(25)) 
local second = String.char(65 + Math.random(25)) 
local firstName = first .. second 

local first2 = String.char(97 + Math.random(25)) 
local second2 = String.char(65 + Math.random(25)) 
local lastName = first2 .. second2 

http.request_batch({ 
    {"POST", "https://blah.blah.com/registration/lookup/", 
     headers = { 
      ["Content-Type"] = "application/x-www-form-urlencoded", 
     }, 
     data = "firstname=" .. firstName .. "&lastname=" .. lastName .. "&dob=02%2F23%2F1980&ssn=459", 
    }, 
})