-1

The following error is occurred when we clicking the sub menus from main menu(Mouse hover).

Error Image Help me how to solve this issue.

if (browserLogs) {
    browserLogs.forEach(function (log) {
        var logLevel = context.config.failTestOnErrorLog.failTestOnErrorLogLevel ? context.config.failTestOnErrorLog.failTestOnErrorLogLevel : 900;
        var flag = false;
        if (log.level.value > logLevel) { // it's an error log
            if (context.config.failTestOnErrorLog.excludeKeywords) {
                context.config.failTestOnErrorLog.excludeKeywords.forEach(function (keyword) {
                    if (log.message.search(keyword) > -1) {
                        flag = true;
                    }
                });
            }
            expect(log.level.value > logLevel && flag).toEqualBecause(true, 'Error logs present in console:' + require('util').inspect(log));
        }
    })
}
DublinDev
  • 2,318
  • 2
  • 8
  • 31
Prakash
  • 11
  • 1
  • 1
    can you show the code you've got, you could have a typo or something else that would tell what the issue is. – Sam B. Feb 17 '19 at 18:15
  • Yeah we will for sure need the code. There is some problem with how you are identifying `Keywords` – DublinDev Feb 17 '19 at 18:25
  • I've downvoted also due to the lack of information. I suspect that your issue lies with fact keywords is likely an elementArray and therefore does not support the foreach method. Try using [each](https://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.each) if that is the case – DublinDev Feb 17 '19 at 19:45
  • Please find my below code. The following code i written in my base.js file. `this.clickByXpath = function(xpath){ element(by.xpath(xpath)).click(); console.log(xpath+" is clicked successfully"); } this.moveToElement = function(xpath){ var el = element(by.xpath(xpath)); browser.actions().mouseMove(el).perform(); }` – Prakash Feb 18 '19 at 07:28
  • Then i called this into another js file `this.clickMenu = function(){ base_page.moveToElement(objects.locators.SalesOrganization.menu_xpath); base_page.clickByXpath(objects.locators.SalesOrganization.selectMenu_xpath);` – Prakash Feb 18 '19 at 07:28
  • Thanks for providing that but this seems to be unrelated to your issue. Could you provide the code you are declaring `keywords` and where you are calling that forEach – DublinDev Feb 18 '19 at 12:22
  • Thanks, I didn't used forEach anywhere. My test steps are getting passed but after that i am getting this issue in console. – Prakash Feb 18 '19 at 17:21
  • 1
    i have added index.js forEach code above. please check it. – Prakash Feb 18 '19 at 17:28
  • Ah I see, originally it appeared keyword was a separate word but the screenshot has cleared things up for me. – DublinDev Feb 19 '19 at 20:54

1 Answers1

0

As you may know forEach is an array operation but I've frequently seen failures with it mistakenly being called on objects. Can you check if it is definitely an array by including the following two lines?

console.log(typeof context.config.failTestOnErrorLog.excludeKeywords);
console.log(Array.isArray(context.config.failTestOnErrorLog.excludeKeywords));

It it does turn out to be an object you can still loop over it using the information in this post.

Hope the helps, let me if it doesn't and I can suggest other options. Have seen this error many times.

DublinDev
  • 2,318
  • 2
  • 8
  • 31