Forum Discussion

MeltingDog's avatar
MeltingDog
Frequent Visitor
5 months ago

Stuck with Cucumber.js - how do I run the same test on different pages?

Hi all,

 

I'm new to Cucumber.js and automated testing in general. I am using Selenium Webdriver and Cucumber.js to run tests from Node.js, and so far so good.

However, I have a hopefully simple problem I just can't seem to find a solution to:

 

How do I run the same test without triggering the "Multiple step definitions match" error?

 

Say, I have 2 .feature files:

 

 

Feature: Home Page

    Scenario: Check the home page
        Given I am on the home page
        Then there should be a banner
        // other tests

 

and

 

Feature: About Page

    Scenario: Check the about page
        Given I am on the about page
        Then there should be a banner
        // other test

 

 

On their respective .js steps files (homePageSteps.js and aboutPageSteps.js) I have the expression:

 

 

Then('there should be a banner', async function() {
    var homeBanner = await banners.checkBannerExists(this, 'banner');
    assert.ok(homeBanner!==null);
});

 

 

But of course running either feature file gives the error:

 

 

 ✖ Then there should be a banner
       Multiple step definitions match:
         there should be a banner - features/pages/steps/homePageSteps.js:32         
         there should be a banner - features/pages/steps/aboutPageSteps.js:20

 

 

Does anyone know how I should be going about using the same test in multiple places/pages?

 

PS: I have extracted the checkBannerExists function to `./support/components/banner.js` as such:

 

const { By } = require('selenium-webdriver');

async function checkBannerExists(webdriver, bannerClass) {
    var banner = await webdriver.driver.findElement(By.className(bannerClass)).getRect();
    return banner.height;
  };

module.exports = { checkBannerExists };

 

 

No RepliesBe the first to reply