protractor config file is not picking up the cucumber step definitions

后端 未结 2 586
轻奢々
轻奢々 2021-01-07 12:32

i am new to protractor and cucumber framework. i followed the steps from protractor site and here https://semaphoreci.com/community/tutorials/getting-started-with-protractor

相关标签:
2条回答
  • 2021-01-07 12:47

    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 .

    0 讨论(0)
  • 2021-01-07 12:51

    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.

    0 讨论(0)
提交回复
热议问题