2016-01-29 5 views
2

Каждый раз, когда я бегом тестов, я получил ошибку: TypeError: e.getContext не является функцияНе удается запустить огурец тесты с транспортиром

Я использую примеры из https://github.com/cucumber/cucumber-js с некоторыми изменениями в мире .js (сделал их, чтобы исправить ошибки тайм-аута)

версий приложений:

  • узел 4.2.6
  • огурец 0.9.4
  • транспортир 3.0.0
  • транспортир-огурец-основа 0.3.3
  • зомби 4.2.1

Мои world.js:

// features/support/world.js 
var zombie = require('zombie'); 
zombie.waitDuration = '30s'; 
function World() { 
    this.browser = new zombie(); // this.browser will be available in step definitions 
    this.visit = function (url, callback) { 
    this.browser.visit(url, callback); 
    }; 
} 

module.exports = function() { 
    this.World = World; 
    this.setDefaultTimeout(60 * 1000); 
}; 

Мои sampleSteps.js :

// features/step_definitions/my_step_definitions.js 

module.exports = function() { 
    this.Given(/^I am on the Cucumber.js GitHub repository$/, function (callback) { 
    // Express the regexp above with the code you wish you had. 
    // `this` is set to a World instance. 
    // i.e. you may use this.browser to execute the step: 

    this.visit('https://github.com/cucumber/cucumber-js', callback); 

    // The callback is passed to visit() so that when the job's finished, the next step can 
    // be executed by Cucumber. 
    }); 

    this.When(/^I go to the README file$/, function (callback) { 
    // Express the regexp above with the code you wish you had. Call callback() at the end 
    // of the step, or callback.pending() if the step is not yet implemented: 

    callback.pending(); 
    }); 

    this.Then(/^I should see "(.*)" as the page title$/, function (title, callback) { 
    // matching groups are passed as parameters to the step definition 

    var pageTitle = this.browser.text('title'); 
    if (title === pageTitle) { 
     callback(); 
    } else { 
     callback(new Error("Expected to be on page with title " + title)); 
    } 
    }); 
}; 

Мой sample.feature:

# features/my_feature.feature 

Feature: Example feature 
    As a user of Cucumber.js 
    I want to have documentation on Cucumber 
    So that I can concentrate on building awesome applications 

    Scenario: Reading documentation 
    Given I am on the Cucumber.js GitHub repository 
    When I go to the README file 
    Then I should see "Usage" as the page title 

Мои транспортир-conf.js:

exports.config = { 

    specs: [ 
    'features/**/*.feature' 
    ], 

    capabilities: { 
    'browserName': 'chrome' 
    }, 

    baseUrl: 'http://127.0.0.1:8000/', 

    framework: 'custom', 
    frameworkPath: require.resolve('protractor-cucumber-framework'), 
    // relevant cucumber command line options 
    cucumberOpts: { 
    require: ['features/support/world.js', 'features/sampleSteps.js'], 
    format: "summary" 
    } 
}; 
+1

Интересно. Я не использовал транспортир в сочетании с Zombie. Что произойдет, если вы переключитесь на использование только ChromeDriver? Кроме того, вы можете использовать холст на странице? Большинство ошибок, связанных с getContext, указывают на проблему доступа к элементам холста. –

+0

На каком этапе происходит ошибка? Запускает ли браузер хотя бы? – nilesh

ответ

1

Я имел такой же вопрос с этим примером. Проблема заключается в странице github.com. Какая проблема, я не знаю.

Итак, я внесла изменения для страницы, которую нужно посетить, и запуск тестов без TypeError: e.getContext не является функцией.

Я изменил sampleSteps.js файл:

module.exports = function() { 
    this.Given(/^I am on the Google.com$/, function (callback) { 
    // Express the regexp above with the code you wish you had. 
    // `this` is set to a World instance. 
    // i.e. you may use this.browser to execute the step: 

    this.visit('http://www.google.com/', callback); 

    // The callback is passed to visit() so that when the job's finished, the next step can 
    // be executed by Cucumber. 
    }); 

    this.When(/^I go to the SEARCH page$/, function (callback) { 
    // Express the regexp above with the code you wish you had. Call callback() at the end 
    // of the step, or callback.pending() if the step is not yet implemented: 

    // changed to this one, otherwise next steps also are skipped... 
    callback(); 
    }); 

    this.Then(/^I should see "(.*)" as the page title$/, function (title, callback) { 
    // matching groups are passed as parameters to the step definition 

    this.browser.assert.text('title', title); 

    callback(); 
    }); 
}; 

Тогда некоторые изменения sample.feature:

Feature: Example feature 
    As a user of Google.com 
    I want to have search with Google 
    So that I can find something 

    Scenario: Search something 
    Given I am on the Google.com 
    When I go to the SEARCH page 
    Then I should see "Google" as the page title 

Я надеюсь, что это поможет с первых шагов работы с cucumber- js и zombie.js.

Это не проблема с транспортиром, потому что та же проблема возникает, когда я запускаю этот образец в WebStorm.

Смежные вопросы