我正在寻找一种基于每次测试设置默认超时的方法。
我正在写一些守夜测试。其中一项测试需要多次点击API才能设置初始测试条件。为了运行测试,必须填充一些用户数据。这是在before()方法中发生的。
问题是,before()达到默认超时间隔时将超时。我已经阅读了设置全局默认超时的文档,但是我不想在所有地方都增加它。如何在每次测试的基础上做到这一点?
前后异步
https://nightwatchjs.org/guide/#asynchronous-before-each-and-after-each-
设置全局asyncHookTimeout
https://github.com/nightwatchjs/nightwatch/blob/master/examples/globalsModule.js#L20
测试代码如下:
const { TEST_USER } = require('../../definitions/users');
const { TEST_USER_DATA } = require('../../definitions/users/data');
module.exports = {
async before(browser, done) {
// the default interval is here, but changing it doesn't have any effect
console.log(browser.options.globals.asyncHookTimeout); // 10000
const usersPO = browser.page.users();
// get the user from the API to test with
const testUser = await usersPO.getUser(TEST_USER);
// post test data to the user
await usersPO.postUserData(testUser.id, TEST_USER_DATA); // this will exceed the timeout.
// finished with async test setup
done();
},
// Tests
};
答案 0 :(得分:0)
一种实现此目的的方法是在每个测试中设置browser.options.globals.asyncHookTimeout值,该值将覆盖配置文件中的默认值。
希望这会对您有所帮助。
干杯!