Forum Discussion

Steve48's avatar
Steve48
New Contributor
4 years ago

Cucumber: My test scenario is running twice - I only want it to run once

I am running a cucumber puppeteer project in node.js

I have only one feature file with one scenario. I have only one step file. In the last step I close the browser. However the browser re-launches and repeats the test. Both runs pass with no failures. How do I stop the repeat test?

 

This is feature file

-------------------------------------------

Feature: Roll Forward and Back

    Scenario: Verify pro2 login, roll forward
        Given The browser is open
        When I open pro2 site
        When I enter valid username and password
        When I click the login button
        Then I see Select Company Dialog

        When I click Select dropdown
        Then I see list of companies

        When I select xxx company
        When I click Login to Company
        Then I go to home page


        When I select mymodel in model list
        When I click on the Revenue folder in left nav
        When I click on Revenue Summary 2 in left nav
        When I go to Revenue Summary page
        When I click on Roll Forward in top menu bar
        When I see Roll Model Forward Dialog

        When I click on arrow to the right of the current Month
        When I see a confirmation dialog

        When I click Save
        Then I confirm that Forecast start period in the grid has increased by 1 month
        When I save the Forecast date
        When I click on TOC
        Then I confirm TOC Forecast start period is correct

        When I again click on Roll Forward in top menu bar
        Then I confirm that the Forecast start period in the dialog box has increased by 1 month

        
        When I click on arrow to the left of the current month
        When I again see a confirmation dialog
        When I again click Save
        When I again click on Revenue Summary 2 in left nav
        Then I confirm that Forecast start period in the grid has decreased by 1 month




 

const { When, Then, Given } = require("cucumber")
var chai = require('chai')
    , expect = chai.expect()
    , should = chai.should()
const puppeteer = require("puppeteer")
const dotenv = require("dotenv")
dotenv.config({ path: 'config.env' });
const company = 'xxx';
let utils = require('./../../utility/utils');
let dateDifferenceDays;
let originalDateStr;
let originalDate;
let rolledDateStr;
let rolledDate;
let originaFirstForecastColumnLetter;
let originaFirstForecastColumnInt;
let rolledFirstForecastColumnLetter;
let rolledFirstForecastColumnInt;
let forecastDate;

async function openBrowser() {
    return await this.launchBrowser();
    // this.browser = await puppeteer.launch({ headless: false, defaultViewport: null })
    // this.page = await this.browser.newPage();
}

async function openPro2Site() {
    expectedUrl = 'https://pro2.xxx.com';
    return await this.visit(expectedUrl);
}

async function enterValidUsernameAndPassword() {
    return await this.fillLoginForm(process.env.USER);
    // await this.page.waitForFunction(
    //     'document.querySelector("#inputEmail")'
    // );
    // await this.page.type('#inputEmail', process.env.USER);
    // await this.page.type('#inputPassword', process.env.PASSWORD);

}

async function clickLoginButton() {
    await this.page.waitForFunction(
        'document.querySelector("body").innerText.includes("Login")'
    );
    await this.page.click('button[class="btn btn-block mt-2"]');
}

async function selectCompanyDialog() {
    await this.page.waitForFunction(
        'document.querySelector("body").innerText.includes("Select Company")'
    );
}

async function clickSelectDropdown() {
// try input[id=["react-select-2-input"];
    //const selector = '.css-1e07y6s';
    const selector='input[id="react-select-2-input"]';
    return await this.clickSelectDropdown(company, selector);
    //return await this.clickAfterWaitForSelector(selector);
}

async function selectIndoreCCompany() {

    const selector = '#react-select-2-option-24';
    await this.clickSelectedCompany(company, selector,1000);
}

async function loginToCompany() {
    await this.page.waitFor(500);
    await this.page.click('button[class="btn btn-block mt-3"]');
}
async function seeCompanyList() {
    await this.page.waitForFunction(
        'document.querySelector("body").innerText.includes("xxx")'
    );
}

