Files
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

65 lines
2.5 KiB
Python

import time
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page(viewport={'width': 1400, 'height': 900})
# 1. 打开登录页
page.goto('http://localhost:10002/admin/login')
page.wait_for_load_state('networkidle')
page.screenshot(path='e:/nanocode/website-new/screenshot_01_login.png')
print('Step 1: 打开登录页')
# 2. 填写账号密码
page.fill('input[type=text]', 'admin')
page.fill('input[type=password]', 'abcd1234')
page.screenshot(path='e:/nanocode/website-new/screenshot_02_filled.png')
print('Step 2: 填写账号密码')
# 3. 点击登录
page.click('button[type=submit]')
page.wait_for_url('**/admin')
page.wait_for_load_state('networkidle')
page.screenshot(path='e:/nanocode/website-new/screenshot_03_dashboard.png')
print('Step 3: 登录成功,进入后台')
# 4. 点击"新闻资讯"展开子菜单
page.click('button:has-text("新闻资讯")')
time.sleep(0.5)
page.screenshot(path='e:/nanocode/website-new/screenshot_04_menu_expanded.png')
print('Step 4: 展开新闻资讯菜单')
# 5. 点击"栏目管理"
page.click('a:has-text("栏目管理")')
page.wait_for_url('**/admin/news/categories')
page.wait_for_load_state('networkidle')
page.screenshot(path='e:/nanocode/website-new/screenshot_05_categories.png')
print('Step 5: 进入栏目管理页面')
# 6. 点击"添加栏目"
page.click('button:has-text("添加栏目")')
time.sleep(0.5)
page.screenshot(path='e:/nanocode/website-new/screenshot_06_modal_open.png')
print('Step 6: 打开添加栏目弹窗')
# 7. 填写栏目信息
page.fill('input[placeholder*="如:公司新闻"]', '测试栏目')
page.fill('input[placeholder*="如:company-news"]', 'test-column')
page.fill('textarea[placeholder*="栏目简介"]', '这是一个用于测试的栏目')
page.screenshot(path='e:/nanocode/website-new/screenshot_07_form_filled.png')
print('Step 7: 填写栏目信息')
# 8. 点击创建
page.click('button:has-text("创建")')
time.sleep(1)
page.screenshot(path='e:/nanocode/website-new/screenshot_08_created.png')
print('Step 8: 创建栏目完成')
# 9. 最终截图
page.screenshot(path='e:/nanocode/website-new/screenshot_09_final.png')
print('Step 9: 最终页面截图')
browser.close()
print('All done!')