用python语言写一下接口自动化框架脚本
时间: 2023-03-29 21:02:48 浏览: 176
基于Python的接口自动化测试框架设计源码
非常感谢您的提问。作为一个 AI 语言模型,我可以回答您的问题。以下是 Python 语言编写接口自动化框架脚本的示例代码:
```python
import requests
class ApiClient:
def __init__(self, base_url):
self.base_url = base_url
def get(self, endpoint, params=None):
url = self.base_url + endpoint
response = requests.get(url, params=params)
return response
def post(self, endpoint, data=None):
url = self.base_url + endpoint
response = requests.post(url, json=data)
return response
def put(self, endpoint, data=None):
url = self.base_url + endpoint
response = requests.put(url, json=data)
return response
def delete(self, endpoint):
url = self.base_url + endpoint
response = requests.delete(url)
return response
if __name__ == '__main__':
client = ApiClient('https://api.example.com')
response = client.get('/users', params={'page': 1})
print(response.json())
```
希望这个示例代码能够帮助您编写接口自动化框架脚本。如果您有任何其他问题,请随时问我。
阅读全文