【发布时间】:2016-01-29 14:14:09
【问题描述】:
每次运行测试时,我都会收到错误:TypeError: e.getContext is not a function
我使用来自 https://github.com/cucumber/cucumber-js 的示例,对 world.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
我的 protractor-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"
}
};
【问题讨论】:
-
有趣。我没有将量角器与僵尸一起使用。如果您切换到只使用 ChromeDriver 会发生什么?另外,您是否可能在页面上使用画布?大多数与
getContext相关的错误都指向访问画布元素的问题。 -
错误发生在哪一步?浏览器是否至少启动?
标签: javascript testing protractor cucumberjs