codeceptjs / CodeceptJS

Supercharged End 2 End Testing Framework for NodeJS
http://codecept.io
MIT License
4.1k stars 722 forks source link

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

Closed Jtech42 closed 1 year ago

Jtech42 commented 5 years ago

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

Jtech42 commented 5 years ago

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