0

webdriverJS を使用していくつかのキュウリ テストを作成しています。各シナリオの後に、アフター フックを使用してブラウザー ウィンドウを閉じようとしています。問題は、ウィンドウが閉じますが、再度開かないことです。ウィンドウが「見つからない」というエラーが表示されます。どんな助けや洞察も大歓迎です。

これが私の.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();
});
4

1 に答える 1

0

どうやら修正できたようです。興味深いのは、バックグラウンド ステートメントの関数で 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"
于 2014-07-09T17:12:34.083 に答える