Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在使用nightwatch断言失败后关闭浏览器会话_Javascript_Node.js_Assert_Nightwatch.js_Assertions - Fatal编程技术网

Javascript 在使用nightwatch断言失败后关闭浏览器会话

Javascript 在使用nightwatch断言失败后关闭浏览器会话,javascript,node.js,assert,nightwatch.js,assertions,Javascript,Node.js,Assert,Nightwatch.js,Assertions,我使用基于Nightwatch.js的Nightwatch Cucumber在node.js中为自动化测试实现了一个新的testframework。因此,有时我使用node.js断言来检查一些值。我在框架中使用PageObject模式。我的问题是浏览器会话在断言失败后没有关闭,我不知道为什么,也不知道如何解决这个问题 以下是我的定义: const { client } = require('nightwatch-cucumber'); const { defineSupportCode

我使用基于Nightwatch.js的Nightwatch Cucumber在node.js中为自动化测试实现了一个新的testframework。因此,有时我使用node.js断言来检查一些值。我在框架中使用PageObject模式。我的问题是浏览器会话在断言失败后没有关闭,我不知道为什么,也不知道如何解决这个问题

以下是我的定义:

const {
  client
} = require('nightwatch-cucumber');
const {
  defineSupportCode
} = require('cucumber');

const page = client.page.page();

defineSupportCode(({Given, When, Then}) => {
  When(/^test$/, () => {
    return page.test();
  });
});
这就是我的PageObject函数:

module.exports = {
  elements: {},
  commands: [{
    test() {
      //here the assertion failed and the browser session still exist and doen't close
      this.assert.equal(false, true);

      return this.api;
    }
  }]
};

那么,我该怎么做才能实现关闭浏览器和测试会话呢?只有当node.js断言失败时才会发生这种情况。

在每次测试结束后使用
挂钩始终关闭浏览器,无论结果如何。看

after:函数(浏览器){
console.log('关闭…');
browser.end();

},
要在每次测试后关闭会话,您必须在每次测试后将
挂接到测试文件,并按如下方式使用它:

afterEach : function(browser, done) {
  browser.end(function(){
    done();
  });
}
你的解决方案行不通,