node.js - Mocha 与 Selenium 错误:TypeError:等待条件必须是类似 promise 的对象、函数或 Condition 对象
问题描述
我是 Mocha 和 Selenium 测试 Express 应用程序的新手。我有以下简单的代码,但我不知道出了什么问题。
describe("authenticateWithGoogle", function() {
it("return a valid access token for our tests", function() {
return new Promise( function(resolve) {
var driver = new Builder().forBrowser('chrome').build();
driver.get('https://www.google.com');
driver.wait("Google",5000).then( (quitDriver,handleFailure) => {
console.log("wait over");
assert.ok(true);
});
resolve();
}).then();
});
});
运行“mocha”时收到以下错误:
TypeError: Wait condition must be a promise-like object, function, or a Condition object
这发生在上面代码中的“driver.wait”行。我真的不明白错误是什么意思。
解决方案
我尝试了相同的 selenium-webdriver 4.0.0 alpha.1 并且它有效。基于它的例子,它使用async await
所以我使用相同的方式。
const {Builder, By, Key, until} = require('selenium-webdriver');
const chai = require('chai');
const assert = chai.assert;
describe("authenticateWithGoogle", function() {
it("return a valid access token for our tests", async function() {
this.timeout(5000);
let driver = await new Builder()
.usingServer('http://localhost:4444/wd/hub')
.forBrowser('chrome').build();
try {
await driver.get('http://www.google.com');
await driver.wait(until.titleIs('Google'), 1000);
} finally {
assert.ok(true);
await driver.quit();
}
});
});
我的设置:
是的,对于测试,oauth
您可以为其创建集成/e2e 测试。你已经在正确的道路上。
希望能帮助到你
推荐阅读
- mysql - 带有 4 个表的 SQL 查询 JOIN
- ruby - Ruby 文件中不遵守 VSCode 样式/PercentLiteralDelimiters 规则
- c# - 根据数据表中的一组日期范围检查日期范围
- javascript - 除非我刷新页面,否则 Javascript localStorage 在其他组件中不可用
- reactjs - 如何在 Flow 中扩展 ViewProps?
- python - 制作一个从字典中的键中检索信息的函数
- excel - 我有 2 个 sumifs 公式。我想根据是否满足 3 个标准来使用一个与另一个。如果语句不起作用
- php - PHP中数组的计数和求和
- c++ - 当摆脱模偏差时 min = -upper_bound % upper_bound; // 工作?
- movesense - J-Flash (Lite) 程序 Movesense