mirror of
https://github.com/insistence/RuoYi-Vue3-FastAPI.git
synced 2026-09-30 07:46:14 +00:00
* fix: 修复无法直接通过后端地址访问API文档的问题 * feat: 新增server_util * refactor: 重构自定义API文档路由逻辑
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import pytest
|
|
from playwright.async_api import async_playwright, expect
|
|
|
|
from common.base_page_test import BasePageTest
|
|
from common.config import Config
|
|
|
|
|
|
class SwaggerTest(BasePageTest):
|
|
async def check_swagger_interface(self) -> None:
|
|
"""测试系统接口页面 (Swagger UI)"""
|
|
|
|
# 1. 直接导航到系统接口页面
|
|
await self.goto_page(Config.frontend_url + '/tool/swagger')
|
|
|
|
# 2. 验证页面加载
|
|
# 等待 iframe 出现
|
|
iframe = self.page.locator('iframe')
|
|
await expect(iframe).to_be_visible()
|
|
|
|
# 获取 iframe 内容框架
|
|
frame = self.page.frame_locator('iframe')
|
|
|
|
# 后端未禁用Swagger时,验证 iframe 内部的标题包含 "RuoYi-FastAPI"
|
|
# 当前生产环境已默认禁用Swagger,此处验证标题是否包含默认禁用提示
|
|
h1_locator = frame.locator('h1')
|
|
await expect(h1_locator).to_contain_text('Swagger UI has been disabled. Please enable it first.', timeout=15000)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_swagger_page() -> None:
|
|
"""测试系统接口页面功能"""
|
|
async with async_playwright() as p:
|
|
test_instance = SwaggerTest()
|
|
await test_instance.setup(p)
|
|
try:
|
|
await test_instance.check_swagger_interface()
|
|
finally:
|
|
await test_instance.teardown()
|