Interface testing Keywords methods¶
-
class
InterfaceLibrary.HttpLibrary.
HttpLibrary
[source]¶ Http Client
-
create_session
(host, port, Alias)[source]¶ Create Session : 创建一个连接host server的HTTP会话
Alias 对当前会话指定别名,在Http请求中可用于识别在高速缓存中的Session对象
也可参考robotframework-requests库中create session关键字
Examples: | Create Session | &{enviro}[host] | &{enviro}[port] | alias |
-
encrypt_post
(para, body, headers)[source]¶ Issues a encrpyt Http Post Request
para 键值字典或json格式
body 加密后的请求体。加密前键值字典格式,加密后可能是字符串格式
headers 根据相应的请求加密算法定制请求头 键值字典格式,例如可包含时间戳,请求唯一标示符,对请求体的签名,用户Id等 返回的response 内容也是加密后的,需要相对应的解密算法来解密。
Examples: | ${enres} | encrpyt post | {“c”:”100”} | ${enbody} | {‘Content-Type’:’text/plain’,’time’:’${strtime}’,’unique’:’${unique}’,’sign’:’${sign}’,’uid’:’‘,’ua’:’IOS/1.0’} |
-
get_request
(uri, para=None)[source]¶ Issues a HTTP Get Request.
para 追加在URL后面的参数,键值字典或Json格式,URL长度有限制,最多只能是1024字节.
uri 可以是请求路径,也可以是带host的url
Examples: | ${res} | Get Request | /cgi-bin/jssdk/ticket / {‘access_token’:’${acces_token}’}
|${res} | post request | /weblogin/user/generate | {“mac”:”${mac}”} | None | | ${resdic} | Evaluate | ${res} | | Set Suite Variable | ${url} | ${resdic[‘result’][‘url’]} | | ${res} | get request | ${url} | {‘uid’:’${uidencode}’,’timestamp’:’${strtime}’,’signature’:’${sign}’,’unique’:’${unique}’} |
-
post_file_request
(uri, file, data=None, para=None)[source]¶ Issues a HTTP Post Request to upload file.
file file must be dictionary of {filename: fileobject} files to multipart upload.
para dictionary of URL parameters to append to the URL.
data the body to attach to the request must be a python dictionary.
文件类型字段以参数或请求体参数传入
Examples: | ${res} | Post File Request | /cgi-bin/file/upload | {‘content’:open(‘Resources/Material/logo.jpg’,’rb’)} | {‘type’:’jpg’} | {‘access_token’:’${access_token}’} |
-
post_request
(uri, data=None, para=None)[source]¶ Issues a HTTP POST request.
uri 请求路径
para 追加在URL后面的参数,键值字典或Json格式,URL长度有限制,最多只能是1024字节.
data 在POST请求的HTTP消息主体中发送的数据,键值字典或Json格式
也可参考robotframework-requests库中post request关键字
Examples: | ${res} | Post Request | /checkUser.do | {‘userName’:’&{account}[username]’,’password’:’&{account}[password]’} | None |#登录接口获取cookie | ${res} | Post Request | /manualreply/addClassify.p | {‘name’:’${name}’} | None |
-
-
class
InterfaceLibrary.CheckResult.
CheckResult
[source]¶ docstring for CheckResult
-
check_code
(response, expectcode)[source]¶ Check HTTP response code.
Examples usage: | Check | {“data”:”null”,”code”:”200”,”msg”:”添加成功”}| 200 |
-
check_if_exists_in_database
(sql)[source]¶ Check if no rows would be returned by given the input ‘SQL’statement. If there are any results, then this will throw an AssertionError.
Example usage: | Check If Not Exists In Database | SELECT name,company_id FROM elf_staff_tab WHERE id=337 |
-
check_if_not_exists_in_database
(sql)[source]¶ Check if no rows would be returned by given the input selectStatement. If there are any results, then this will throw an AssertionError.
Example usage: | Check If Not Exists In Database | SELECT name,remark FROM elf_activity_tab WHERE id=337 | If the id is not exist, the output is:No date return #pass
-
connect_to_database
(dbname, dbusername, dbpassword, dbhost, dbport=3306)[source]¶ Example usage: | Connect To Database | dbname | dbusername | dbpassword | dbhost |
-
delete_rows_from_table
(condition, table)[source]¶ Delte all the rows within a given table and condition.
Example usage: | Delete Rows FROM Table | id=337 | elf_activity_tab |
-
execute_mysql_script
(sqlScriptFileName)[source]¶ Executes the sql sript file of the sqlScriptFileName as SQL commands. lines that starts with a number sign (#,`–) are treated as a commented line. The sql script can include `begin end function.
Examples usage: | Execute Mysql Script | ${CURDIR}test_scriptsqlfile.sql |
-
generate_date
(days=0)[source]¶ generate date based on current date Example usage: | Generate Date | 5 | # Generate the date after 5 days from today | Generate Date | -5 | # Generate the date before 5 days from today
-
generate_random_int
(n2, n1=1)[source]¶ generate random int between n1 and n2
Examples usage: | Generate Random Int | 100 |
Generate Random Int | 100 | 5
-
mysql_select
(sql)[source]¶ Execute mysql SELECT statement,now it default handle the fist row of the select datas, if select one element,it return a string,if select multiple elements,it return a list.
Examples usage: | Mysql Select | SELECT name FROM elf_activity_tab WHERE ID = 3| this examples return a string
Mysql Select | SELECT name,remark FROM elf_activity_tab WHERE ID = 3|this examples return a list
-