Utilizing .isDisplayed() in conjunction with .each() in ProtractorJS for Angular: A guide

Currently, I am working on setting up a test within my Angular application. The goal of this test is to click on an element and check if a specific object is displayed. While I believe the code provided below should work, I am aware that the isDisplayed() method is designed for a single element and not multiple elements. I have heard about the .each() function but I am unsure of how to incorporate it in this scenario. Can someone guide me on using .each() with isDisplayed()?

it('should flip cards and check to make sure graph is visible', function(){
var cards = element.all(by.repeater('card in cards'));
var backOfCard = element.all(by.css('#current-status ul li .back canvas'));

expect(browser.getCurrentUrl()).toEqual('http://localhost:8000/app/#/dashboard');
expect(cards.count()).toBe(4);
cards.click().then(function(){
    expect(backOfCard.isDisplayed()).toBe([true, true, true, true]);
});
});

Answer №1

It is possible to utilize the isDisplayed() function on a ElementArrayFinder:

expect(backOfCard.isDisplayed()).toBe([true, true, true, true]);

Another option is to use map() in this scenario:

var values = backOfCard.map(function (elm) {
    return elm.isDisplayed();
});
expect(values).toBe([true, true, true, true]);

Furthermore, you have the ability to employ reduce() to obtain a single boolean value for validation:

var allDisplayed = backOfCard.reduce(function (acc, elm) {
    return elm.isDisplayed().then(function (isDisplayed) {
        return isDisplayed && acc;
    });
}, false);
expect(allDisplayed).toBeTrue();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the purpose of utilizing "({ })" syntax in jQuery?

What is the purpose of using ({ }) in this context? Does it involve delegation? Can you explain the significance of utilizing this syntax? What elements are being encapsulated within it? For instance: $.ajaxSetup ({ // <-- HERE error: fError, ...

What are the best methods for retrieving data from a subcollection in Firebase/Firestore with maximum efficiency

Utilizing Firestore to store posts with simple properties like {title: 'hi', comment: true} has been a seamless process for fetching user-specific data, given the structure of my collection: posts/user.id/post/post.name. An example would be posts ...

Arrays passed as query parameters to Next.js router.query may result in the value being

When trying to pass objects from an array to another page using router.query, individual objects like router.query.title work as expected. However, when attempting to pass arrays such as router.query.reviews, it returns something like reviews: ['&apos ...

Testing factories with Jasmine and Angular: A step-by-step guide

After conducting thorough research online, I have come up empty-handed in finding a solution to my issue. Essentially, I have a factory declared in the following manner: angular.module('puFactories').factory('RestFactory', function ($h ...

Guidelines on maintaining an active getSelection with JavaScript

I need help figuring out how to change the font size of selected text within a div without losing the highlight/selection when I click a button. Can someone assist me in keeping the text highlighted while also resizing it upon clicking the button? ...

Error: The function is not defined on this.props during the handleCHange event

After going through numerous answers to similar questions on this topic, I believe that I am following all the necessary steps but for some reason, it is not working. Below is the specific section of code that is causing the error: import React from &apos ...

Error encountered: Selenium and ChromeDriver do not support the attribute execute.script for WebElement

After numerous online searches on how to make my Selenium taskbot scroll, I came across suggestions like using driver.execute_script("JS exec;"). However, I encountered an issue as my Selenium only recognizes a driver._execute() command and throws a KeyErr ...

Apply a dynamic function to assign a background color to a specific class

Currently, I have a function called getBackground(items) that returns a background color from a JSON file list. Within my application, there is a component that automatically adds a class name (.item-radio-checked) when a user clicks on an item in the list ...

`NodeJS and ExpressJS: A guide on accessing a remote phpMyAdmin server`

I am in the process of setting up a GraphQL server and facing an issue with connecting to a remote phpMyAdmin server provided by a friend. The error message I am encountering is: Error: getaddrinfo ENOTFOUND 54.193.13.37/phpmyadmin 54.193.13.37/phpmyadmi ...

Extract all potential outcomes from a search field that has a restriction on search results

Looking to extract all the names from a specific website using Python: Encountering an issue where it only fetches the top 50 results for each search. Experimented with wildcard searches in the last name field to narrow down subsequent searches, but this ...

Is it possible to retrieve the parent object?

My code snippet is as follows, and I'm struggling to access the data object from within the innerFn function. Is there a way to accomplish this? export default { data: { a: "a", b: "b" }, fn: { innerFn: () => co ...

The second node child process encounters execution issues in Linux

For a challenge, I needed to find a way to automatically restart my bot within itself. After some trial and error, I came up with a solution. However, when testing on a Raspberry Pi via ssh, the process exits after the first child process ends. Surprisingl ...

Can a single controller be shared between isolated directives?

This code snippet demonstrates a timeframe feature that displays tag information on the left and event information on the right. Each type of timeline within the timeframe contains two directives for the tag/event, each utilizing an abstract directive inte ...

What are some effective ways of using the parent, before, and children selectors?

<table> <tr><td><input type="text" value="123"></td><td><input class="here" type="text"></td></tr> <tr><td><input type="text" value="333"></td><td><input class=" ...

Validating properties of a class using Typescript's Class-Validator

I tried using the class-validator decorator library for validation processes on my sample project. However, it doesn't seem to be working as expected. The sample project aims to create projects based on user inputs, and I'm attempting to validate ...

Obtain GPS coordinates (latitude/longitude) from a Google map by dropping a marker on the

Is there a straightforward script that can load a Google Map and, when clicked, display a marker that saves the latitude and longitude values to a variable? Does anyone know if there is an existing PHP solution for this functionality? Appreciate any help ...

Is it possible to include multiple eventTypes in a single function call?

I have created a function in my service which looks like this: public refresh(area: string) { this.eventEmitter.emit({ area }); } The area parameter is used to update all child components when triggered by a click event in the parent. // Child Comp ...

Issue with adding to lightbox feature when loading content dynamically using AJAX PHP is not functioning as expected

Hey there! I've encountered an interesting issue with my code that adds models to a lightbox. It's functioning perfectly on static pages like this one. $scope.add = function(permalink, post_id) { if (typeof(Storage) !== "undefined") { ...

The alignment is off

<script> var myVar = setInterval(myTimer, 1000); function myTimer() { var d = new Date(); document.getElementById("demo").innerHTML = d.toLocaleTimeString(); } </script> <p text-align="right" id="demo" style="font-family:Comic Sans ...

Exploring the possibilities of using React for looping?

I have integrated Dexie.js with React for this specific example. However, the implementation details are not of great importance to me. My main focus is on finding out how to iterate through all objects in my IndexDB database using React. In the code snip ...