当前位置: 首页 > wzjs >正文

网站建设必须要服务器么c2c模式发展趋势

网站建设必须要服务器么,c2c模式发展趋势,网站php环境搭建,wordpress调用当前tag标签的热门文章📌 自动化测试框架设计 该框架基于 pytest,支持 Web API 自动化测试,采用 关键字驱动,支持 远程执行、多机调度、失败重试、数据驱动(CSV),并结合 allure 生成可视化测试报告。 📂…

📌 自动化测试框架设计

该框架基于 pytest,支持 Web + API 自动化测试,采用 关键字驱动,支持 远程执行、多机调度、失败重试、数据驱动(CSV),并结合 allure 生成可视化测试报告。


📂 目录结构

automation_framework/  
│── config/                        # 配置文件存放目录
│   ├── settings.ini               # 全局配置(浏览器、API、环境等)
│   ├── remote_hosts.ini           # 远程执行机列表
│
│── tests/                         # 测试用例目录
│   ├── web/                       # Web 相关测试
│   │   ├── test_login.py          # Web登录测试
│   ├── api/                       # API 相关测试
│   │   ├── test_api.py            # API测试示例
│   ├── conftest.py                # pytest 配置
│
│── core/                          # 关键字封装
│   ├── web_keywords.py            # Web自动化关键字库
│   ├── api_keywords.py            # API自动化关键字库
│
│── utils/                         # 工具类
│   ├── logger.py                  # 日志封装
│   ├── remote_executor.py         # 远程执行
│   ├── screenshot.py              # 截图工具
│   ├── csv_parser.py              # CSV数据驱动解析
│
│── reports/                       # 测试报告存放目录
│
│── logs/                          # 日志存放目录
│
│── requirements.txt               # 依赖包
│── run_tests.py                   # 运行测试主入口
│── pytest.ini                     # pytest 配置
│── README.md                      # 说明文档

📌 1. 依赖管理

requirements.txt

 
pytest
pytest-rerunfailures
pytest-xdist
selenium
requests
allure-pytest
paramiko
pandas


📌 2. 配置文件

config/settings.ini

 
[WEB]
browser = chrome
base_url = http://example.com
headless = false
implicit_wait = 5[API]
base_url = http://example.com/api
timeout = 10

config/remote_hosts.ini

[executor_1]
host = 192.168.1.101
username = user
password = pass[executor_2]
host = 192.168.1.102
username = user
password = pass

📌 3. Web 关键字封装

core/web_keywords.py

from selenium import webdriver
from selenium.webdriver.common.by import By
import configparser
import allureclass WebKeywords:def __init__(self):"""初始化浏览器驱动"""config = configparser.ConfigParser()config.read("config/settings.ini")options = webdriver.ChromeOptions()if config.getboolean("WEB", "headless"):options.add_argument("--headless")self.driver = webdriver.Chrome(options=options)self.driver.implicitly_wait(config.getint("WEB", "implicit_wait"))def open_url(self, url):"""打开指定URL"""self.driver.get(url)def find_element(self, locator):"""查找元素"""return self.driver.find_element(By.XPATH, locator)def click(self, locator):"""点击元素"""self.find_element(locator).click()def send_keys(self, locator, text):"""输入文本"""self.find_element(locator).send_keys(text)def take_screenshot(self, name):"""截图并附加到Allure报告"""path = f"reports/screenshots/{name}.png"self.driver.save_screenshot(path)allure.attach.file(path, name="screenshot", attachment_type=allure.attachment_type.PNG)def close(self):"""关闭浏览器"""self.driver.quit()

📌 4. API 关键字封装

core/api_keywords.py

import requests
import configparserclass APIKeywords:def __init__(self):"""初始化API测试类"""config = configparser.ConfigParser()config.read("config/settings.ini")self.base_url = config["API"]["base_url"]self.timeout = config.getint("API", "timeout")def get(self, endpoint, params=None, headers=None):"""发送GET请求"""return requests.get(f"{self.base_url}{endpoint}", params=params, headers=headers, timeout=self.timeout)def post(self, endpoint, data=None, json=None, headers=None):"""发送POST请求"""return requests.post(f"{self.base_url}{endpoint}", data=data, json=json, headers=headers, timeout=self.timeout)


📌 5. conftest.py 配置

 
import pytest
import allure
from core.web_keywords import WebKeywords
from core.api_keywords import APIKeywords@pytest.fixture(scope="session")
def web():"""Web自动化前后置"""web = WebKeywords()yield webweb.close()@pytest.fixture(scope="session")
def api():"""API自动化前后置"""return APIKeywords()@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item):"""失败截图"""outcome = yieldreport = outcome.get_result()if report.when == "call" and report.failed:web_fixture = item.funcargs.get("web", None)if web_fixture:web_fixture.take_screenshot(item.name)


📌 6. CSV 数据驱动

utils/csv_parser.py

import pandas as pddef parse_csv(file_path):"""解析CSV文件"""return pd.read_csv(file_path).to_dict(orient="records")

CSV 用例格式

 
test_name,username,password,expected
valid_login,user1,pass123,success
invalid_login,user1,wrongpass,failure


