Skip to content

Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演

统一浏览器首启与详情完成信号

MigenAIab01aa3c1046
diff --git a/test/e2e_support.py b/test/e2e_support.py
index 480b34d..88ccb2f 100644
--- a/test/e2e_support.py
+++ b/test/e2e_support.py
@@ -110,7 +110,7 @@ def launch_context(
accept_downloads: bool,
extension_dir: Path = EXTENSION_DIR,
) -> BrowserContext:
- return playwright.chromium.launch_persistent_context(
+ context = playwright.chromium.launch_persistent_context(
profile_dir,
headless=True,
channel=os.environ.get("PROMPTDIRECTOR_E2E_CHANNEL", "chromium"),
@@ -123,6 +123,17 @@ def launch_context(
f"--load-extension={extension_dir}",
],
)
+ worker = context.service_workers[0] if context.service_workers else context.wait_for_event("serviceworker")
+ bootstrap = context.new_page()
+ bootstrap_errors: list[str] = []
+ record_page_errors(bootstrap, bootstrap_errors)
+ try:
+ bootstrap.goto(f"chrome-extension://{worker.url.split('/')[2]}/collector.html", wait_until="domcontentloaded")
+ bootstrap.evaluate("async () => chrome.runtime.sendMessage({type: 'GET_STATE'})")
+ assert not bootstrap_errors, f"扩展首次初始化出现运行时错误:{bootstrap_errors}"
+ finally:
+ bootstrap.close()
+ return context
def record_page_errors(page: Page, errors: list[str]) -> None:
diff --git a/test/library_132_e2e.py b/test/library_132_e2e.py
index b41aacb..bbd1994 100644
--- a/test/library_132_e2e.py
+++ b/test/library_132_e2e.py
@@ -20,14 +20,15 @@ def wait_for_initial_gallery_batch(page, total: int) -> int:
return count
-def save_pending_classification(page) -> None:
- page.locator(".pending-classification-inline select").select_option("content:image-case")
- page.evaluate(
- """() => new Promise(resolve => requestAnimationFrame(
- () => requestAnimationFrame(resolve)
- ))"""
- )
- button = page.locator(".pending-classification-inline button")
+def save_pending_classification(page, entry_id: str) -> None:
+ drawer = page.locator("#detail-drawer")
+ expect(drawer).to_have_attribute("data-entry-id", entry_id)
+ panel = page.locator(".pending-classification-inline")
+ expect(panel).to_be_visible()
+ select = panel.locator("select")
+ select.select_option("content:image-case")
+ expect(select).to_have_value("content:image-case")
+ button = panel.locator("button")
expect(button).to_be_enabled()
button.click()
@@ -309,20 +310,24 @@ def main() -> None:
library.evaluate("scrollTo(0, 0)")
library.locator(".case-card[data-entry-id='pending-2']").click()
- save_pending_classification(library)
+ save_pending_classification(library, "pending-2")
expect(library.locator("#detail-drawer")).to_have_attribute("data-entry-id", "pending-2")
expect(library.locator("#detail-drawer")).to_have_class("detail-drawer open")
library.locator("#detail-close").click()
library.locator("#pending-filter").check()
- library.locator(".case-card").first.click()
+ first_pending_card = library.locator(".case-card").first
+ first_pending_id = first_pending_card.get_attribute("data-entry-id")
+ assert first_pending_id
+ first_pending_card.click()
expect(library.locator(".pending-classification-inline")).to_be_visible()
library.screenshot(path="/tmp/prompt-director-132-pending-inline.png")
- first_id = library.locator("#detail-drawer").get_attribute("data-entry-id")
- save_pending_classification(library)
- expect(library.locator("#detail-drawer")).not_to_have_attribute("data-entry-id", first_id)
+ save_pending_classification(library, first_pending_id)
+ expect(library.locator("#detail-drawer")).not_to_have_attribute("data-entry-id", first_pending_id)
expect(library.locator(".pending-classification-inline")).to_be_visible()
- save_pending_classification(library)
+ second_pending_id = library.locator("#detail-drawer").get_attribute("data-entry-id")
+ assert second_pending_id and second_pending_id != first_pending_id
+ save_pending_classification(library, second_pending_id)
expect(library.locator("#detail-drawer")).not_to_have_class("open")
expect(library.locator("#feedback")).to_contain_text("待确认已处理完")