2014-06-05 11 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", 
    }, 
})