当我试图递增一个变量时,无法将变量与字典中的值进行比较。

问题描述 投票:0回答:1

假设如果 ${x} 是dictionary,并且具有 {'a':'4','b':'3'}. 请看下面的代码。我在递增数值后收到错误信息。而这个变量${count}在递增前后的类型都是'int'。

${count}=       set variable    3
Dictionary Should Contain Value      ${x}       ${count}  ##--------> True
${Count}=    Evaluate    ${Count}+1
Dictionary Should Contain Value      ${x}}       ${count}  ##-------> Doesnot contain value '4'
robotframework robotframework-ide
1个回答
0
投票

您的变量 ${count} 开头不是整数,而是字符串.Integer在机器人框架中必须这样设置。它是字符串.Integer必须在Robot Framework中这样设置。${count}= set variable ${3}

在您的 Evaluate 你有一个整数,因为 3+1 评价为 4

你的字典有字符串作为值。{'a':'4','b':'3'}所以第一个调用是有效的,因为你期望字符串 "3" 第二次调用失败,因为整数的 4 ins不等于字符串 "4"

这段代码可以用。

*** Settings ***
Library           Collections

*** Variables ***
&{x}              a=4    b=3

*** Test Cases ***
test
    ${count}=    set variable    3
    Dictionary Should Contain Value    ${x}    ${count}
    ${Count}=    Evaluate    str(${Count}+1)
    Dictionary Should Contain Value    ${x}    ${count}
© www.soinside.com 2019 - 2024. All rights reserved.