📌 7. Web 测试用例

tests/web/test_login.py

 
import allure
import pytest
from utils.csv_parser import parse_csvdata = parse_csv("data/login_cases.csv")@allure.feature("Login Page")
@pytest.mark.parametrize("test_name,username,password,expected", data)
def test_login(web, test_name, username, password, expected):web.open_url("http://example.com/login")web.send_keys("//input[@id='username']", username)web.send_keys("//input[@id='password']", password)web.click("//button[@id='login']")assert expected in web.driver.page_source


📌 8. API 测试用例

tests/api/test_api.py

 
import allure@allure.feature("API Test")
def test_get_api(api):response = api.get("/users")assert response.status_code == 200@allure.feature("API Test")
def test_post_api(api):response = api.post("/login", json={"username": "test", "password": "test123"})assert response.status_code == 200


📌 9. 远程执行

utils/remote_executor.py

import paramiko
import configparserclass RemoteExecutor:def __init__(self):self.config = configparser.ConfigParser()self.config.read("config/remote_hosts.ini")def run_remote_tests(self):for section in self.config.sections():ssh = paramiko.SSHClient()ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())ssh.connect(self.config[section]["host"], username=self.config[section]["username"], password=self.config[section]["password"])stdin, stdout, stderr = ssh.exec_command("pytest --alluredir=reports/allure-results")print(stdout.read().decode())ssh.close()


📌 10. 运行测试

 
# 本地执行
pytest --alluredir=reports/allure-results --reruns 2# 远程执行
python utils/remote_executor.py# 生成 Allure 报告
allure generate reports/allure-results -o reports/html-reports --clean
allure open reports/html-reports


这样,你就有了 Web + API 关键字驱动自动化框架,支持 失败重试、数据驱动、远程执行! 🚀


文章转载自:

http://drm10fge.jxscp.cn
http://gWwAdxvT.jxscp.cn
http://2QwKTZoy.jxscp.cn
http://JwRo07Iq.jxscp.cn
http://s8BH3GuH.jxscp.cn
http://AtdTwdK5.jxscp.cn
http://waxryJ7D.jxscp.cn
http://oniKZFGO.jxscp.cn
http://EahCc6X1.jxscp.cn
http://3iX6gsbr.jxscp.cn
http://nSzPRKNr.jxscp.cn
http://1p4SVkGV.jxscp.cn
http://O68Pc9Cs.jxscp.cn
http://1V0eO38C.jxscp.cn
http://9uu2gbF2.jxscp.cn
http://72CtzNYU.jxscp.cn
http://CH0krASa.jxscp.cn
http://ctdjQ3uv.jxscp.cn
http://55nwaaz7.jxscp.cn
http://wIg9IqvI.jxscp.cn
http://y0GApXeB.jxscp.cn
http://AOyOkJ2P.jxscp.cn
http://jUBfPYAY.jxscp.cn
http://pPQ23xjo.jxscp.cn
http://pIFG13ul.jxscp.cn
http://w5o6R77v.jxscp.cn
http://ov6hBllw.jxscp.cn
http://RxYCe3Dr.jxscp.cn
http://9HbSTBBK.jxscp.cn
http://v0GuaX8u.jxscp.cn
http://www.dtcms.com/wzjs/717464.html

相关文章:

  • 我注册了哪些网站吗wordpress无法访问站点
  • 热点链接到另一个网站怎么做南昌营销网站公司哪家好
  • 做网站必须原创吗特种作业证查询
  • 外贸网站建设 惠州手机网站输入框
  • 网站建设中的英文utc+wordpress
  • 购物网站开发背景及意义山东省服务外包网
  • 2018年网站开发语言排行wordpress #
  • 做网站工作好么长春做网站推广
  • 网站建设功能介绍赣州信息港手机版
  • 深圳二次源网站建设seo挂机赚钱
  • 建设网站的企业哪家好大数据营销是做什么的
  • 网站商城建设基本流程北京企业网站推广
  • 湘潭新思维网站上海通信管理局网站
  • 郴州网站seo外包软件公司运营是做什么的
  • 网站建设自查情况报告京津冀协同发展纲要
  • 鞍山网站制作谁家好郑州哪家医院看妇科比较专业
  • 中山移动网站建设报价东城网站建设工作室
  • 网页制作与网站开发从入门到精通 豆瓣网站开发平均工资
  • 帮人做网站赚钱吗wordpress编辑器 下载地址
  • 长安网站建设详细教程太原注册公司在哪个网站申请
  • 石家庄万达网站制作一般门户网站
  • 网站免费正能量链接怎样开电商
  • 镇江网站优化哪家好wordpress弹窗登录
  • 山东网站制作应用app开发公司都有哪些部门
  • 精选网站建立 推广 优化阿里云做视频网站可以吗
  • 影视自助建站电脑制作图片的软件
  • 网站建设的步骤和要点订货系统
  • 网站举报能不能查到举报人工商局网站做年报
  • 个人建站网站编辑岗位
  • 服务器怎么做网站wordpress 更换模板