Laurie
Laurie

Reputation: 43

Cucumber-js test showing as 'pending' when they should pass or fail

I am a new programmer. I am trying to set up a cucumber.io suite. I read the docs and set up the example from https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md. When I run the test provided, the example test passes, as expected.

Scenario: Reading documentation

✔ Given I am on the Cucumber.js GitHub repository

✔ When I click on "CLI"

✔ Then I should see "Running specific features"

1 scenario (1 passed)

3 steps (3 passed)

0m03.724s

Using the example as a starting point, when I add another .feature and .js file and run the test, all the actions for my new test are shown as 'pending'. Additionally, the first test no longer passes:

3 scenarios (1 ambiguous, 2 undefined)

10 steps (2 ambiguous, 7 undefined, 1 passed)

0m03.743s

Can anyone tell me what I need to do to have my tests run? What do I need to do to remove the ambiguous and undefined tests?

I checked my regex and it matches. I know my indenting is off here, but I am new to posting code!

My .feature file:

Feature: Sign In
As a returning user of examples
I want to log in the site
So that I can use the site

Scenario: Getting to the Sign in page via "Log In"
    Given I am on example.com
    When I click the "Sign In" button 
    Then I am taken to the login screen

Scenario: Entering my information 
    Given I am on the login and I am the landing tab "Log In" 
    When I enter my credentials
    And click the arrow
    Then I am successfully logged in 

My test:

var seleniumWebdriver = require('selenium-webdriver');
module.exports = function () {
this.Given(/^I am on I am on example.com$/, function() {
  return this.driver.get('https://example.com');
});

this.When(/^I click on "([^"]*)"$/, function (text) {
  return this.driver.findElement({linkText: text}).then(function(element) {
    return element.click();
  });
});

this.Then(/^I should see "([^"]*)"$/, function (text) {
  var xpath = "//*[contains(text(),'" + text + "')]";
  var condition = seleniumWebdriver.until.elementLocated({xpath: xpath});
   return this.driver.wait(condition, 5000);
  });
 };

Upvotes: 0

Views: 1280

Answers (1)

Grasshopper
Grasshopper

Reputation: 9058

Original scenario -

Scenario:
Given I am on the Cucumber.js GitHub repository - PASSED - This is the only step that passes that is present only in the original feature file.
When I click on "CLI" - AMBIGIOUS - This step is present in original feature file as well as the new feature file you created.
Then I should see "Running specific features" - AMBIGIOUS - This step is present in original feature file as well as the new feature file you created.

New scenario -

Scenario: Getting to the Sign in page via "Log In"
    Given I am on example.com - UNDEFINED - The step definition you have defined mentions 'I am on' twice instead of once. 
    When I click the "Sign In" button - UNDEFINED - No matching step.
    Then I am taken to the login screen - UNDEFINED - No matching step.

Scenario: Entering my information 
    Given I am on the login and I am the landing tab "Log In" - UNDEFINED - No matching step.
    When I enter my credentials - UNDEFINED - No matching step.
    And click the arrow - UNDEFINED - No matching step.
    Then I am successfully logged in - UNDEFINED - No matching step.

Thus you get 7 undefined, 2 ambiguous and 1 passed step. So the first original scenario becomes ambiguous and the other 2 undefined.

You need to remove the duplicate steps from the new test.js and add in new step definitions to match the new scenario steps.

Upvotes: 0

Related Questions