我正在尝试将 Selenium (v4.18.1) 测试集成到 Angular Web 应用程序中。测试将在 Microsoft Edge 浏览器 (v122.0.2365.59) 中进行。我已经安装了 Microsoft Edge WebDriver (v122.0.2365.59)。目前,我不从事自定义测试;我首先根据 Microsoft Learn 提供的示例进行一些断言:https://learn.microsoft.com/es-es/microsoft-edge/webdriver-chromium/?tabs=javascript&form=MA13LH
const { Builder, By } = require('selenium-webdriver');
const assert = require('assert');
(async () => {
const driver = await new Builder().forBrowser('MicrosoftEdge').build();
try {
await driver.get('https://bing.com');
const element = await driver.findElement(By.id('sb_form_q'));
await element.sendKeys('WebDriver');
await element.submit();
// Example assertion: Verify that the page title contains the search query
const pageTitle = await driver.getTitle();
assert(pageTitle.includes('WebDriver'), 'Page title does not contain search query');
// Example assertion: Verify that search results are displayed
const searchResults = await driver.findElements(By.className('b_algo'));
assert(searchResults.length > 0, 'No search results found');
} finally {
await driver.quit();
}
})();
运行npm test后,受控的Edge浏览器窗口打开,测试运行成功。然而,之后我遇到了以下问题:
$ npm 测试
[电子邮件受保护] 测试 npx 摩卡测试/**/*.spec.js --超时 60000
0 通过(1ms)
[31204:30320:0301/141401.539:错误:policy_logger.cc(157)]:组件企业行