python BDD API测试
1. 配置内网
确认能登录 https://deopcard.corp.OOOO.com/ui/builds
Artifacts>set me up>search: pypi> Get the info as below in resolve tab
在这个文件夹路径下 :Users->username->AppData->Roaming->pip
pip内容
[global]
index-url = https://suehlsu:APA7W98qEsw2WoxQSrQWvunXWT9@deopcard.corp.hkjc.com/artifactory/api/pypi/pypi-remote/simple
trusted-host = deopcard.corp.OOOO.com
2. pycharm里面创建项目
配置File -> Settings
3. 安装插件
File -> Settings -> Plugins 安装Gherkin
4. 虚拟环境操作
项目窗口的下面打开Terminal 窗口
pipenv shell 命令,进入虚拟环境
安装 requests 和 behave :
pip install request
pip install behave
5. 写API case
5.1 feature 文件
1 2 3 4 5 6 | Feature: Python BDD test Scenario: Introduce yourself Given What is your name When How old are you Then Where do you live |
5.2 写方法文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import requests from behave import * from requests import * @given ( 'What is your name' ) def tellName(context): print ( "My name is A." ) headers = { "Accept" : "application/json,text/javascript, */*" , "X-Requested-With" : "XMLHttpRequest" } url = "http://10.194.109.125/EnvironmentMonitor/ICSQuickLogin" response = requests.get(url, headers = headers) print ( type (response)) txt = str (response.text) print (response.text) file = open ( 'response/response.txt' , mode = 'a' ) file .write(response.text) file .flush() file .close() @when ( 'How old are you' ) def tellAge(context): print ( "I'm 100 years old." ) @then ( 'Where do you live' ) def tellLocation(context): print ( "I live in SZ." ) |
终端窗口执行case命令behave
6. 生成报告
安装Allure
带参数执行下面命令,查看报告
behave -f allure_behave.formatter:AllureFormatter -o result ./features
File --> Reload All from Disk
7. behave学习地址
https://behave.readthedocs.io/en/stable/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架