Commit 17a340be authored by wushanjing's avatar wushanjing

增强智能接单页面跳转容错

parent 0c2c8d06
......@@ -25,6 +25,7 @@ from e2e.utils.env_config import assert_url_allowed_for_env
WANYOUJI_CONSOLE_URL = "https://test-merchant-lianlianyun.lianlianwz.com/productConsole?productCode=P20250814095939369041"
WANYOUJI_WORKSHOP_ORDER_LIST_URL = "https://test-orbit.lianlianwz.com/order"
WANYOUJI_ORDER_HALL_URL = "https://test-orbit.lianlianwz.com/orderHall"
WANZHANGGUI_ORDER_LIST_URL = "https://test-order-pc.lianlianwz.com/orderManage/orderList"
PROD_WANZHANGGUI_CONSOLE_URL = "https://merchant-lianlianyun.shunfju.com/productConsole?productCode=P20251222184412861622"
PROD_WANZHANGGUI_ORDER_LIST_URL = "https://order-pc.shunfju.com/orderManage/orderList"
......@@ -96,18 +97,21 @@ class WanzhangguiOrderPage(TenantAuthPage):
self.wait_for_enterprise_console_shell()
self.page.wait_for_timeout(1200)
self.dismiss_transient_order_error()
if self.is_production():
self.click_sidebar_text("商家订单管理列表", right_edge=True)
self.page.wait_for_timeout(800)
self.click_sidebar_text("订单管理列表")
else:
self.click_sidebar_text("商家管理", right_edge=True)
self.page.wait_for_timeout(800)
self.click_sidebar_path(
"/orderManage/orderList",
app_hint="Saas-福单",
fallback_texts=["订单管理"],
)
try:
if self.is_production():
self.click_sidebar_text("商家订单管理列表", right_edge=True)
self.page.wait_for_timeout(800)
self.click_sidebar_text("订单管理列表")
else:
self.click_sidebar_text("商家管理", right_edge=True)
self.page.wait_for_timeout(800)
self.click_sidebar_path(
"/orderManage/orderList",
app_hint="Saas-福单",
fallback_texts=["订单管理"],
)
except AssertionError:
self.force_wanzhanggui_order_list_url()
self.page.wait_for_timeout(3500)
for attempt in range(3):
......@@ -126,6 +130,18 @@ class WanzhangguiOrderPage(TenantAuthPage):
self.page.wait_for_timeout(3500)
return self.wait_for_order_list_ready()
def force_wanzhanggui_order_list_url(self) -> None:
target_url = self.order_list_url()
assert_url_allowed_for_env(target_url)
for frame in self.page.frames:
if "test-order-pc" in frame.url or "order-pc.shunfju.com" in frame.url:
try:
frame.evaluate("url => { window.location.href = url; }", target_url)
return
except Exception:
continue
self.goto(target_url)
def is_production(self) -> bool:
return "shunfju.com" in self.tenant_home_url
......@@ -292,6 +308,9 @@ class WanzhangguiOrderPage(TenantAuthPage):
self.page.wait_for_timeout(1000)
def order_frame(self) -> Frame:
main_frame = self.page.main_frame
if "test-order-pc" in main_frame.url or "order-pc.shunfju.com" in main_frame.url:
return main_frame
for frame in self.page.frames:
if "test-order-pc" in frame.url or "order-pc.shunfju.com" in frame.url:
return frame
......@@ -356,6 +375,34 @@ class WanzhangguiOrderPage(TenantAuthPage):
self.page.wait_for_timeout(2500)
return self.futong_frame_by_path("/merchantSupplyAuth", target_url=WANZHANGGUI_SUPPLY_AUTH_URL)
def text_has_expired_login(self, text: str) -> bool:
return any(
keyword in text
for keyword in [
"登录已过期",
"认证失败",
"重新登录请求失败",
"请重新登录",
"登录失效",
]
)
def relogin_current_main_account_if_possible(self) -> bool:
phone = getattr(self.page, "_e2e_current_main_account", "")
if not phone:
return False
try:
from e2e.utils.account_store import account_store
account = account_store().find(phone=phone)
except Exception:
account = None
if not account or not account.password:
return False
self.clear_login_state()
self.login_main_account(phone, account.password)
return True
def ensure_sidebar_child_visible(self, parent_text: str, child_text: str) -> None:
last_text = ""
for _ in range(4):
......@@ -394,8 +441,23 @@ class WanzhangguiOrderPage(TenantAuthPage):
raise AssertionError(f"未找到丸掌柜业务 iframe {path},当前 frames:{urls}")
def ensure_workshop_guarantee(self, workshop_name: str, enabled: bool) -> str:
frame = self.open_workshop_authorization()
row_text = self.workshop_authorization_row_text(frame, workshop_name)
last_error: Exception | None = None
for attempt in range(2):
frame = self.open_workshop_authorization()
try:
row_text = self.workshop_authorization_row_text(frame, workshop_name)
break
except AssertionError as exc:
last_error = exc
try:
text = frame.locator("body").inner_text(timeout=5000)
except Exception:
text = str(exc)
if attempt == 0 and self.text_has_expired_login(text) and self.relogin_current_main_account_if_possible():
continue
raise
else:
raise AssertionError(f"工作室授权列表未找到工作室:{workshop_name}") from last_error
if self.guarantee_enabled_from_row(row_text) == enabled:
return row_text
......@@ -6199,11 +6261,19 @@ class WanyoujiFulfillmentPage(TenantAuthPage):
for attempt in range(3):
try:
self.click_sidebar_text("工作室履约应用", right_edge=True)
self.click_sidebar_text("抢单大厅")
try:
self.click_sidebar_path(
"/orderHall",
app_hint="Saas-丸友集",
fallback_texts=["抢单大厅", "外部合作抢单大厅"],
)
except AssertionError:
self.click_sidebar_text("抢单大厅")
break
except AssertionError:
if attempt == 2:
raise
self.force_wanyouji_business_frame_url(WANYOUJI_ORDER_HALL_URL)
break
self.page.wait_for_timeout(2000)
self.goto(WANYOUJI_CONSOLE_URL)
self.wait_for_enterprise_console_shell()
......@@ -6218,6 +6288,9 @@ class WanyoujiFulfillmentPage(TenantAuthPage):
]
if frames:
return frames
if _ in {2, 5}:
self.force_wanyouji_business_frame_url(WANYOUJI_ORDER_HALL_URL)
self.page.wait_for_timeout(2500)
self.page.wait_for_timeout(1000)
urls = [frame.url for frame in self.page.frames]
texts: list[str] = []
......@@ -13897,7 +13970,7 @@ class WanyoujiFulfillmentPage(TenantAuthPage):
raise AssertionError(f"未找到丸友集业务 iframe;keywords={keywords}; frames={urls}")
def wanyouji_business_frames(self) -> list[Frame]:
return [
frames = [
frame
for frame in self.page.frames
if frame.url != "about:blank"
......@@ -13908,6 +13981,15 @@ class WanyoujiFulfillmentPage(TenantAuthPage):
or "test-ledger" in frame.url
)
]
main_frame = self.page.main_frame
if main_frame.url != "about:blank" and (
"test-wshop" in main_frame.url
or "test-orbit" in main_frame.url
or "test-booster" in main_frame.url
or "test-ledger" in main_frame.url
):
frames.insert(0, main_frame)
return frames
def retry_if_app_load_timeout(self) -> None:
for _ in range(3):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment