Search code examples
typescriptprotractor

AssertionError: object tested must be an array, a map, an object, a set, a string, or a weakset, but object given


I am trying to assert a drop down value under tab li. Here is my code for that:

await searchPage.enterSearch("/html/body/nw-search/nw-text-search/div/div/div/div/div[2]/input","Honda");
await  element.all(by.css("body > nw-search > nw-text-search > div > div > div > div > div.autocomplete-wrapper > ul > li:nth-child(1) > ul li")).then(async function(items) {
              expect(items.length).equals(5);
              await  expect(items[0].getText()).contain("honda: Civic");
            });

However, while running the above code I am getting below error. Even though I am passing a string. I tried both single quotes and double quotes. :

AssertionError: object tested must be an array, a map, an object, a set, a string, or a weakset, but object given


Solution

  • Items is not an Array, it is ElementArrayFinder. Use count method instead of length.