1
votes

I am having an e2e testing pack with protractor-cucumber-framework and Chai for asserting.

I have a Feature file with a data table as below.

Scenario: Menu Validation
        Given I am on the home page
        When I do Hover over the menu item I should have the menu dropdown
            |menu1                    |
            |menu2                    |
            |menu3                    |

I have the step definition as below.

When(/^I do Hover over the menu item I should have the menu dropdown/, (dataTable) => {
    let rootMenu : Array<string> = Array.from( dataTable.rawTable )
    rootMenu.forEach((ele) => {
        console.log(ele[0]);
        element(by.id(ele[0])).isPresent().then(function(present) { 
            expect(present).to.equal(true);
         });
    });
});

Even if the menu element ID is not present this test step never fail, I checked further the expect(present).to.equal(true); never get executed. I am not sure what I am missing.

1
there are many things I don't understand why you do them this way... for example why you do forEach of the rootMenu but then you say ele[0] like if the rootMenu was an array of arrays - Sergey Pleshakov
Yes, I have cucumber feature file which has a data table, The data table is an array of array. So rootMenu have data from the feature file like this [[menu1],[menu2],[menu3]] - Rasmi

1 Answers

0
votes

can you try this instead

When(/^I do Hover over the menu item I should have the menu dropdown/, async (dataTable) => {
    let rootMenu : Array<string> = Array.from( dataTable.rawTable )
    for (let i; i < rootMenu.length; i++) {
        let ele = = rootMenu[i];
        console.log(ele[0]);
        expect(await element(by.id(ele[0])).isPresent()).to.equal(true);
    }
})