async function goToHomePage() {
    await this.page.waitFor(1500);
    await this.page.url().should.equal('https://pro2.xxx.com/#/');
    console.log('got to login 100');
}
async function selectMyModel() {
    await this.page.waitFor(20000);// This was very necessary
    //Expose selected model title h4
    const btnSelector = 'button[class="btn btn-lg modu-threepointbt br-left-30 br-right-30"]';
    //Expose model list
    await this.page.click(btnSelector);
    await this.page.waitFor(5000);

    const result0 = await this.page.evaluate(() => {
        [...element] = document.querySelectorAll('h4[class="addmodul-name"]');
        return [...element.map(x => x.textContent.trim())];
    });


    let selectedModel = result0[0];

    if (selectedModel !== 'mymodel') {

        const result = await this.page.evaluate(() => {
            [...element] = document.querySelectorAll('span[id="updateModal"]');
            return [...element.map(x => x.textContent.trim())];
        });

        const model = 'mymodel';
        const foundIndex = result.indexOf(model)

        let selector3 = `.appendmod-header li:nth-child(${foundIndex + 1}) > #updateModal`;

        await this.clickAfterWaitForSelector(selector3);

        await this.page.waitFor(5000);
    }
    //close model list
    await this.page.click(btnSelector);
}

async function clickRevenueFolder() {
    let selector;
    const result = await this.page.evaluate(() => {
        [...element] = document.querySelectorAll('a[href^="#function"');
        return [...element.map(x => x.textContent.trim())];
    });
    const folderTitle = 'Revenue';
    const foundIndex = result.indexOf(folderTitle)
    if (result[0] === 'Financial') {
        selector = 'a[href="#function1"]';
    } else {
        selector = 'a[href="#function0"]';
    }

    await this.clickSelector(selector);
}

async function clickRevenuePage() {
    this.page.waitFor(8000);
    await this.page.evaluate(() => {
        selector = 'a[href="#/sheet/6106"]'
        this.document.querySelector(selector).click()
    })
}


async function verifyRevenueSummaryPage() {
    const url = 'https://pro2.xxx.com/#/sheet/6106';
    //const wait = 25000;
    const wait = 5000;
    await this.verifyUrl(url, wait);
}


async function clickRollForwardInMenu() {
    const selector = 'a[id="rollmodelDropdown"]';
    await this.clickSelector(selector);

}

async function getOriginalDate() {
    //from dialog box
    const selectorTitle = 'p[class="dropdown-item title"]';
    const selectorDate = 'div[class="rollmodel_cal_date"]';
    originalDate = await this.getOriginalForecastDateStr(selectorTitle, selectorDate);
    // format Dec-22

}
async function clickRollForwardArrow() {
    const selector = 'i[class="fas fa-chevron-right"]'
    await this.clickAfterWaitForSelector(selector);
}

async function waitForConfirmationDialog() {

    const selector = 'section[class="modal-main liappend-headermodal position-relative"]';

    await this.waitForThisSelector(selector);
}

async function clickSave() {

    const selector = 'button[class="btn mymodalbtn_save float-right"]'
    await this.clickAfterWaitForSelector(selector);
}

// async function waitForToaster() {
//     selector = 'document.querySelector("body").innerText.includes("forecast date updated successfully")'
//     vanishDelay = 10 * 1000;
//     await this.confirmToaster(selector, vanishDelay);
// }

async function confirmRollForwardGrid() {
    const selector = 'div.grid-column-header-forecast';
    const wait = (240 * 1000);
    const monthDifference = await this.confirmRollGrid(selector, originalDate, wait);
    monthDifference.should.equal(1);
}

async function saveForecastDate() {

    const selector = 'div.grid-column-header-forecast';

    forecastDate = await this.getForecastDate(selector, 0);


}

async function clickTOC() {
    const wait = 3 * 1000;

    selector = 'a[data-for="sidebarTableContent"]';

    await this.clickTOCInLeftNav(selector, wait);
}

async function confirmTOC() {
    //selector = 'div[class="custom-control custom-radio d-flex flex-row chart-time-frame-model-label-text"]';
    selector = '.w-90 > .form-row > .form-group > .d-flex:nth-child(2) > .custom-control:nth-child(2)'
    const wait = (1 * 1000);

    const monthDifference = await this.confirmTOCForecastDate(selector, forecastDate, wait);
    monthDifference.should.equal(0);

}

