Refactor DiscreteMaterialPlanExtractor to use logout function from auth module and update headless mode in main script
This commit is contained in:
@@ -6,6 +6,7 @@ import os
|
||||
import pandas as pd
|
||||
from playwright.sync_api import sync_playwright
|
||||
from utils.excel_converter import ExcelConverter
|
||||
from utils.auth import login, logout
|
||||
|
||||
|
||||
class DiscreteMaterialPlanExtractor:
|
||||
@@ -186,8 +187,6 @@ class DiscreteMaterialPlanExtractor:
|
||||
Returns:
|
||||
输出文件路径
|
||||
"""
|
||||
from login import login
|
||||
|
||||
with sync_playwright() as playwright:
|
||||
# 调用登录模块
|
||||
browser, context, page, main_frame = login(
|
||||
@@ -236,7 +235,7 @@ class DiscreteMaterialPlanExtractor:
|
||||
|
||||
# 执行账号注销
|
||||
self._print("\n开始执行账号注销...")
|
||||
self.logout(main_frame)
|
||||
logout(main_frame, verbose=self.verbose)
|
||||
|
||||
# 转换并合并文件
|
||||
if downloaded_files:
|
||||
@@ -256,37 +255,6 @@ class DiscreteMaterialPlanExtractor:
|
||||
|
||||
return output_file
|
||||
|
||||
def logout(self, main_frame):
|
||||
"""执行账号注销"""
|
||||
# 元素1:账号菜单按钮(logo 图标)
|
||||
self._print("点击账号菜单按钮...")
|
||||
main_frame.get_by_role("img", name="logo").click()
|
||||
|
||||
# 等待菜单出现
|
||||
import time
|
||||
time.sleep(1)
|
||||
|
||||
# 元素2:"退出登录"按钮
|
||||
self._print("点击退出登录按钮...")
|
||||
main_frame.get_by_text("退出登录").click()
|
||||
|
||||
# 等待确认框出现
|
||||
time.sleep(1)
|
||||
|
||||
# 元素3:退出登录确认框(判断是否出现)
|
||||
self._print("等待退出登录确认框...")
|
||||
try:
|
||||
confirm_text = main_frame.get_by_text("退出确定要退出当前账号吗?")
|
||||
self._print("找到确认框,点击确定按钮")
|
||||
|
||||
# 元素4:确认按钮
|
||||
main_frame.get_by_role("button", name="确定(Y)").click()
|
||||
except:
|
||||
self._print("未找到确认框,可能已自动退出")
|
||||
|
||||
time.sleep(2) # 等待注销完成
|
||||
|
||||
|
||||
def main():
|
||||
"""测试函数"""
|
||||
extractor = DiscreteMaterialPlanExtractor(
|
||||
|
||||
Reference in New Issue
Block a user