如圖示意
↓
但DB中欄位為空值時,由RIDE取出文字會看到兩種狀況:
DB呈現{null},用RIDE抓出來呈現"None"
DB呈現,用RIDE抓出來呈現"".0個字元的空白而Web UI中欄位為空值時,由RIDE取出文字也會有狀況:
Web UI呈現,用RIDE抓出來呈現" ".1個字元的空白
以下為Robot Framework Python的寫法
--------------------------------
*** Test Cases *** Verify data with DB Connect Database ${UI_List} Create List #找出網頁上的ListView有多少筆資料,存入變數${Get_Organization_Count} ${Get_Organization_Count} Get Matching Xpath Count xpath=html/body/div[5]/div[2]/div/div/div[3]/div[4]/div/table/tbody/tr #建立FOR迴圈,從1~${Get_Organization_Count}的範圍 : FOR ${INDEX} IN RANGE 1 ${Get_Organization_Count}+1 \ ${announcement}= Get Text xpath=html/body/div[5]/div[2]/div/div/div[3]/div[4]/div/table/tbody/tr[${Index}]/td[10]/div \ #此為第一種狀況:UI欄位看起來是空白,但擷取後呈現1個字元的空白→EX:" ".『Strip String』即為去除空白 \ ${announcement}= Strip String ${announcement} \ Append To List ${UI_List} ${announcement} \ #此為第二種狀況:因為DB欄位顯示"{null}",但擷取後呈現"None".故須將UI欄位轉為"None"再進行比對 \ ${announcement}= Run keyword if "${announcement}"=="" SPACE Convert To None ${announcement} \ ... ELSE No Convert ${announcement} \ Append To List ${UI_List} ${announcement} Log -----------------已取完UI_List--------------------------------- Connect Database ${DB_List} Create List ${select_Basic_Hospital}= Set Variable select Top ${Get_Organization_Count} hospital_code, nhi_code, hospital_name, addr, phone, email from Basic_Hospital where active_flag = '1' ORDER BY hospital_name ASC ${queryResults}= Query ${select_Basic_Hospital} #找出DB上有多少筆列資料,存入變數${RowCount} ${RowCount} Row Count ${select_Basic_Hospital} : FOR ${x} IN RANGE 0 ${RowCount} \ Log 第${x}次呼叫Query DB data by Nested loop \ ${DB_List_Return}= Query DB data by Nested loop ${DB_List} ${x} ${select_Basic_Hospital} Log -----------------已取完DB_List_Return--------------------------------- #UI與DB清單進行比對 Should Be Equal ${UI_List} ${DB_List_Return} *** Keywords *** Query DB data by Nested loop [Arguments] ${DB_List} ${x} ${DML} Connect Database ${queryResults}= Query ${DML} #執行DML資料操作語言 ${Verify_List} Convert To String ${queryResults[0]} #只取一列資料當代表 #用逗號分開字串(註解不要寫在有=的句子後面) ${result} = Split String ${Verify_List} , ${ColumnTotal} Get Length ${result} #可以取得長度=欄位數 Log 取得列資料的欄位數${ColumnTotal} : FOR ${y} IN RANGE 0 ${ColumnTotal} \ ${Verify_List} Convert To String ${queryResults[${x}][${y}]} \ Append To List ${DB_List} ${Verify_List} [Return] ${DB_List} SPACE Convert To None [Arguments] ${OriginString} #當沒有值時,DB呈現{null},用RIDE抓出來呈現"None".所以畫面上的值要None再跟DB比 ${Return_None}= Convert To String None [Return] ${Return_None} No Convert [Arguments] ${OriginString} [Return] ${OriginString}--------------------------------
Install Robotframework IDE (RIDE)
【XPATH】透過FirePath與Firebug擴充套件找出XPATH
沒有留言:
張貼留言