Windows环境下Python自动化测试项目:需登录网站压测及Allure集成咨询
企业登录页场景下的Python自动化测试项目压测方案需求
项目现状
我在Windows环境下开发基于Python的网站自动化测试项目,需覆盖功能测试、可访问性测试、性能压测三个模块,并通过Allure Framework生成统一测试报告。目前已完成功能与可访问性测试:
- 用Selenium实现页面自动化操作
- 用axe完成可访问性检测
- 用Allure生成测试报告
但性能压测环节遇到了技术瓶颈。
已尝试方案及问题
- Apache JMeter:已搭建测试计划,但被测网站需通过企业HTML登录页登录后方可访问目标页面。HTTP Post Request无法模拟登录按钮的点击操作,HTTP Authorization Manager仅适用于弹窗式登录,不支持完整HTML登录页的登录流程。
- Locust:计划将其集成到现有Python项目中,但发现
@task装饰器仅支持页面连接类操作,无法处理复杂的登录步骤(如证书异常处理、表单填写、按钮点击等)。
现有可运行的登录代码(PyTest环境)
以下是我已实现的website.py代码,包含登录流程、axe可访问性测试及页面文本校验功能,可通过PyTest正常运行:
import allure import sys import time from axe_selenium_python import Axe from libraries.report import Report from selenium import webdriver from selenium.webdriver.common.by import By class Website: def __init__(self, browser: str, username: str, password: str): try: if browser == "Chrome": self.driver = webdriver.Chrome() elif browser == "Edge": self.driver = webdriver.Edge() except: print("Only 'Chrome' and 'Edge' browsers are supported for testing.") sys.exit(1) self.driver.get("https://localhost/homepage") get_source = self.driver.page_source # Scan the page not_private1 = "Your connection is not private" not_private2 = "Your connection isn't private" if (not_private1 in get_source or not_private2 in get_source): # NET::ERR_CERT_COMMON_NAME_INVALID self.driver.find_element(By.ID, "details-button").click() # Click "Advanced" button self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") # Scroll to the bottom of the page self.driver.find_element(By.ID, "proceed-link").click() # Click "Proceed to localhost (unsafe)" link get_source = self.driver.page_source # Redirects to Corporate Login Page login_page = "Login Page" if (login_page in get_source): self.driver.find_element(By.ID, "userNameInput").send_keys(username) self.driver.find_element(By.ID, "passwordInput").send_keys(password) self.driver.find_element(By.ID, "submitButton").click() time.sleep(1) # connects to the homepage def access(self, json: str): axe = Axe(self.driver) axe.inject() # Inject axe-core javascript into page. results = axe.run() # Run axe accessibility checks. axe.write_results(results, json) # Write results to file report = Report() if len(results["violations"]) == 0: # Assert no violations are found print("No Access Violations found on page!") report.screenshot_png(self.driver, "access: PASS") self.driver.close() assert True return True else: print("Access Violations found on page!") report.screenshot_png(self.driver, "access: FAIL") self.driver.close() assert False, axe.report(results["violations"]) # Reports violations found on page return False def find_string(self, search_text: str): get_source = self.driver.page_source # Scan the page report = Report() if (search_text in get_source): print("String Text '" + search_text + "' on page found!") report.screenshot_png(self.driver, "find_string: PASS") self.driver.close() assert True return True else: print("String Text '" + search_text + "' on page not found.") report.screenshot_png(self.driver, "find_string: FAIL") self.driver.close() assert False, "String Text '" + search_text + "' on page not found." return False def close(self): self.driver.close() # Closes the browser
需求
寻求适配该场景的性能压测方案,要求:
- 支持处理现有代码中的登录流程(包括证书异常处理、表单填写、登录按钮点击)
- 能将压测结果集成至Allure测试报告中
内容的提问来源于stack exchange,提问作者PillagingProgrammer
相关产品推荐
相关产品推荐

