Robot Framework:Httplibrary库

1. source installation, download url: https://github.com/peritus/robotframework-httplibrary/

2.RF import library: HttpLibrary.HTTP

3. Use the keywords and description

Keyword

Use description

DELETE

Sending to the server http delete request, which receives a parameter [URL], post request and the request is very similar manner, Example:

DELETE

/_utils/config.htm

 

HEAD

Sending to the server http HEAD request which receives a parameter [URL], get request and the request is very similar manner, Example:

HEAD

/_utils/config.htm

 

PUT

Sending to the server http PUT request that receives a parameter [URL], post request and the request is very similar manner, Example:

PUT

/_utils/config.htm

 

Get Json Value

Gets the value of a node Json string, examples:

${value}

Get Json Value

{"foo": {"bar": [1,2,3]}}

/foo/bar

Should Be Equal

${value}

[1, 2, 3]

 

 

 

Json Value Should Equal

This assertion is a keyword used to determine a node value corresponding json string is not consistent with the expected and, examples:

${json}

Set Variable

{"foo": {"bar": [1,2,3]}}

 

 

Json Value Should Equal

${json}

/foo/bar

[1, 2, 3]

 

Json Value Should Not Equal

This is an assertion key to determine if an node json string corresponding value is not expected and inconsistent, when inconsistent, is successful, otherwise fails, example:

${json}

Set Variable

{"foo": {"bar": [1,2,3]}}

 

 

Json Value Should Not Equal

${json}

/foo/bar

[1, 2, 3]

 

Log Response Body

Response Body print out the contents of the http request to execute the request or get general keywords after issuing a request to use the post. The request receiving a parameter [log_level = INFO], when no incoming log level parameter, the level of use info to the default print log.

Log Response Headers

打印出http请求执行后的 Response Headers内容,该关键字一般在post请求或者get请求发出后使用。该请求接收一个参数[ log_level=INFO ],在没有传入日志级别参数时,默认使用info级别来打印日志。

Log Response Status

打印出http请求执行后的 Response Status状态码,该关键字一般在post请求或者get请求发出后使用。该请求接收一个参数[ log_level=INFO ],在没有传入日志级别参数时,默认使用info级别来打印日志。

Response Body Should Contain

这是一个断言关键字,用来判断http请求响应后的Response Body 中应该需要包含的内容,该关键字接收一个参数[ should_contain(包含的内容) ],示例:

GET

/foo.xml

Response Body Should Contain

version="1.0"

Response Body Should Contain

encoding="UTF-8"

 

Response Header Should Equal

这是一个断言关键字,用来判断http请求响应后的Response Header是否和预期一致,该关键字接收两个参数[ header_name | expected ],示例:

Response Header Should Equal

Content-Type

text/html; charset=utf-8

 

Response Header Should Not Equal

这是一个断言关键字,用法和Response Header Should Equal刚好相反,用来判断http请求响应后的Response Header是否和预期不一致,在不一致时,执行成功,否在执行失败,该关键字接收两个参数[ header_name | not_expected ],示例:

Response Header Should Equal

Content-Type

text/html; charset=utf-8

 

Response Should Have Header

这是一个断言关键字,用来判断http请求响应后的Response Header中是否包含预期的header名称,该关键字接收一个参数[ header_name ],示例:

Response Should Have Header

Content-Type

 

Response Should Not Have Header

这是一个断言关键字,用来判断http请求响应后的Response Header中是否不包含预期的header名称,该关键字接收一个参数[ header_name ],示例:

Response Should Not Have Header

Content-Type

 

Response Status Code Should Equal

这是一个断言关键字,用来判断http请求响应后的Response status code是否和预期一致,该关键字接收一个参数[ status_code ],示例:

Response Status Code Should Equal

200

 

Response Status Code Should Not Equal

这是一个断言关键字,用来判断http请求响应后的Response status code是否和预期不一致,在不一致时,执行成功,否在执行失败,该关键字接收一个参数[ status_code ],示例:

Response Status Code Should Not Equal

200

 

Set Http Host

该关键字用来设置http请求时的host名称,现在一般该关键字已经很少用了,推荐使用Create HTTP Context关键字来替代该关键字。

Set Basic Auth

该关键字用来设置http请求时的Basic Auth(Basic Auth简单点说明就是每次请求API时都提供用户的username和password。),该关键字接收两个参数[ username | password ]

Set Json Value

该关键字用来设置json字符串中某个节点的值,示例:

${json}

Set Json Value

{"foo": {"bar": [1,2,3]}}

/foo

12

Should Be Equal

${json}

{"foo": 12}

 

 

 

Log Json

该关键字用来打印json字符串的内容,示例:

Should Be Equal

{"foo": {"bar": [1,2,3]}}

INFO

 

Stringify Json

该关键字用来将数据转换为json形式的字符串,示例:

${data}

Create List

a b c

${json_string}

Stringify JSON

${data}

log

${json_string}

 

 

Show Response Body In Browser

使用默认的浏览器来显示最后一次http请求的response body

Should Be Valid Json

该关键字是一个断言关键字,用来判断某个字符串是不是一个有效的json字符串,示例:

Should Be Valid Json

["a b c"]

 

Parse Json

该关键字用来解析一个json字符串,示例:

${json}

Parse Json

{"foo": {"bar": [1,2,3]}}

log

${json}

 

 

Next Request Should Succeed

该关键字用来判断,在存在多次请求时,下一次请求应该需要执行成功,使用该关键字时,一般需要存在至少两次请求,http请求中,很多请求都有一个特性,那就是幂等,比如get 请求,head请求等,都是幂等的请求,即执行一次和执行多次,都应该是成功的,返回的结果应该都是一致的。在执行第二次http请求时,返回的http code>=400时,会认为第二次请求执行失败了,示例:

GET

/user/signin/aa.htm

Next Request Should Succeed

 

GET

/user/signin/aa.htm

 

Next Request Should Not Succeed

该关键字用来判断,在存在多次请求时,下一次请求不应该执行成功,使用该关键字时,一般需要存在至少两次请求,http请求中,也有很多请求是非幂等的,比如常用的post请求,就是一个典型的非幂等请求,即执行一次和执行多次,执行的结果不一定都是一致的。在执行第二次http请求时,返回的http code<400时,会认为第二次请求执行成功了,示例:

POST

/user/signin

Next Request Should Not Succeed

 

POST

/user/signin

 

Next Request Should Have Status Code

该关键字用来判断,在存在多次请求时,下一次http请求返回的code值是否和预期一致,示例:

POST

/user/signin

Next Request Should Have Status Code

302

POST

/user/signin

 

Next Request May Not Succeed

该关键字和Next Request Should Succeed关键字很类似,使用该关键字时,一般需要存在至少两次请求,在下一次请求返回的http code>=400时,会认为下一次请求是执行失败了。示例:

POST

/user/signin

Next Request May Not Succeed

 

POST

/user/signin

 

 

Guess you like

Origin www.cnblogs.com/channy14/p/11410713.html