gpt4 book ai didi

mocha.js - 在执行 Nightmare 测试期间如何在多个位置评估页面?

转载 作者:行者123 更新时间:2023-12-03 13:24:10 26 4
gpt4 key购买 nike

我正在尝试编写Nightmare.js测试,该测试在执行过程中的多个点声明/evaluate()事物。

it("should return to home page when quit button is pressed", function (done) {
var username = 'sinbad';
new Nightmare({ show: true })
.goto(url)
.type('#choosenickname', username)
.click('#write-btn')
.wait('div.game')

.evaluate(function () {
return document.querySelectorAll('#write-btn').length;
})
.then(function (result) {
// No 'write' buttons found
result.should.eql(0);
})
// Everything after this point doesn't work
.click('#quit-btn')
.wait('div.home')
.evaluate(function () {
return document.querySelectorAll('#write-btn').length;
})
.then(function (result) {
// After quitting, we should have a write button
result.should.eql(1);
done();
});
});

当我运行它时,我得到
TypeError: (intermediate value).goto(...).type(...).click(...).wait(...).evaluate(...)
.then(...).click is not a function

最佳答案

根据this sample,答案似乎是像这样组成then():

it("should return to home page when quit button is pressed", function (done) {
var nightmare = loginPlayer('sinbad')
nightmare
.evaluate(function () {
return document.querySelectorAll('#write-btn').length;
})
.then(function (result) {
// No 'write' buttons found
result.should.eql(0);
}).then(function () {
return nightmare
.click('#quit-btn')
.wait('div.home')
.evaluate(function () {
return document.querySelectorAll('#write-btn').length;
})
})
.then(function (result) {
// After quitting, we should have a write button
result.should.eql(1);
done();
});
});

关于mocha.js - 在执行 Nightmare 测试期间如何在多个位置评估页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41907654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com