Javascript 钩住后关闭窗口,但在下一个场景中不会重新打开

Javascript 钩住后关闭窗口,但在下一个场景中不会重新打开,javascript,cucumber,cucumberjs,webdriver-io,Javascript,Cucumber,Cucumberjs,Webdriver Io,我正在使用webdriverJS编写一些cumber测试。我试图在每个场景之后使用after钩子关闭浏览器窗口。问题是,窗口将关闭但不会重新打开。我得到的错误是它找不到窗口。任何帮助或见解都将不胜感激 这是我的.feature文件 Background Given I go to the website "..." Scenario: One When I click() on "..." When I getText() of the title "..." Then the title s

我正在使用webdriverJS编写一些cumber测试。我试图在每个场景之后使用after钩子关闭浏览器窗口。问题是,窗口将关闭但不会重新打开。我得到的错误是它找不到窗口。任何帮助或见解都将不胜感激

这是我的.feature文件

Background
Given I go to the website "..."

Scenario: One
When I click() on "..."
When I getText() of the title "..."
Then the title should be "..."

Scenario: Two
When I click() on "..."
When I getText() of the title "..."
Then the title should be "..."
这是我的hooks.js文件

var ID = null;

module.exports = function(){
this.After( function (err, next){
    client

    .getCurrentTabId( function(err, tabID){ 
        ID = tabID;
        expect(err).to.be.null;
        next() })

    .close( ID, function(err){
        console.log('-------------CLOSE-------------');
        next(); });
    });
};
下面是.js文件的前几行

   client = webdriverjs.remote({ desiredCapabilities: {browserName: 'safari'},   logLevel:   
            'verbose'});

module.exports = function()
{
  client.init();

this.Given(/^I go to the website "([^"]*)"$/, function (url, next){
    client
    .url(url)
    console.log("BACKGROUND STATEMENT");
    next();
});

看来我们能修好它。有趣的是,before钩子中的行不能在后台语句的函数中完成

这是一个.js文件,钩子和步骤定义在同一个文件中,但它们应该可以分开

webdriverjs = require('webdriverjs');

var sharedSteps = module.exports = function(){

this.Before(function(done) {
    console.log('TestCase Enter >>>');
    client      = webdriverjs.remote({ desiredCapabilities: {browserName: 'firefox'}, logLevel:   
                   'silent'}),
    client.init(done); });

this.After(function(done) {
    console.log('TestCase Exit >>>');
    client.close(done);})

this.Given(/^I go to the website "([^"]*)"$/, function (url, next) {
    console.log("BACKGROUND STATEMENT");        
    client
        .url(url)
        .call(next);});

this.When(/^I use getTitle\(\) to get title of this website$/, function (next) {
    client 
        .getTitle(function(err, title) {
            tmpResult = title;
            next(); });
 });

this.Then(/^the command should return "([^"]*)"$/, function (result, next) {
    next(); });

};

 module.exports = sharedSteps;
以下是.feature文件供您参考:

Feature: Hook Example

Scenario: Get title of website One
    When I go to the website "http://www.google.com"
    When I use getTitle() to get title of this website
    Then the command should return "Google"

Scenario: Get title of website Two
    When I go to the website "http://www.yahoo.com"
    When I use getTitle() to get title of this website
    Then the command should return "Yahoo"