así que aquí está el código que tengo para cada uno y pongo una gran cantidad de datos en una matriz y luego vuelvo a repetir y verifico cada $. El objetivo es hacer un bucle `` así
it('should be able to search rolex in ebay and every price should have $ in it', () => { browser.url('./') $('[class="gh-tb ui-autocomplete-input"]').click(); $('[class="gh-tb ui-autocomplete-input"]').setValue("rolex"); browser.keys("Enter"); const searchResult = [] $$('[class="s-item__title"]').forEach((element) => { if (element.getText().length > 50) searchResult.push(element.getText().toLowerCase()); }); searchResult.every((i) => expect(i).to.have.lengthOf.above(5)) const priseOfSearch = [] $$('[class="s-item__price"]').forEach((element) => { if (element.getText().length > 0) priseOfSearch.push(element.getText().toLowerCase()); }); priseOfSearch.every((i) => expect(i).to.contain('$')); new verion it('should be able to search rolex in ebay and every price should have $ in it', () => { browser.url('./') $('[class="gh-tb ui-autocomplete-input"]').click(); $('[class="gh-tb ui-autocomplete-input"]').setValue("rolex"); browser.keys("Enter"); $$('[class="s-item__title"]').forEach((element) => { if (element.getText().length > 50) { expect(element.getText().toLowerCase().to.have.lengthOf.above(5)) } $$('[class="s-item__price"]').forEach((element) => { if (element.getText().length > 0) { expect(element.getText().toLowerCase().to.contain('$')); } }); }) }) })No tiene sentido usar .every() porque ese método devuelve un valor booleano y el valor de retorno no se usa en el código.
Tampoco tiene sentido probar la longitud del texto con expectativa, porque la condición ya confirma que todo el texto tendrá más de 5 caracteres (también más de 50 caracteres).
En la mayoría de las aplicaciones, está bien recorrer una matriz varias veces. Por lo general, no afecta el rendimiento de manera notable.
Para responder a su pregunta ahora, si desea iterar una vez, es posible llamando directamente al método expect en el ciclo forEach en lugar de filtrar y luego iterar.
$$('[class="s-item__title"]').forEach((element) => { if (element.getText().length > 50) { expect(element.getText().toLowerCase()).to.have.lengthOf.above(5) } });