List output are not getting recognize for custom library in robotframework when json library is used and list is mix with unicode character

橙三吉。 提交于 2019-12-13 23:11:26

问题


Here three file list.robot , code.json is input file , Library file compareLib.py when i run this program, it always return False , i am expecting true since 30 is present in list all file are present in same folder

list.robot file

*** Settings ***
Library  SudsLibrary
Library  JSONLibrary
Library  OperatingSystem
Library  compareLib.py

*** Test Cases ***
test json data1
        # load file in json object
        ${json_obj}=    Get file  code.json
        ${obj}=  evaluate    json.loads('''${json_obj}''')    json
        log  ${obj}
        ${value} =   Get Value From Json    ${obj}  $..code_id
        #variable ${value} return list [20,30,40] from code.json file
        log to console   ${value}
        ${compare}  set variable  30
        ${contain} =  contain_number  ${value}  ${compare}
        log to console  ${contain}

sample code.json file start from array '[' then three block {} then array closing block ']'

lib file

here arg1 is list [20,30,40] and arg2 is 30 , i am expecting True but it returns false

def contain_number(arg1,arg2):
    if arg2 in arg1:
        return True
    else:
        return False

回答1:


The problem was when you pass the ${compare} variable from robotframework to python function , it was going as unicode string

so the comaprison was some thing like this ([30, 40, 30], u'30')

u'30' was not going to be found in the list that is ${Value}.

so i have converted the string passed from robotframework to integer in your Python file and that should work now

def contain_number(arg1,arg2):
    arg2=int(arg2)
    if arg2 in arg1:
        return True
    else:
        return arg1,arg2,False


来源:https://stackoverflow.com/questions/47417767/list-output-are-not-getting-recognize-for-custom-library-in-robotframework-when

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!