async function clickRollForwardInMenuAgain() {
    const selector = 'a[id="rollmodelDropdown"]';
    const wait = 10 * 1000;
    await this.clickSelector(selector, wait);
    await this.page.waitFor(2 * 1000);

}
async function confirmRollForwardDialog() {


    const selector = 'div[class="rollmodel_cal_date"]';
    rolledDateStr = await this.getRolledDateStr(selector);


    monthDifference = await this.confirmRollDialog(rolledDateStr, originalDate);

    monthDifference.should.equal(1);

}
async function clickRollBackwardArrow() {
    const selector = 'i[class="fas fa-chevron-left"]'
    await this.clickAfterWaitForSelector(selector);

}

async function confirmRollBackwardGrid() {

    const selector = 'div.grid-column-header-forecast';
    const wait = (30 * 1000);
    const monthDifference = await this.confirmRollGrid(selector, originalDate, wait);
    monthDifference.should.equal(0);
    await this.closeBrowser();
}
////////////////////////////////////

// async function clickRollBackwardArrow() {
//     selector='i[class="fas fa-chevron-left"]'

// }
/////////////////////////////////////

//LOGIN SECTION
Given("The browser is open", { timeout: 30000 }, openBrowser)
When("I open pro2 site", { timeout: 10000 }, openPro2Site);

When("I enter valid username and password", enterValidUsernameAndPassword);

When("I click the login button", clickLoginButton);

Then("I see Select Company Dialog", selectCompanyDialog);

When("I click Select dropdown", { timeout: 10000 }, clickSelectDropdown);

Then("I see list of companies", seeCompanyList);
When('I select IndoreC company', selectIndoreCCompany);
When('I click Login to Company', loginToCompany);

Then('I go to home page', goToHomePage);


//////////////////////////////////////
When('I select mymodel in model list', { timeout: 60000 }, selectMyModel);
When('I click on the Revenue folder in left nav', { timeout: 60000 }, clickRevenueFolder);
When('I click on Revenue Summary 2 in left nav', { timeout: 60000 }, clickRevenuePage);
When("I go to Revenue Summary page", { timeout: 60000 }, verifyRevenueSummaryPage);
When('I click on Roll Forward in top menu bar', clickRollForwardInMenu);
When('I see Roll Model Forward Dialog', getOriginalDate);
When('I click on arrow to the right of the current Month', clickRollForwardArrow);
When('I see a confirmation dialog', waitForConfirmationDialog);
When('I click Save', clickSave);
//When('I see a completion toaster within 4 minutes', { timeout: 240 * 1000 }, waitForToaster);
Then('I confirm that Forecast start period in the grid has increased by 1 month', { timeout: 250 * 1000 }, confirmRollForwardGrid);
When('I save the Forecast date', { timeout: 20000 }, saveForecastDate);
When('I click on TOC', { timeout: 20000 }, clickTOC);
Then('I confirm TOC Forecast start period is correct', { timeout: 20000 }, confirmTOC)
When('I again click on Roll Forward in top menu bar', { timeout: 20000 }, clickRollForwardInMenuAgain);
Then('I confirm that the Forecast start period in the dialog box has increased by 1 month', { timeout: 0 }, confirmRollForwardDialog);

When('I click on arrow to the left of the current month', clickRollBackwardArrow);
When('I again see a confirmation dialog', waitForConfirmationDialog);
When('I again click Save', clickSave);
When('I again click on Revenue Summary 2 in left nav', { timeout: 60000 }, clickRevenuePage);
Then('I confirm that Forecast start period in the grid has decreased by 1 month', { timeout: 60000 }, confirmRollBackwardGrid);




I am running a cucumber puppeteer project in node.js

I have only one feature file with one scenario. I have only one step file. In the last step I close the browser. However the breowser re-launches and repeats the test. Both runs pass with no failures. How do I stop the repeat test?

No RepliesBe the first to reply