當(dāng)前位置:兩周學(xué)會自動化測試 >> 腳本參數(shù)化實現(xiàn)用例的自動化批量執(zhí)行

腳本參數(shù)化實現(xiàn)用例的自動化批量執(zhí)行

自動化測試的核心和靈魂是自動化批量執(zhí)行用例,那么對于自動化執(zhí)行過程中的執(zhí)行記錄,我們也要記錄下來,這個時候需要對我們的測試腳本進(jìn)行參數(shù)化和場景的編輯:

首先我們錄制一個登陸頁面的腳本(具體操作請見“腳本錄制”一文),點(diǎn)擊視圖中參數(shù)表部分添加參數(shù)表:

接下來我們對腳本進(jìn)行參數(shù)化,在這個腳本里我們可以對用戶名:username和密碼:password進(jìn)行參數(shù)化。

參數(shù)化命令分別是:

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)參數(shù)表設(shè)置:

然后把要循環(huán)的內(nèi)容,也是之前編輯好的腳本放到循環(huán)體內(nèi),整個腳本如下:

for(ParameterData pd : ar.getParameterDataList("lianxi22.xls")/*.subList(0, 4)*/)

{

//ar.parameterData = pd;//ar.parameterData可用于腳本之間傳遞參數(shù)

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í)行的結(jié)果。

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