如何在Robot Framework中清除或删除列表中的值

问题描述:

我编写了一个Testcase,它将从Excel工作表读取登录详细信息,并为每对细节登录和注销。如何在Robot Framework中清除或删除列表中的值

我正在从Excel中读取数据,每行详细信息我传递给列表并将其作为输入发送到另一个关键字/函数进行登录。

注销后,我只想删除列表中的值,它显示为成功,但在下次运行时它也显示旧值。

我搜索了,我没有得到任何关键字来清除所有列表值。

有人可以帮我解决这个问题。下面的代码是:

*** 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 | 
----------------------------------------------------------------------------------------------------------- 

尝试使用关键词“创建列表”作为FOR循环的最后一步而不是“删除值”用户定义的关键字。此外,将变量$ {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}创建列表”变化:该命令将显示在列表

+0

拉克什喜清除值,抱歉,我没有得到你,我必须在“创建列表”用户定义的关键字中实现哪些功能。 –

+0

“创建列表”是在BuiltIn库中可用的库关键字。你不需要为它编写任何脚本。只需在测试用例部分复制并粘贴上述脚本。尝试它并更新。 – Rakesh

+0

谢谢Rakesh,它工作。 –