Node.js Webdriver.io-如何在配置中使用beforeach挂钩
我正在使用MEAN stack和Webdriver构建一个应用程序进行测试 目前,我正在使用Mocha的Beforeach和afterEach挂钩在测试之间清理数据库,例如:Node.js Webdriver.io-如何在配置中使用beforeach挂钩,node.js,database,selenium,webdriver,mean,Node.js,Database,Selenium,Webdriver,Mean,我正在使用MEAN stack和Webdriver构建一个应用程序进行测试 目前,我正在使用Mocha的Beforeach和afterEach挂钩在测试之间清理数据库,例如: describe('Links', function() { // drop DB collections beforeEach(function(done){ //create database objects }); afterEach(function(done){ // drop
describe('Links', function() {
// drop DB collections
beforeEach(function(done){
//create database objects
});
afterEach(function(done){
// drop DB collections
});
});
有没有一种方法可以设置wdio.conf.js,以便在每次测试之前和之后自动执行此操作?配置的before:
和after:function(){}
作为一个beforeAll/afterAll运行,而不是针对每个测试。是的,请参阅以下url:
如果启动wdio配置,将生成一个名为wdio.conf.js的文件,此文件上存在用于在测试之后或之前启动脚本的函数,我将显示包含此文件的函数示例:
// =====
// Hooks
// =====
// Run functions before or after the test. If one of them returns with a promise, WebdriverIO
// will wait until that promise got resolved to continue.
//
// Gets executed before all workers get launched.
onPrepare: function() {
// do something
},
//
// Gets executed before test execution begins. At this point you will have access to all global
// variables like `browser`. It is the perfect place to define custom commands.
before: function() {
// do something
},
//
// Gets executed after all tests are done. You still have access to all global variables from
// the test.
after: function(failures, pid) {
// do something
},
//
// Gets executed after all workers got shut down and the process is about to exit. It is not
// possible to defer the end of the process using a promise.
onComplete: function() {
// do something
}
重要的是,如果您启动一个异步脚本,并在清理数据库时等待回调,因此需要承诺,否则下一步hook将启动,而不是等待上一个函数hook,例如:
onPrepare: function() {
return new Promise(function(resolve, reject) {
sauceConnectLauncher({
username: 'the_pianist2',
accessKey: '67224e83a-1cf7440d-8c88-857c4d3cde49',
}, function (err, sauceConnectProcess) {
if (err) {
return reject(err);
}
console.log('success');
resolve();
});
});
},
要启动sauce connect,我建议使用sauce服务,这样会更方便。在配置文件afterStep:function()中发布屏幕截图命令的最佳位置是什么??