登錄接口測試的時候,會有個登錄賬號每個賬號都需要測試一下,爲了不每測試一個賬號就修改一下body參數,可以在預執行腳本中編寫一個mock腳本進行獲取
把這些登錄賬號設置爲數組,在獲取數組,把數組中的值賦值爲環境變量或者全局變量,調用變量就可以了。
var arr = [{“test”:[“xiaoya”,“1”]},{“test”:[“admin”,“2”]},{“test”:[“xiaoming”,“3”]}];
var index = Math.floor((Math.random()*arr.length));
var test=arr[index];
apt.globals.set(“username”, test.test[0]);
apt.globals.set(“password”, test.test[1]);