I am looping values from an Excel file by using ${txnExcel}
to search and compare the value. But sometimes ${txnExcel}
is doesn't exist in the system. In that case I want to ignore the fail (as there is no need to compare value) and continue to the next ${txnExcel}
by skipping the error.
open excel ${PATH_EXCEL}
${exp_row_count} get row count Sheet1
:For ${i} in range 1 ${exp_row_count}
\ ${excel_index} evaluate ${i}+1
\ ${txnExcel} Read Cell Data By Name Sheet1 B${excel_index}
\ ${ServiceTypeExcel} Read Cell Data By Name Sheet1 C${excel_index}
\ ${TransferAmountExcelOrigin} Read Cell Data By Name Sheet1 D${excel_index}
\ ${CurrencyExcel} Read Cell Data By Name Sheet1 E${excel_index}
\ ${TransferAmountExcel} set variable ${TransferAmountExcelOrigin} ${CurrencyExcel}
#=======================================================================================
\ input text name=id_or_tsn ${txnExcel}
\ click button name=Submit
\ wait until element is visible xpath=/html/body/div[2]/div[2]/div/div/div/div[1]/div[2] 5s
#===========================Compare Transaction Element================================================
\ ${txnCompare} get text xpath=/html/body/div[2]/div[2]/div/div/div/div[1]/div[2]
\ ${ServiceTypeCompare} get text xpath=/html/body/div[2]/div[2]/div/div/div/div[3]/div[2]/span
\ ${TransferAmountCompare} get text xpath=/html/body/div[2]/div[2]/div/div/div/div[5]/div[2]/span
\ ${CurrencyCompare} get text xpath=/html/body/div[2]/div[2]/div/div/div/div[4]/div[2]
\ should be equal as strings ${txnExcel} ${txnCompare} invalid TXN comparison[${i}]
\ should be equal as strings ${ServiceTypeExcel} ${ServiceTypeCompare} invalid ServiceType comparison[${i}]
\ should be equal as strings ${TransferAmountExcel} ${TransferAmountCompare} invalid Transfer Amount comparison[${i}]
\ should be equal as strings ${CurrencyExcel} ${CurrencyCompare} invalid Currency comparison[${i}]
#============================End Compare Transaction Element====================================================
Here the solution that work for me now .
open excel ${PATH_EXCEL}
${exp_row_count} get row count Sheet1
:For ${i} in range 1 ${exp_row_count}
\ ${excel_index} evaluate ${i}+1
\ ${txnExcel} Read Cell Data By Name Sheet1 B${excel_index}
\ ${ServiceTypeExcel} Read Cell Data By Name Sheet1 C${excel_index}
\ ${TransferAmountExcelOrigin} Read Cell Data By Name Sheet1 D${excel_index}
\ ${CurrencyExcel} Read Cell Data By Name Sheet1 E${excel_index}
\ ${TransferAmountExcel} set variable ${TransferAmountExcelOrigin} ${CurrencyExcel}
#=======================================================================================
\ input text name=id_or_tsn ${txnExcel}
\ click button name=Submit
\ ${found_txn} run keyword and return status wait until element is visible xpath=/html/body/div[2]/div[2]/div/div/div/div[1]/div[2] 5s
\ ${error_message} run keyword unless ${found_txn} get text xpath=/html/body/div[2]/div[2]
\ run keyword and continue on failure element should be visible xpath=/html/body/div[2]/div[2]/div/div/div/div[1]/div[2]
\ run keyword unless ${found_txn} continue for loop
#===========================Compare Transaction Element================================================
\ ${txnCompare} get text xpath=/html/body/div[2]/div[2]/div/div/div/div[1]/div[2]
\ ${ServiceTypeCompare} get text xpath=/html/body/div[2]/div[2]/div/div/div/div[3]/div[2]/span
\ ${TransferAmountCompare} get text xpath=/html/body/div[2]/div[2]/div/div/div/div[5]/div[2]/span
\ ${CurrencyCompare} get text xpath=/html/body/div[2]/div[2]/div/div/div/div[4]/div[2]
\ should be equal as strings ${txnExcel} ${txnCompare} invalid TXN comparison[${i}]
\ should be equal as strings ${ServiceTypeExcel} ${ServiceTypeCompare} invalid ServiceType comparison[${i}]
\ should be equal as strings ${TransferAmountExcel} ${TransferAmountCompare} invalid Transfer Amount comparison[${i}]
\ should be equal as strings ${CurrencyExcel} ${CurrencyCompare} invalid Currency comparison[${i}]