腳本參數化實現(xiàn)用例的自動化批量執(zhí)行
自動化測試的核心和靈魂是自動化批量執(zhí)行用例,那么對于自動化執(zhí)行過程中的執(zhí)行記錄,我們也要記錄下來,這個時候需要對我們的測試腳本進行參數化和場景的編輯:
首先我們錄制一個登陸頁面的腳本(具體操作請見“腳本錄制”一文),點擊視圖中參數表部分添加參數表:

接下來我們對腳本進行參數化,在這個腳本里我們可以對用戶名:username和密碼:password進行參數化。
參數化命令分別是:
ar.window("IEFrame_上海澤眾軟件科技有限公司客戶管理系統(tǒng) - Windows Internet Explorer").setValue("INPUT_text_username", ""+pd.getFrom("username"));
ar.window("IEFrame_上海澤眾軟件科技有限公司客戶管理系統(tǒng) - Windows Internet Explorer").setValue("INPUT_password_password", ""+pd.getFrom("password"));
循環(huán)參數表設置:

然后把要循環(huán)的內容,也是之前編輯好的腳本放到循環(huán)體內,整個腳本如下:
for(ParameterData pd : ar.getParameterDataList("lianxi22.xls")/*.subList(0, 4)*/)
{
//ar.parameterData = pd;//ar.parameterData可用于腳本之間傳遞參數
ar.window("IEFrame_上海澤眾軟件科技有限公司客戶管理系統(tǒng) - Windows Internet Explorer").clickControl("INPUT_text_username", 68, 12, "left");
ar.window("IEFrame_上海澤眾軟件科技有限公司客戶管理系統(tǒng) - Windows Internet Explorer").setValue("INPUT_text_username", ""+pd.getFrom("username"));
ar.window("IEFrame_上海澤眾軟件科技有限公司客戶管理系統(tǒng) - Windows Internet Explorer").setValue("INPUT_password_password", ""+pd.getFrom("password"));
ar.window("IEFrame_上海澤眾軟件科技有限公司客戶管理系統(tǒng) - Windows Internet Explorer").clickControl("INPUT_submit_登 錄", 40, 15, "left");
ar.window("IEFrame_上海澤眾軟件科技有限公司客戶管理系統(tǒng) Windows Internet Explorer").clickControl("A_退出系統(tǒng)", 23, 2, "left");
}
執(zhí)行下測試腳本,我們來看下執(zhí)行的結果。

腳本執(zhí)行成功,這邊我們總共跑了四條用例!參數表里面數據的組數決定了我們自動化測試要跑的用例的條數!