文章目录
我的第一个自动化测试
本文章介绍python+pytest+allure自动化测试的搭建。使用vscode进行编写运行,POM模式,pytest框架,allure生成测试结果。
vscode
1.vscode介绍
17年用pycharm写过一个简单的自动化脚本,当时是学习selenium以及实践应用。
19年再次想编写脚本时,pycharm控制比较严格,一直提示需要输入码,所以改用vscode,使用起来发现vscode除了使用门槛比pycharm高一点,其他都还是非常不错的。
推荐指数*****
vscode是微软出品的编程软件,有以下特点:
1、 占用内存低
2、 代码补全,比较人性化
3、 加载文件无压力
4、 界面设计杠杠的
5、 多插件安装
6、 内置Git
2.vscode 配置
虽说优点很多,但是使用起来,需要很多自己的配置。(可能会有不对的地方,需要大家指出)
launch.json配置:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python:Debug",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "D:\\Program Files\\Python38\\python.exe",
//"pythonPath": "${command:python.interpreterPath}",
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
},
{
"name": "PyTest",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "D:\\Program Files\\Python38\\python.exe",
"module":"pytest",
"args": [
"-sv",
"--disable-pytest-warnings",
"--html=report.html"
],
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
},
{
"name": "PyTest: Debug",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "D:\\Program Files\\Python38\\python.exe",
"module":"pytest",
"args": [
"-sv",
"--disable-pytest-warnings",
"--html=report.html"
],
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
},
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"host": "localhost",
"port": 3000
}
]
}
setting.json
{
"python.pythonPath": "D:\\Program Files\\Python38\\python.exe",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.testing.unittestEnabled": false,
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"test*.py"
],
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestPath":"d:\\program files\\python38\\lib\\site-packages\\pytest",
"python.testing.pytestArgs": [
"."
],
"python.testing.autoTestDiscoverOnSaveEnabled":true,
"python.linting.flake8Enabled": false,
"python.jediEnabled": true,
"python.autoComplete.addBrackets": true,
"python.formatting.provider": "yapf",
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 100,
"editor.fontSize": 15,
"fileheader.configObj": {
"createFileTime": true,
"timeNoDetail": false,
"language": {
"languagetest": {
"head": "/$$",
"middle": " $ @",
"end": " $/"
}
},
"autoAdd": false,
"autoAlready": true,
"annotationStr": {
"head": "/*",
"middle": " * @",
"end": " */",
"use": true
},
"headInsertLine": {
"php": 2
},
"beforeAnnotation": {
"py": "#!/usr/bin/env python\n# coding=UTF-8"
},
"specialOptions": {}
},
"fileheader.customMade": {
"Author": "user",
"Date": "Do not edit",
"LastEditors": "user",
"LastEditTime": "Do not Edit",
"Descripttion": "",
},
"fileheader.cursorMode": {
"description": "",
"param": "",
"return": ""
},
"python.languageServer": "Jedi"
}
task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "VScode",
"type": "shell",
// "command"为python.exe的绝对路径
"command": "D:\\Program Files\\Python38\\python.exe",
"args": [
"${file}"
],
"problemMatcher": [],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},