zoukankan      html  css  js  c++  java
  • 【Robot Framework】List 的相关使用方法

    List在编程里面是非常重要的一个数据结构,也有丰富的用法,不过,RF虽然虽然封装比较好,但和直接用python比起来,灵活性真的是非常差啊

    先还是祭出官方文档 http://robotframework.org/robotframework/latest/libraries/Collections.html

    使用前需要导入Collections库,这个库在RobotFramework中主要是用来处理列表和字典的

    本文呢主要介绍下List的相关用法,字典的处理留到后面再说

     1.创建列表 Create List

    20190927 15:08:05.612 : INFO : ${list} = ['1', '2', '3']
    20190927 15:08:05.612 : INFO : ['1', '2', '3']

    2.Append To List

    Adds values to the end of list. 向列表的末尾追加元素

     20190927 15:17:31.460 : INFO : ${list} = ['1', '2', '3']

    20190927 15:17:31.461 : INFO : ['1', '2', '3', 'a', 'b', 'c']

    3.Combine Lists 合并两个列表,并返回合并后的结果

    值得注意的是,合并后,原来的两个列表并没有改变

    20190927 15:20:48.277 : INFO : ${list_1} = ['1', '2', '3']
    20190927 15:20:48.277 : INFO : ${list_2} = ['a', 'b', 'c']
    20190927 15:20:48.278 : INFO : ${list_3} = ['1', '2', '3', 'a', 'b', 'c']
    20190927 15:20:48.279 : INFO : ['1', '2', '3']
    20190927 15:20:48.279 : INFO : ['a', 'b', 'c']
    20190927 15:20:48.280 : INFO : ['1', '2', '3', 'a', 'b', 'c']

    4.Copy List 复制一个列表

    20190927 15:25:10.654 : INFO : ${list_1} = ['1', '2', '3']
    20190927 15:25:10.655 : INFO : ${list_2} = ['1', '2', '3']
    20190927 15:25:10.655 : INFO : ['1', '2', '3']
    20190927 15:25:10.656 : INFO : ['1', '2', '3']

    5.Get From List 从列表中取值

    Index 0 means the first position, 1 the second, and so on. Similarly, -1 is the last position, -2 the second last, and so on.

    Using an index that does not exist on the list causes an error. The index can be either an integer or a string that can be converted to an integer.

    index为0时,取第一个元素,-1时取最后一个,以此类推。如果index越界,就会报错 

     

    20190927 15:30:49.936 : INFO : ${list} = ['1', '2', '3', 'a', 'b', 'c']
    20190927 15:30:49.937 : INFO : ${x} = 1
    20190927 15:30:49.937 : INFO : ${y} = 2
    20190927 15:30:49.938 : INFO : ${z} = c

    5.Get Index From List 返回给定值得索引

    20190927 15:33:34.884 : INFO : ${list} = ['1', '2', '3', 'a', 'b', 'c']
    20190927 15:33:34.885 : INFO : ${x} = 5

    6.Get Slice From List 数组切片

    两个参数(start,end),如果两个参数都给定了,则返回两个参数之间的值,就像python里面的 list[start:end]

    如果end值缺省,则返回从start开始后面所有的值。start缺省同理

    如果值为附属,则从末尾开始计数

    20190927 15:43:08.480 : INFO : ${list} = ['1', '2', '3', 'a', 'b', 'c']
    20190927 15:43:08.481 : INFO : ${x} = ['3', 'a', 'b']
    20190927 15:43:08.482 : INFO : ${y} = ['3', 'a', 'b', 'c']
    20190927 15:43:08.483 : INFO : ${z} = ['b', 'c']

    7.Insert Into List 往list中插入数值

    20190927 15:46:35.575 : INFO : ${list} = ['1', '2', '3']
    20190927 15:46:35.576 : INFO : ['hahah', '1', '2', '3']
    20190927 15:46:35.577 : INFO : ['hahah', '1', '2', 'oooo', '3']

    8.Remove From List 根据索引移除列表中的值

    20190927 15:56:50.199 : INFO : ${list} = ['name1', 'name2', 'name3']
    20190927 15:56:50.201 : INFO : ['name1', 'name3']

    9.Remove Values From List 根据values移除列表里面的值

    20190927 15:58:07.931 : INFO : ${list} = ['name1', 'name2', 'name3']
    20190927 15:58:07.933 : INFO : ['name2']

    10.Reverse List 倒转列表

    20190927 16:32:09.760 : INFO : ${list} = ['name1', 'name2', 'name3']
    20190927 16:32:09.762 : INFO : ['name3', 'name2', 'name1']

    11.Set List Value 更新列表中的某一个值

    20190927 16:34:16.284 : INFO : ${list} = ['name1', 'name2', 'name3']
    20190927 16:34:16.286 : INFO : ['xxx', 'name2', 'name3']

    12.Sort List 列表排序

    如果是字母则根据字母表排序,如果是数字,则根据数字排序

    20190927 16:37:00.375 : INFO : ${list} = ['b', 'a', 'c', '5', '2', '9']
    20190927 16:37:00.376 : INFO : ['2', '5', '9', 'a', 'b', 'c']

  • 相关阅读:
    Javascript正则表达式详解转载
    转载Sqlserver2005 存储过程分页
    转载手把手教你用C#打包应用程序
    学习内容
    用C#实现将HTML文件转换为CHM文件(转)
    C# Windows服务添加安装程序
    sql 2008评估期已过有关如何升级,企业试用版到期,升级为企业版+sql2008破解
    iis不能启动是什么原因?错误提示:“提示服务器没有及时相应启动或控制请求”
    .NET 获取数据库中所有表名的方法
    如何获取Dynamics当前登录的用户的GUID,进而获取用户的信息
  • 原文地址:https://www.cnblogs.com/ronyjay/p/11598107.html
Copyright © 2011-2022 走看看