Robotframework 如何使用robot框架将两个值作为字符串进行比较?

Robotframework 如何使用robot框架将两个值作为字符串进行比较?,robotframework,Robotframework,当对象不相等但它们是字符串时,如何匹配值。 ${tab}=Get Text xpath=./[@id='projectTable\u info']${已选中 text}=Fetch从${selected text}=Fetch的右侧${tab}获取 从${sele}的右${tab}=从左${Fetch selected text}entries${empno}=获取表格单元格 xpath=./[@id='projectTable']3 6获取值${empno} ${only value}=Fet

当对象不相等但它们是字符串时,如何匹配值。

${tab}=Get Text xpath=./[@id='projectTable\u info']${已选中 text}=Fetch从${selected text}=Fetch的右侧${tab}获取 从${sele}的右${tab}=从左${Fetch selected text}entries${empno}=获取表格单元格
xpath=./[@id='projectTable']3 6获取值${empno} ${only value}=Fetch from Right${empno}|应该是字符串 ${only value}${sele}转换为字符串${only value}转换 到字符串${sele}应等于${only value}${sele}

它在控制台中给出错误 如果对象在转换为字符串后不相等,则失败。 信息参数类型为:
失败2!=2

在进行比较之前,可以使用将值转换为字符串的

Should be equal as strings    ${only value}    ${sele}
您的代码似乎试图手动将值转换为字符串,这也是一个合理的解决方案。不幸的是,的文档有点模糊,导致您错误地使用它。关键字不会更改参数,它会返回一个新字符串

如果要手动转换变量,则需要如下操作:

${sele}=          Convert to string    ${sele}
${only value}=    Convert to string    ${only value}
Should be equal   ${only value}    ${sele}
在进行比较之前,可以使用将值转换为字符串的

Should be equal as strings    ${only value}    ${sele}
您的代码似乎试图手动将值转换为字符串,这也是一个合理的解决方案。不幸的是,的文档有点模糊,导致您错误地使用它。关键字不会更改参数,它会返回一个新字符串

如果要手动转换变量,则需要如下操作:

${sele}=          Convert to string    ${sele}
${only value}=    Convert to string    ${only value}
Should be equal   ${only value}    ${sele}

此脚本尝试将输入转换为浮点,并比较Python 2中的值:

def should_be_x_than (self, number1, relation, number2):
    '''
    This keyword makes relation between 2 numbers (it converts them to number)
    Accepted relations:
    < > <= => =
    '''
    if relation =="<":
        return float(number1) < float(number2)
    if relation ==">":
        return float(number1) > float(number2)
    if relation =="=>":
        return float(number1) >= float(number2)
    if relation =="<=":
        return float(number1) <= float(number2)
    if relation =="=":
        return float(number1) == float(number2)

此脚本尝试将输入转换为浮点,并比较Python 2中的值:

def should_be_x_than (self, number1, relation, number2):
    '''
    This keyword makes relation between 2 numbers (it converts them to number)
    Accepted relations:
    < > <= => =
    '''
    if relation =="<":
        return float(number1) < float(number2)
    if relation ==">":
        return float(number1) > float(number2)
    if relation =="=>":
        return float(number1) >= float(number2)
    if relation =="<=":
        return float(number1) <= float(number2)
    if relation =="=":
        return float(number1) == float(number2)

也许使用evaluate是最简单的,尤其是当rc需要时

[Documentation]    = / compare two string \ =
${rc}=    evaluate    'name'=='theon'
Log To Console   \n${rc}

也许使用evaluate是最简单的,尤其是当rc需要时

[Documentation]    = / compare two string \ =
${rc}=    evaluate    'name'=='theon'
Log To Console   \n${rc}

您的代码是乱码。这里有越来越多更好的选项来比较字符串-您的代码是乱码。这里有越来越多更好的选项来比较字符串-“应与字符串相等”可能无法解决值为和时的问题\然而,“应该等于整数”不会有这种副作用,这是推荐的\我用它来表示HTTP状态码。@GaGa_Ek:正确。然而,这个问题是关于比较字符串,而不是整数。当值为和时,“应等于字符串”可能无法解决问题\然而,“应该等于整数”不会有这种副作用,这是推荐的\我用它来表示HTTP状态码。@GaGa_Ek:正确。然而,这个问题是关于比较字符串,而不是整数。