I am new to automated testing, Selenium
and Cucumber.JS
and am trying to set it up in Node.JS
to run several tests on my website.
I have gotten single scenarios/test working fine, but I am a bit confused as to how to set up multiple Scenarios and Step files.
For example, if I wanted to check that my home page has both a working drop down menu and banner would I do (on home-page.feature
):
Feature: Home Page
Scenario: Check the home page
Given I am on the home page
When a main menu item is clicked
Then the dropdown menu should appear
And there should be a banner
Or:
Feature: Home Page
Scenario: Check the menu
Given I am on the home page
When a main menu item is clicked
Then the dropdown menu should appear
Scenario: Check the banner
Given I am on the home page
When the home page loads
Then there should be a banner
Also, if the latter, with the 2
scenarios, is better to do would I create 2 steps.js
files, or try to put 2
sets of Given()
, When()
, Then()
functions on the one homePageSteps.js
file, e.g. (not working):
Given('I am on the home page', async function () {
this.driver = new Builder()
.forBrowser('firefox')
.build();
this.driver.wait(until.elementLocated(By.tagName('h1')));
await this.driver.get('https://www.awebsite.com');
});
When('a main menu item is clicked', async function() {
var menuItems = await this.driver.findElements(By.className('main-menu-item'));
var firstMenuItem = menuItems[0];
firstMenuItem.click();
});
Then('the mega menu should appear', async function() {
var megaMenu = await this.driver.findElements(By.className('dropdown-menu'));
var megaMenuHeight = megaMenu[0].getCssValue("max-height");
assert.notEqual(megaMenuHeight, 0);
});
Given('I am on the home page', async function () {
this.driver = new Builder()
.forBrowser('firefox')
.build();
this.driver.wait(until.elementLocated(By.tagName('h1')));
await this.driver.get('https://www.awebsite.com/');
});
When('the home page loads', async function() {
// Something to tell that the page is loaded
});
Then('there should be a banner', async function() {
var banner = await driver.findElement(By.name('range_input')).getRect();
assert.ok(banner.height!==null)
});
I've tried searching for the right way to doing this, but everything I find seems to be tutorials on how to just do 1
scenario.
Could anyone point me in the right direction?