Mocha With Selenium The Error: TypeError: Wait condition must be a promise-like object, function, or a Condition object
Mocha With Selenium The Error: TypeError: Wait condition must be a promise-like object, function, or a Condition object
我是 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();
}
});
});
我的设置:
- 节点 8.9
- selenium-独立 https://www.npmjs.com/package/selenium-standalone
是的,为了测试 oauth
您可以为它创建 integration/e2e 测试。你已经在正确的道路上。
希望对您有所帮助
我是 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();
}
});
});
我的设置:
- 节点 8.9
- selenium-独立 https://www.npmjs.com/package/selenium-standalone
是的,为了测试 oauth
您可以为它创建 integration/e2e 测试。你已经在正确的道路上。
希望对您有所帮助