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 |

delete_request(uri, para, data, headers)[source]

Issues a HTTP DELETE request. headers 请求以字典格式的报头

encrypt_post(uri, para, body, headers)[source]

Issues a encrpyt or specific headers Http Post Request

para 键值字典或json格式

body 若需要加密,加密前键值字典或json格式格式,加密后是字符串格式
对于不需要加密的body,则为字典或json格式,json格式需在headers里指定Content-Type类型
headers 根据相应的请求加密算法定制请求头 键值字典格式,例如可包含时间戳,请求唯一标示符,对请求体的签名,用户Id等
返回的response 内容也是加密后的,需要相对应的解密算法来解密。 对于某些特殊的登录方式,可能需要在headers中加入与登录有关的字段,如id,key,token等,具体根据开发项目需求来.

Examples: | ${enres} | encrpyt post | {“c”:”100”} | ${enbody} | {‘Content-Type’:’text/plain’,’time’:’${strtime}’,’unique’:’${unique}’,’sign’:’${sign}’,’uid’:’‘,’ua’:’IOS/1.0’} | | ${res} | encrpyt post | /api/device/addDevice | None | {“deviceId”:”${deviceId}”} | {‘Content-Type’:’application/json’,’token’:’${token}’}|

get_request(uri, para=None, headers=None)[source]

Issues a HTTP Get Request.

para 追加在URL后面的参数,键值字典或Json格式,URL长度有限制,最多只能是1024字节.

uri 可以是请求路径,也可以是带host的url

headers 若不通过cookie登录,则可以在headers中填写与登录有关的字段(根据项目需求来)

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}’} | | ${res} | Get Request | /api/poctrecord/getGuide | None | {‘Content-Type’:’application/json’,’token’:’${token}’,’key’: ‘${key}’ |

head_request(uri, headers)[source]

Issues a HTTP HEAD request. headers 请求以字典格式的报头

post_file_request(uri, file, data=None, para=None, headers=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.

headers 若不通过cookie登录,则可以在headers中填写与登录有关的字段(根据项目需求来)

文件类型字段以参数或请求体参数传入

Examples: | ${res} | Post File Request | /cgi-bin/file/upload | {‘content’:open(‘Resources/Material/logo.jpg’,’rb’)} | {‘type’:’jpg’} | {‘access_token’:’${access_token}’} |

${res} | Post File Request | /api/file/upload | {‘MultiPart File’:open(‘${file}’,’rb’)} | None | None | {‘Content-Type’:’application/json’,’token’:’${token}’,’key’: ‘${key}’ |
post_request(uri, form_data=None, para=None, json_data=None)[source]

Issues a HTTP POST request. 此关键字只适用于普通post请求和用cookie 登录的post请求, 若需要利用headers里的特殊字段来登录,目前先用encrypt post 关键字,后面再修复

uri 请求路径

para 追加在URL后面的参数,键值字典或Json格式,URL长度有限制,最多只能是1024字节.

form_data 在POST请求的HTTP消息主体中发送的数据,键值字典。对应headers Content-Type:application/x-www-form-urlencoded

json_data 在POST请求的HTTP消息主体中发送的数据,json格式。 对应headers Content-Type:application/json

也可参考robotframework-requests库中Post Request关键字

Examples: | ${res} | Post Request | /checkUser.do | {‘userName’:’&{account}[username]’,’password’:’&{account}[password]’} | None |#登录接口获取cookie | ${res} | Post Request | /manualreply/addClassify | {‘name’:’${name}’} | None |None| | ${res} | Post Request | /api/device/addDevice | None | None | {“deviceId”:”${deviceId}”,”deviceName”:”${deviceName}”} |

class InterfaceLibrary.CheckResult.CheckResult[source]

docstring for CheckResult

check_code(response, expectcode)[source]

Check HTTP response code. response application/json type

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, timeflag=0)[source]

generate date based on current date,if you want to get the date with time, you can set the parameter timeflag as 1 Example usage: | Generate Date | 5 | # Only generate the date after 5 days from today eg:2016-09-13 | Generate Date | -5 | # Only generate the date before 5 days from today eg:2016-09-04 | Generate Date | 5 | 1 | Generate the date with time before 5 days from today eg:2016-09-08 10:30:20 | Generate Date | 0 | 1 | Generate the current date with time | Generate Date | Generate the current date.

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
json_to_dict(jsondata)[source]

Convert json form data to dict type

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

random_index(str, key)[source]

generate random int from http response keyword

Examples usage: | Random Index | ${res} | id | this examples return a int between 0 and id term length - 1