我正在尝试编写一个简单的 e2e 测试。
import {chromium, webkit, firefox} from "playwright";
(async () => {
for (const browserType of [chromium, firefox, webkit]) {
const browser = await browserType.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
await page.goto("https://github.com");
await page.fill('input[aria-label="Search GitHub"]', "Playwright");
await page.press('input[aria-label="Search GitHub"]', "Enter");
await page.click(".repo-list-item:nth-child(1) a");
await page.click('span[data-content="Security"]');
await page.screenshot({path: `screenshots/security-${browserType.name()}.png`, fullPage: false});
await page.close();
await browser.close();
}
})();
此代码适用于铬和火狐。但是,当我使用 webkit 时,它会在第二个屏幕上中断。Webkit 错误日志:
Error.captureStackTrace(stackObject);
^
page.click: Protocol error (Runtime.awaitPromise): The page has been closed.
=========================== logs ===========================
waiting for selector ".repo-list-item:nth-child(1) a"
selector resolved to visible <a class="v-align-middle" href="/microsoft/playwrig…>…</a>
attempting click action
waiting for element to be visible, enabled and not moving
element is moving - waiting...
element is visible, enabled and does not move
scrolling into view if needed
done scrolling
checking that element receives pointer events at (468,222)
<div class="mr-3">↵ Apache-2.0 license↵ </div> from <div>…</div> subtree intercepts pointer events
retrying click action
waiting for element to be visible, enabled and not moving
element is moving - waiting...
element is visible, enabled and does not move
scrolling into view if needed
done scrolling
checking that element receives pointer events at (468,222)
<div class="mr-3">↵ Apache-2.0 license↵ </div> from <div>…</div> subtree intercepts pointer events
retrying click action
我在 Windows 10 上。