如何用数字检查列表,在 Robot Framework 中按数字顺序排列 [英] How can I check list with numbers, that is ordered numerically in Robot Framework

查看:49
本文介绍了如何用数字检查列表,在 Robot Framework 中按数字顺序排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在检查我的清单时遇到问题.实际上,我需要检查列表是否在 Robot Framework 中按数字顺序排列.

I have problem with checking my list. Actually I need check that list is ordered numerically in Robot Framework.

假设我们有一个列表

${nice}= ['13', '12', '10', '7', '6', '6', '6', '4', '3', '2', '2', '1', '1', '1', '0', '0']

我需要验证第一个元素大于第二个,第二个大于第三个等等.

I need to verify that the first element is greater than the second, the second greater than the third and so on.

问题是,Robot Framework 中的关键字排序列表"没有以正确的方式对数字列表进行排序.

Problem is, that in Robot Framework keyword 'Sort List' doesn't order number list in proper way.

决定之一是在机器人框架中调用 Python 方法 'sort' 或 'sorted',但也许有更好的方法来做到这一点?

One of the decision is to call Python method 'sort' or 'sorted' in robot framework, but maybe there is better way to do it?

推荐答案

你可以使用 python 的 sorted using Evaluate 关键字以降序获取列表元素,然后使用Lists should Be Equal 关键字比较它们

You can use python's sorted using Evaluate keyword to get the list elements in descending order and then use Lists Should Be Equal keyword to compare them

Import Library     Collections
@{nice}=    Create List    13    12    10    7    6    6    6    4    3    2    2    1    1    1    0    0                                              
${sorted}=    Evaluate     sorted(${nice}, key=int, reverse=True)                                                                                       
Lists Should Be Equal    ${nice}    ${sorted}   

这篇关于如何用数字检查列表,在 Robot Framework 中按数字顺序排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