CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Using await, with an I object function, inside of a helper, causes the scenario to exit.

Open Jtech42 opened this issue 7 years ago • 1 comments

What are you trying to achieve?

I need a Helper function to read some data:

  async processAllOptions(locator, selectDropdownsArr, uniqueMenuItem, I) {
  let priceCaloriesArr = [];
    for(let x = 0; x < selectDropdownsArr.length; x++){
          let result = await I.selectOption(locator, selectDropdownsArr[x]);
          priceCaloriesArr[x] = await selectDropdownsArr[x] + ":";
          priceCaloriesArr[x] += await this.getElementsText({"xpath":".//*[text()=\"" + uniqueMenuItem + "\"]/following::*[@class=\"productPrice ng-scope\"][1]"}) + ", ";
          priceCaloriesArr[x] += "Calorie Info: " + await this.getElementsText({"xpath":".//*[text()=\"" + uniqueMenuItem + "\"]/following::*[@class=\"caloriesInfo ng-scope\"][1]"}) + ", ";
        }
    return priceCaloriesArr;
  }

Without the await, I am seeing it read the pricing and calories text before the selectOption function completes, thus they are not changed yet. I need to wait on the I.selectOption function to complete, then check the text. Using a hard wait after I.selectOption also did not read the text correctly and showed again as if no option was selected.

What do you get instead?

Console just stops at the await I.selectOption step and exits the whole scenario.

Provide console output if related. Use --verbose mode for more details.

   './/*[text()="PEPSI"]//following::*[@class="productControllers custom-product-ctrls"][1]/div/div/select' }
    Emitted | step.before (I select option {"xpath":".//*[text()=\"PEPSI\"]//following::*[@class=\"productControllers custom-product-ctrls\"][1]/div/div/select"},...
    Emitted | step.after (I select option {"xpath":".//*[text()=\"PEPSI\"]//following::*[@class=\"productControllers custom-product-ctrls\"][1]/div/div/select"}, ...

ja@TRGTTT C:\Users\jason\Desktop\Website-Codeceptjs-Automation

Details

  • CodeceptJS version: latest
  • NodeJS Version: latest
  • Operating System: Windows
  • Protractor

Jtech42 avatar Mar 26 '19 15:03 Jtech42

I resolved this by writing a protractor function that selects options from dropdowns instead.

Jtech42 avatar Mar 29 '19 17:03 Jtech42