Robotframework 如何在robot框架上使用run关键字

Robotframework 如何在robot框架上使用run关键字,robotframework,Robotframework,我正在写一个关于robot框架的代码,它是关于比较excel文件和mysql数据库之间的数据。在我的代码中,我可以成功地比较数据,但如果有不匹配的情况,我想知道在哪个列中。如果我需要更详细地解释,我有66列,我知道它们的名称,因为它是在excel文档中编写的,让我们想想excel和数据库之间有两个不匹配的地方,我编写的代码给了我错误的值,如 1) Lists are different: Index 0: 905390000510 != 905390000511 2) Lists are di

我正在写一个关于robot框架的代码,它是关于比较excel文件和mysql数据库之间的数据。在我的代码中,我可以成功地比较数据,但如果有不匹配的情况,我想知道在哪个列中。如果我需要更详细地解释,我有66列,我知道它们的名称,因为它是在excel文档中编写的,让我们想想excel和数据库之间有两个不匹配的地方,我编写的代码给了我错误的值,如

1) Lists are different:
Index 0: 905390000510 != 905390000511 
2) Lists are different:
Index 0: 88975322100222 != 88975322100332
但每次都是写索引0,所以我不知道错误在哪里。所以我需要在anywhere中将if子句添加到我的代码中,但我还没有实现它,因为当我想使用
RUN关键字
if语句时,我得到了所有的列名,但我只需要得到2。我怎样才能解决它?我在下面添加我的代码

*** Test Cases ***
open first excel file

    connect to database  pymysql  testdb  root  rootpass  localhost  3306
    :FOR    ${i}    IN RANGE    2  67
    \   open excel document  ${path1}  ${i}
    \   ${cname}  read excel cell  1  ${i}  Sheet2
    \   ${value1}=  read excel cell  2  ${i}  Sheet2
    \   @{list1}  create list  ${value1}
    \   @{queryResults}=  query  select a_${i} from test_table where a_1 = 'filename1'
    \   run keyword and continue on failure  lists should be equal  ${list1}  @{queryResults}
    \   run keyword if  "${list1}" !=" ${queryResults}"  log to console  ${cname}

我的excel文件在第一行中包含列名,在第二行中包含数据。

虽然您的脚本包含一个列表比较,但在我看来,这不是一个列表比较,而是一个值比较,应该会产生如下消息

第“1”行第“BBBB”列中的值2222!=4444

下面是一个示例,在生成错误消息时,比较两个列表的值,并从第三个列表检索列名:

*** Settings ***
Library    Collections

*** Test Cases ***
Compare List
    ${ListColumns}    Create List    AAAA    BBBB    CCCC     
    ${ListA}          Create List    1111    2222    3333
    ${ListB}          Create List    1111    4444    3333

    FOR    ${i}    IN RANGE    0    2
        run keyword and continue on failure  
        ...       should be equal as Strings      
        ...            @{ListA}[${i}]      
        ...            @{ListB}[${i}]
        ...            values=False
        ...            msg=In Row "${1}" Column "${ListColumns}[${i}]" value @{ListA}[${i}] != @{ListB}[${i}].
    END
此脚本将产生以下控制台输出:

==============================================================================
Compare List                                                          | FAIL |
In Row "1" Column "BBBB" value 2222 != 4444.
------------------------------------------------------------------------------
SO004.Compare                                                         | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
SO004                                                                 | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
记住这一点,您可以通过这种方式将其应用于脚本。请记住,下面的代码未经测试,但应该可以工作

Open First Excel File

    Connect To Database  pymysql  testdb  root  rootpass  localhost  3306

    FOR    ${i}    IN RANGE    2    67
        # Get the value and column
        open excel document  ${path1}  ${i}
        ${ColumnName}      read excel cell  1  ${i}  Sheet2
        ${Excelvalue}      read excel cell  2  ${i}  Sheet2   

        # This is a nested list where the @{queryResults}[0][0] means the first column from the first row.
        @{queryResults}    query  select a_${i} from test_table where a_1 = 'filename1'

        run keyword and continue on failure  
        ...       should be equal as Strings      
        ...            @{ListA}[${i}]      
        ...            @{ListB}[${i}]
        ...            values=False
        ...            msg=In Row "${1}" Column " ${ColumnName}" value ${Excelvalue} != @{queryResults}[0][0].
    END