protractor config file is not picking up the cucumber step definitions

不羁的心 提交于 2019-12-01 01:12:29

It's trying to use CucumberJS 2.0.0+ syntax - which is in development at the moment.

Either downgrade CucumberJS to 1.3.1 or below, or do this to your step definitions:

var chai = require('chai'),
    expect = chai.expect,
    chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

var {defineSupportCode} = require('cucumber');

defineSupportCode(({Given, When, Then}) => {
  Given(/^I go to "([^"]*)"$/, function(site) {
    return browser.get(site);
  });

  When(/^I add "([^"]*)" in the task field$/, function(task) {
    return element(by.model('todoList.todoText')).sendKeys(task);
  });

  When(/^I click the add button$/, function() {
    var el = element(by.css('[value="add"]'));
    return el.click();
  });

  Then(/^I should see my new task in the list$/, function() {
    var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).to.eventually.equal(3);
    return expect(todoList.get(2).getText()).to.eventually.equal('Do not Be Awesome');
  });
});

Which is the CucumberJS 2.0.0+ syntax

Edit

There are two ways of setting timeouts in CucumberJS 2.0.0

Default timeout

This is to set the default timeout for all of the scenarios that you have:

let scenarioTimeout = 200 * 1000,
    {defineSupportCode} = require('cucumber');

defineSupportCode(({setDefaultTimeout}) => {
    setDefaultTimeout(scenarioTimeout);
});

In this example, I am setting the scenario timeout to 200 seconds. You can change this to whatever you feel is appropriate.

Individual Steps

This is to set the timeout for a slow step:

 When(/^I click the add button$/, {timeout: 60 * 1000}, function() {
    var el = element(by.css('[value="add"]'));
    return el.click();
  });

In this example, the timeout is set to 60 seconds, you may want this larger or smaller, depending on what the step is doing.

Bárbara Cabral da Conceição

In your config file:

require: ['./features/step_definitions/*.steps.js'],

But your file is: testone_steps.js, it should be: testone.steps.js

D'you see the difference? Just change _ to ., because in your config file you are using .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!