0

I've been trying to catch and throw this error thinking that might be the issue but the test still passes. I am at a loss as to how to catch/throw this (if that is the issue) so the test will fail when the assertion fails.

The Error Msg -

UnhandledPromiseRejectionWarning: AssertionError: expected '25' to equal '2500'
    at selectElement.getText.then
...
1 scenario (1 passed)
13 steps (13 passed)

Here is my code Feature Code

Then(/^I verify the below options are correct:$/, async (coverageTable: TableDefinition) => {
async function processArray2(array) {
  let ArrayList;
  let firstLetterlowerEl;
  let actualList;
  for (let i = 0; i < array.rows().length; i++) {
    ArrayList = Coverage_Defaults[array.rows()[i][0]][array.rows()[i][1]];
    firstLetterlowerEl = await array.rows()[i][0].charAt(0).toLowerCase() + array.rows()[i][0].slice(1);
    actualList = await coveragesAuto[firstLetterlowerEl].elementId;
    await assertions.assertDropDownSelectedValue(actualList,ArrayList);
  }
});

The assertion code

    public assertDropDownSelectedValue = async (elementId: string, expectedText: string, override?: string) => {
        try {
            let selectElement = override === 'xpath' ? element(by.xpath(elementId)).$('option:checked') : element(by.id(elementId)).$('option:checked');
            await selectElement.getText()
                .then((text: any) => expect(text).to.equal(expectedText)).catch(Err => {throw Err.stack})

        } catch (Err) {
            if (Err instanceof error.NoSuchElementError) {
                log.error(`${elementId} Element not found error \n ${Err.stack}`);
                throw Err.stack;
            } else if (Err instanceof error.ElementNotSelectableError) {
                log.error(Err.stack);
                throw Err.stack;
            } else {
                log.error(`Dropdown selected option does NOT match with expected text - elementId passed : ${elementId}`);
                throw Err;
            }
        }
    }
BruceEng
  • 1
  • 1
  • I should note that if I call the await assertions.assertDropDownSelectedValue(actualList,ArrayList) directly without the for loop that it works correctly (fails correctly). The reason I need the for loop is that I want to be able to loop through each value array in the table and compare it against the values of a dropdown. – BruceEng Oct 15 '19 at 18:57

1 Answers1

0

I think you need to use an IIFE for you loop.

Also if you are doing an await, its better to save the value of that promise in a variable and then using that variable instead of using a .then.

I also have a feeling that this error is because of your code missing a promise during execution. Because of that the for loop finishes before your complete code is executed. Thus the test passes but the exception fails.