Robot?framework?循環(huán)讀取excel中入?yún)?/p>
從本地文件讀取用戶名和密碼實(shí)現(xiàn)多用戶的登陸,詳情見下。
[if !supportLists]①?[endif]編寫登陸操作奴曙,詳情見下草讶。
以上三個(gè)參數(shù)中地址取值公共參數(shù),見下圖坤溃。另外登錄用戶名和密碼都是依據(jù)excel每行記錄進(jìn)行取值入?yún)ⅰ?/p>
Excel文件中最好都設(shè)置為文本格式嘱丢,在單元格左上角填入’。
循環(huán)讀取excel入?yún)⑷缦掠旆恚琫xcel中有多少行就循環(huán)多少次伐谈,見下试疙。
具體腳本如下。
*** Settings ***
Library ??????????Selenium2Library
Library ??????????DatabaseLibrary
Resource ?????????./業(yè)務(wù)流程.txt
Library ??????????ExcelLibrary
Library ??????????Collections
*** Variables ***
${URL-pre} ???????http://172.29.0.180/sncfc-smp/login/index.do ???# pre新進(jìn)件菜單地址
${URL-sit} ???????http://172.29.0.188:8015/sncfc-smp/login.jsp ???# sit新進(jìn)件菜單地址
${username} ??????17010438 ???#操作用戶名
${password} ??????`123Qwer ???#操作用戶密碼
*** Test Cases ***
新進(jìn)件申請(qǐng)-店內(nèi)任性付
01打開瀏覽器并登錄 ???${URL-pre} ???${username} ???${password}
#打開菜單進(jìn)入主頁(yè)面
店內(nèi)任性付測(cè)試1
00打開瀏覽器并登錄 ???${URL-pre}
#打開菜單進(jìn)入主頁(yè)面
00LOGIN
????[Arguments] ???${URL-pre} ???${username} ???${password}
????[Timeout]
????Open Browser ???${URL-pre} ???chrome
????Maximize Browser Window
????Input Text ???id=username ???${username}
????Input Text ???id=password ???${password}
????click BUTTON ???id=button1
????sleep ???2
????Confirm Action
????wait until element is visible ???id=logout
close Browser
00打開瀏覽器并登錄
????[Arguments] ???${URL-pre}
????[Timeout]
????open excel ???C://Python27//ExcelRobotTest//ExcelRobotTest.xls
????@{list_column_A} ???get column values ???TestSheet1 ???0
????#log many ???@{list_column_A}
????${list_column_B} ???get column values ???TestSheet1 ???1
????#log many ???${list_column_B}
????${count_row} ???get row count ???TestSheet1
????#log many ???${count_row}
????set_suite_variable ???${count_row}
????${y} ???set_variable ???1
????: FOR ???${x} ???IN RANGE ???${count_row}
????\ ???${user0} ???set_variable ???${list_column_A[${x}][${y}]}
????\ ???log ???${user0}
????\ ???${pwd0} ???set_variable ???${list_column_B[${x}][${y}]}
????\ ???log ???${pwd0}
????\ ???00LOGIN ???${URL-pre} ???${list_column_A[${x}][${y}]} ???${list_column_B[${x}][${y}]}