测试框架基本能力
- 项目管理:pip、 virtualenv
- 用例编写:pytest
- 领域能力:app、 web、http
- 执行调度:pytest、pycharm、shell、jenkins
- 测试报告:allure2
HTTP测试能力
- 请求方法构造:get、post、put、delete、head... ...
- 请求体构造:form、json、xml、binary
- 响应结果分析:status code、response body、json path、xpath
Requests框架特点
Requests常见http请求构造方法
import requests
r = requests.put('https://httpbin.org/put', data={'key':'value'})
r = requests.delete('https://httpbin.org/delete')
r = requests.head('https://httpbin.org/get')
r = requests.options('https://httpbin.org/get')
实战环节
import requests
class TestDemo:
def test_get(self):
r = requests.get("http://httpbin.testing-studio.com/get")
print(r.status_code)
print(r.text)
print(r.json())
assert r.status_code == 200
test_requests.py::TestDemo::test_get
============================== 1 passed in 0.76s ==============================
Process finished with exit code 0
PASSED [100%]200
{
"args": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Host": "httpbin.testing-studio.com",
"User-Agent": "python-requests/2.25.0",
"X-Forwarded-Host": "httpbin.testing-studio.com",
"X-Scheme": "https"
},
"origin": "101.205.253.7",
"url": "https://httpbin.testing-studio.com/get"
}
{'args': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Host': 'httpbin.testing-studio.com', 'User-Agent': 'python-requests/2.25.0', 'X-Forwarded-Host': 'httpbin.testing-studio.com', 'X-Scheme': 'https'}, 'origin': '101.205.253.7', 'url': 'https://httpbin.testing-studio.com/get'}