Robotframework 如何在Robot框架中清除或删除列表中的值
我编写了一个测试用例,它将从excel工作表中读取登录详细信息,并针对每一对详细信息进行登录和注销 我正在从Excel中读取数据,每一行的详细信息都将传递给列表,并将其作为输入发送到另一个关键字/函数进行登录 注销后,我只想删除列表中的值,它显示为successed,但在下一次运行中,它也显示了旧值 我搜索过,没有任何关键字来清除所有列表值 有人能帮我一下吗。代码如下:Robotframework 如何在Robot框架中清除或删除列表中的值,robotframework,Robotframework,我编写了一个测试用例,它将从excel工作表中读取登录详细信息,并针对每一对详细信息进行登录和注销 我正在从Excel中读取数据,每一行的详细信息都将传递给列表,并将其作为输入发送到另一个关键字/函数进行登录 注销后,我只想删除列表中的值,它显示为successed,但在下一次运行中,它也显示了旧值 我搜索过,没有任何关键字来清除所有列表值 有人能帮我一下吗。代码如下: *** Settings *** Documentation CLM Registration
*** Settings ***
Documentation CLM Registration Test Case
Test Teardown Close All Browsers
Library Selenium2Library
Library Collections
Library ExcelLibrary
Library String
*** Variables ***
${delay} 5s
${excelName} LoginTestData.xls
@{rowValues}
${rowCount} ${EMPTY}
${cellCount} ${EMPTY}
*** Test Cases ***
Get Data from Excel
Open Excel Sheet ${excelName}
@{sheetNames} Get Sheet Names
${sheetName} Set Variable @{sheetNames}[0]
${rowCount} Get Row Count ${sheetName}
${cellCount} Get Column Count ${sheetName}
: FOR ${rindex} IN RANGE 1 ${rowCount}
\ @{rowValues} Get Values ${sheetName} ${rindex} ${cellCount}
\ Log to console row values are for index ${rindex} : @{rowValues}
\ Login to the CLM @{rowValues}
\ Log cell count is : ${cellCount}
\ Change Language to English
\ Sleep ${delay}
\ Logout from CLM
\ Remove Values ${rowValues} ${cellCount}
*** Keywords ***
Open Excel Sheet
[Arguments] ${excelName}
Open Excel ${excelName} useTempDir=False
Get Values
[Arguments] ${sName} ${row} ${cCount}
Log to console user is in Get Values function
: FOR ${cindex} IN RANGE 0 ${cCount}
\ Log to console get the data from ${sName}[${cindex}][${row}]
\ ${cellValue} Read Cell Data By Coordinates ${sName} ${cindex} ${row}
\ Insert Into List ${rowValues} ${cindex} ${cellValue}
[Return] @{rowValues}
Login to the CLM
[Arguments] @{rowValues}
Open Browser http://172.20.24.74/clm-ui/#/login/ chrome
Maximize Browser Window
Sleep ${delay}
Input Text id=username @{rowValues}[0]
Input Password id=password @{rowValues}[1]
Click Button css=.btn.btn-primary
Remove Values
[Arguments] ${rowValues} ${cellCount}
Log to console rowvalues are : ${rowValues} and cell Count: ${cellCount}
: FOR ${index} IN RANGE 0 ${cellCount}
\ ${value}= Remove from List ${rowValues} -1
\ Log to console value removed from list is : ${value}
Change Language to English
Sleep ${delay}
Wait Until Element Is Visible xpath=//*[@id='top-navbar']/ul[2]/li/a/span[2] 30s
Click Element xpath=//*[@id='top-navbar']/ul[2]/li/a/span[2]
Click Element xpath=//*[@id='top-navbar']//a[contains(text(),'English')]
Logout from CLM
Sleep ${delay}
Click Element xpath=//*[@id='top-navbar']/ul[2]/li/a/span[2]
Click Link link=Logout
在输出中,它显示为已删除的值,但下一次运行时,它也显示旧值
结果如下:
===========================================================================================================
ReadExcel :: CLM Registration Test Case
===========================================================================================================
Get Data from Excel user is in Get Values function
get the data from LoginDetails[0][1]
get the data from LoginDetails[1][1]
row values are for index 1 : [u'akurasa', u'Srija210$']
rowvalues are : [u'akurasa', u'Srija210$'] and cell Count: 2
value removed from list is : Srija210$
value removed from list is : akurasa
user is in Get Values function
get the data from LoginDetails[0][2]
get the data from LoginDetails[1][2]
row values are for index 2 : [u'clmui', u'tecnotree', u'akurasa', u'Srija210$']
rowvalues are : [u'clmui', u'tecnotree', u'akurasa', u'Srija210$'] and cell Count: 2
value removed from list is : Srija210$
value removed from list is : akurasa
| PASS |
-----------------------------------------------------------------------------------------------------------
尝试使用关键字“createlist”作为FOR循环的最后一步,而不是用户定义的关键字“removevalues”。另外,如果每行的列数不同,则在循环中移动变量${cellCount}
Get Data from Excel
Open Excel Sheet ${excelName}
@{sheetNames} Get Sheet Names
${sheetName} Set Variable @{sheetNames}[0]
${rowCount} Get Row Count ${sheetName}
: FOR ${rindex} IN RANGE 1 ${rowCount}
\ ${cellCount} Get Column Count ${sheetName}
\ @{rowValues} Get Values ${sheetName} ${rindex} ${cellCount}
\ Log to console row values are for index ${rindex} : @{rowValues}
\ Login to the CLM @{rowValues}
\ Log cell count is : ${cellCount}
\ Change Language to English
\ Sleep ${delay}
\ Logout from CLM
\ @{rowValues} Create List
“@{rowValues}Create List”:此命令将清除列表中的值在我的情况下,我想要清除的列表是全局的,因此我无法使用Create List清除它。在这种情况下,a
:FOR ${elem} IN @{list}
Remove values from list ${list} ${elem}
帮助。Hi Rakesh,很抱歉,我没有告诉您,我必须在“创建列表”用户定义关键字中实现什么功能。“创建列表”是内置库中可用的库关键字。你不需要为它写任何脚本。只需在测试用例部分复制并粘贴上面的脚本。尝试并更新。