robotframework 找出重复元素
思路
一、把需要进行比较的元素取出来组装成一个list
二、利用python函数,从list中找出重复函数
python函数:
from collections import Counter #引入Counter
a = [11233,11233,44444,32311]
b = dict(Counter(a))
print ({key:value for key,value in b.items()if value> 1}) #展现重复元素和重复次数
robot robotframework:
#获取到的ID组装成一个list
${List_ID} Create List ${ID_1} ${ID_2} ${ID_3} ${ID_4} ${ID_5}
... ${ID_6} ${ID_7} ${ID_8} ${ID_9} ${ID_10}
sleep 1
#用python函数找出重复的ID以及重复次数
${Dict} Evaluate dict(collections.Counter(${List_ID})) collections
${Duplicate_ID} Evaluate ({key:value for key,value in ${Dict}.items()if value > 1})
注意点:在robot robotframework中Counter的引入
在未引入Counter时,运行会报一个错failed: NameError: name 'Counter' is not defined
解决方案
dict(collections.Counter(${List_ID}))