Protractor anticipates returns with square brackets rather than quotation marks

I'm currently in the process of testing a webpage and I've encountered an issue with using a repeater and model to verify the text input.

My attempt at ensuring that the expected text matches what I want resulted in the following code snippet:

expect(element.all(by.repeater('n in [].constructor(product.config.num_streamers) track by $index')).get(1).all(by.model('name.value')).getAttribute('value')).toEqual("testtext");

The problem lies in the output showing an object with brackets instead of just plain text within quotes. The failed exception reads as follows: Expected [ 'testtext' ] to equal 'testtext'.

This failure is solely due to the presence of unnecessary brackets and spaces. Can someone please assist me in finding a solution and explaining why these brackets are appearing?

Answer №1

When you call getText() on a collection of elements (referred to as ElementArrayFinder in Protractor), it will return a promise that resolves into an array containing the texts of all the matching elements.

If you only need a single element, use .element instead of .all:

expect(element.all(by.repeater('n in [].constructor(product.config.num_streamers) track by $index')).get(1).element(by.model('name.value')).getAttribute('value')).toEqual("testtext");

Some extra tips:

  • You could have used the toContain() matcher instead of toEqual()
  • The track by part in the by.repeater() is automatically ignored by Protractor
  • To improve readability, consider declaring the element outside of the matcher or implementing the Page Object pattern for better organization:
  • var elm = element.all(by.repeater('n in [].constructor(product.config.num_streamers)')).get(1).element(by.model('name.value'));
    expect(elm.getAttribute('value')).toEqual("testtext");
    

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

Enhance the image with interactive shapes using JavaScript or JQuery

Looking to integrate dynamic shapes such as circles, rectangles, lines, ovals, etc. into images using a jQuery plugin or JavaScript. For example: https://i.sstatic.net/zXWCF.png Similar to how dynamic text can be added by typing in a textbox, I am lookin ...

Using Cordova plugman to add the initial platform-specific plugin into the project

Here are the system dependencies: cordova: @7.1.0 plugman: @2.0.0 I am trying to use plugman specifically for installing plugins on a particular platform (such as android). Having reviewed the documentation, I find that the workflow and usage is not en ...

Struggling to integrate selenium seamlessly with a dropdown menu (select element)

I am currently working on automating a task using Selenium, specifically trying to select a specific value from a dropdown menu. Below is an image showing the elements in question: https://i.sstatic.net/wwESM.png Here is the code snippet of the element: ...

Unlock the power of deep linking with the Branch SDK and integrate seamlessly with

Trying to utilize Branch's deep-linking features, particularly deferred deep-linking, in my Ionic project has been a challenge. The issue lies in the incomplete documentation provided for Cordova/Ionic integration by Branch. Despite installing their C ...

What are the solutions for resolving the Express.js 404 status error?

I am new to node.js and express.js and I am attempting to create a login form using MERN. Whenever I try to access the register route, I keep getting a 404 status error and I can't figure out what's wrong with my code. Can someone please help m ...

What is the process for incorporating a unique Mongo expression into a JSON object?

I'm currently trying to figure out how to add a specific Mongo command to my JSON object. Normally, adding regular strings or objects is straightforward, but I'm struggling with this particular command: $set : { "author" : req.body.name } Simpl ...

Encountering errors when initializing a JavaScript module through Angular2 instantiation

I have a situation where I need to utilize a plain JavaScript module within my Angular service. However, when I try to create an instance of the module in the constructor, I encounter the following error: TypeError: Engine is not a constructor The code ...

Update the DOM by setting the innerHTML with a template tag

I'm currently working on a Vue project and I'm facing an issue with setting the innerHTML of an HTML element using a template tag. Here's an example of what I've tried: let divElem = document.getElementById('divElem') let inne ...

Using a React button to sort through an array

Hey there, I'm currently working on an app that filters a list based on user input. The idea is to click on buttons to exclude users with specific letters in their names. However, the code I have right now isn't functioning properly. Any assistan ...

Utilizing shared code amongst React components

There are several components with methods similar to the ones below: class Header extends Component { sidebarToggle(e) { e.preventDefault(); document.body.classList.toggle('sidebar-hidden'); } sidebarMinimize(e) { e.preventDe ...

How can we avoid animations being interrupted by user interaction?

My webpage has an animation that runs smoothly on desktop, but stops as soon as I interact with the page on a touch device. I have tested this issue on Chrome and Safari on iPad. I'm curious if this behavior is intentional on the part of browser vend ...

How can I organize the selected options from a select2 form element using a basic sorting method?

I am utilizing select2 by ivaynberg and encountering an issue with the data arrangement upon submission. Is there a method to have the results in the form submit data reflect the order in which they were selected in the select2 element, without relying on ...

Detecting Changes in Angular Only Works Once when Dealing with File Input Fields

Issue arises with the file input field as it only allows uploading one file at a time, which needs to be modified. Uploading a single file works fine. However, upon attempting to upload multiple files, it appears that the "change" handler method is not tr ...

The intricacy of the jQuery each function and its interaction with $(this

EXPLANATION: I am working with two elements, each containing a set of options. The first element has options with db-ids as values, acting as parent categories. The second element is filled with options where the parent db-ids are their values and their o ...

Issues arising post transitioning to 14.0.0 from 13.0.0 version of ngx-masonry library leading to failed tests

Following the update to the latest stable version of the library ngx-masonry 14.0.0, our tests started failing. The release was just yesterday (24.10.2022) and you can find the changelog here: https://github.com/wynfred/ngx-masonry/blob/master/CHANGELOG.md ...

Running several Java versions simultaneously on a Windows 7 operating system

I am facing a compatibility issue where my selenium project requires Java 1.8 version to run, but the application itself runs on Java 1.6. Is there a way to set up different java versions for these two? I wonder if it's possible to make them work toge ...

Issues with ng-show and ng-hide not functioning as expected

Is there a way to hide a section when a certain variable is null? <ion-item class="item-avatar calm" id="detalleDeCita-list-item29" ui-sref="volare2.perfilDelAsesor" ng-show="asesor" > <h2calm>Asesor {{asesor}} <p>Ver perfil< ...

refreshing a react component when new props are received

Looking for a solution involving a React Native Component that requires an image URI as a prop? The prop is passed from another js file using the code snippet below: <SlideComponent imageUri={listOfAssets[counter].uri} /> The approach of passi ...

Initiating a horizontal scroll menu at the center of the screen: Step-by

I need assistance setting up a horizontal scrolling menu for my project. The requirement is to position the middle button in the center of the .scrollmenu div. Currently, I am working with HTML and CSS, but open to suggestions involving javascript as well ...

Find the position of an element in an array that includes a specific string value using JavaScript or Node.js

I need help figuring out how to find the index of an array that contains or includes a specific string value. Take a look at my code below to see what I've tried so far: Here is a simple example: var myarr = ["I", "like", "turtles"]; var arraycontai ...