1、list变量就相当于多个参数,而不是一个参数的数组,一般用于传递未知个个数参数的方法。如果需要用string数组就直接用3,4,5,数字数组直接用${3,4,5}
2.list变量的对比需要用关键字:Lists Should Be Equal
这个需要import Collections
注意:@{list}是robot提供的语法,python并没有@{},只有${},所以要比较两个@{list},需要把@{list},直接写成${list}进行对比
List should be equl ${list a} ${list b}
*** Test Cases ***
Test List
@{list1}= Create List 1 2 3 # 生成一个list: [1,2,3]
@{list2}= Create List 1 2 3 # 生成一个list: [1,2,3]
@{list3}= Create List 1 2 # 生成一个list: [1,2]
Should Be Equal ${list1} ${list2} #list1和list2是相同的列表,比较结果相等
Should Not Be Equal ${list1} ${list3} #list1和list3是不同的列表,不相等
2、list排序,对比
#@{listA} #create list #1 #3 #2 #4
#@{listB} #create list #1 #2 #3 #4
Sort List ${listA}
Sort List ${listB}
should be equal ${listA} ${listB}
3、数组
*** Settings ***
Library Collections
*** Test Cases ***
TestCase001
${dict} create dictionary
set to dictionary ${dict} a=1 b=2 c=3
log ${dict}
4、 基本的循环 :FOR (综合一些关键词的组合运用)
${count} Convert To Integer 0 (因为系统默认是string类型,所以要先转换为整数)
@{item_list} Set Variable ${res['body'].response.list.find_all('item')} (BeautifulSoup中的findAll函数)
: FOR ${item} IN @{item_list}
log ${item}
${count}= Evaluate ${count}+1
log ${item.get('id')}
Should Not Be Empty ${item.get('playdual')}
Should Not Be Empty ${item.get('pubdate')}
should be equal ${count} ${num}
01、should contain 、 should not contain 与should contain x times
should contain ${list_b} ${b}
should not contain ${list_b} 1
should contain x times ${list_b} 21 2
说明:变量${list_b}包含对象 ${b} 而不包含对象1,且对象21在变量${list_b}出现了两次。
02、should be empty 与 should not be empty
should be empty ${list_c}
should not be empty ${list_a}
说明:变量${list_c}没有赋值,所以为空;相反,变量${list_a}有赋初始值,故为非空。
03、should be equal 与 should not be equal
should be equal ${res['body'].response.flag['code']}(取出节点属性) 0/${mobileNo}(都可以)
should not be equal ${res['body'].response.flag['code']} ${list_b}
说明:系统默认你给出的变量和0,1这样的数都是以string存储的;
04、Should Be Equal As Numbers 与 Should not Be Equal As Numbers
Should Be Equal As Numbers ${list_b[0]} 1.0000
Should not Be Equal As Numbers ${list_b[0]} 1.1
说明:${list_b[0]}=1,忽略精度,故与1.0000相等;而即使是忽略精度,1与1.1还是不相等的;
05、Should Be Equal As Integers与Should not Be Equal As Integers
Should Be Equal As Integers ${list_a[3]} ${list_b[3]}
Should not Be Equal As Integers ${list_a[4]} ${list_b[4]}
说明:${list_a[3]}=21,${list_b[3]}=21,而系统默认为字符串格式的“21”,故需要转化为整数类型,转化为整数后两个对象相等;
${list_a[4]}=12,${list_b[4]}=21,即使转化为整数后两个对象依旧是不相等;
06、Should Be Equal As Strings与Should not Be Equal As Strings
Should Be Equal As Strings ${list_a[2]} ${list_b[2]}
Should not Be Equal As Strings ${list_a[0]} ${list_b[0]}
说明:${list_a[2]}=${21},${list_b[2]}=${21},而均为数值型的21,故需要转化为字符串类型,转化为字符串后两个对象相等;
07、Should Be True与Should not Be True 这个是用于判断最常用的语句
should be true ${res['body'].response.userticketinfo['availabletickets']}<=${res['body'].response.userticketinfo['totaliickets']}
Should not Be True ${list_a[0]} < 10
说明:${list_a[0]}=1(字符串类型),其ASCII值比字符串10的ASCII值小;
08、Should start With与Should not start With
Should start With ${string} peng
Should not start With ${string} h
说明:${string}=”pengliwen is in hangzhou“是以peng开头,而非以h开头;
09、Should End With与Should not End With
Should End With ${string} hangzhou
Should not End With ${string} pengliwen
说明:${string}=”pengliwen is in hangzhou“是以hangzhou结尾,而非以pengliwen结尾;
10、should match与should not match
should match ${name} p??
should not match ${string} h?*
说明:模式匹配和shell中的通配符类似,它区分大小写,'*'匹配0~无穷多个字符,“?”单个字符
${name}=plw,由以p开头的三个字母组成
11、Should Match Regexp与Should not Match Regexp
Should Match Regexp ${name} ^\\w{3}$
Should not Match Regexp ${name} ^\\d{3}$
说明:反斜杠在测试数据是转义字符,因此模式中要使用双重转义;'^'和'$'字符可以用来表示字符串的开头和结尾
${name}=plw,是有三个字母--w{3}组成,而不是由三个数字--d{3}组成。
红包分享
钱包管理

