How can you efficiently extract data from a variety of cells spanning across multiple rows in Protractor?

Need help with accessing and verifying data from specific cells in a table.

The table consists of 10 rows and each row has 13 cells. I want to extract values and perform assertions only on cells 1, 2, 3, and 5.

Below is the snippet of code I am using:

let rows = element.all(by.tagName('tr'));
    let data = rows.map((row) => { 
        let cells = row.all(by.tagName('td'));
        return {
            position: cells.get(1).getText(),
            category: cells.get(2).getText(),
            value: cells.get(3).getText(),
            points: cells.get(5).getText()
        }        
    })

    expect(data).to.deep.equal([
        {position: "1", category: "test1", value: "11", points: "3"},
        {position: "2", category: "test2", value: "12", points: "5"},
        {position: "3", category: "test3", value: "13", points: "3"},
        {position: "4", category: "test4", value: "14", points: "5"},
        {position: "5", category: "test5", value: "15", points: "3"},
        {position: "6", category: "test6", value: "16", points: "5"},
        {position: "7", category: "test7", value: "17", points: "3"},
        {position: "8", category: "test8", value: "18", points: "5"},
        {position: "9", category: "test9", value: "19", points: "3"},
        {position: "10", category: "test10", value: "20", points: "5"}
    ]);

Seeking assistance on resolving an error message that says:

AssertionError: expected { Object (flow_, stack_, ...) } to deeply equal [ Array(10) ]

Answer №1

Have you considered using expect([]).toEqual([]) instead?

If dealing with objects is causing difficulties, you can try using JSON.stringify.

expect(JSON.stringify(data)).toEqual('[{"....."}]');

Alternatively,

expect(JSON.stringify(data)).toMatch('[{"....."}]');

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

Long Waiting Time for the Ionic 2 Splash Screen

I've had struggles with the splash screen while developing several apps using ionic 2. The splash screen seems to take ages to disappear, and I understand that it's influenced by the number of plugins used and their response time. Is there a way ...

Encountering the error message "Type '{ theme: Theme; }' is not compatible with type" while attempting to pass it as a prop to the App component

Trying out a new strategy for my app initialization by incorporating the use of the useLocation hook within my App component. I'm still learning Typescript and encountering a problem. This is what I have so far: // index.tsx const theme: Theme = cre ...

What is the reason for the lack of automatic refresh in the browser when Component props are changed in App.js and they are used in the state of a class component?

Just getting into learning React and trying to grasp the distinction between props and state. Currently working with two files, App.js and Counter.js. In App.js: import Counter from './Counter' function App() { return ( <Counter initia ...

Modify a particular attribute in an array of objects

I am currently working on an Angular project and dealing with the following array object: { "DATA": [ { "CUSTOM1": [ { "value": "Item1", ...

You are unable to assign a string value instead of an object when making multiple selections

Utilizing react-select for autocomplete and option-related field has been quite helpful. However, I have noticed that in a single selection scenario, the code provided below only works when sending the value as a string. Unfortunately, it does not function ...

"Here's a simple guide to generating a random number within a specified range

I have encountered a specific issue: Within an 8-column grid, I am attempting to randomly place an item with a random span width. While I have successfully managed to position the item and give it a random width, I am struggling with adjusting the width b ...

Steps for displaying the contents of a popup window on the screen

I have attempted the following: <button onclick="window.print()" class="uk-button uk-float-left"><?php echo JText::_('COM_CSTUDOMUS_IMPRIMIR'); ?></button> Additionally: self.print() window.focus();window.print() When I try ...

Using optional function arguments with destructured arguments in TypeScript can result in throwing an error

interface Type1 { attr1: string; attr2: string; } interface Type2 { attr1: string; attr2: string; attr3: string; // additional attribute } function fn(config: Type1 | Type2): void { // The error code is displayed above. I am ...

Submit an image to Digital Ocean Space with Expo

I have been attempting to utilize the output image from the takePictureAsync function and upload it to a Digital Ocean Space using Expo. The uploading process with signed PUT URL appears to be functioning correctly, but I am encountering issues during the ...

Utilize jQuery to apply inline styles to dynamically created div elements

I am attempting to apply inline styles to a div using jQuery. The current state of the div, as seen in Firebug, is shown below: https://i.sstatic.net/rqhIc.jpg My goal is to retain the existing CSS while adding margin-left:0 and margin-right:0 to the cur ...

The expiration time and date for Express Session are being inaccurately configured

I'm experiencing an issue with my express session configuration. I have set the maxAge to be 1 hour from the current time. app.use( session({ secret: 'ASecretValue', saveUninitialized: false, resave: false, cookie: { secure ...

Rotating an object in Three.js along the radius of a sphere

I want to position an object at the end of a sphere's radius based on its coordinates (x, y, z). In traditional mathematical formulas for the coordinates of a point on a sphere, we use: var x = radius * Math.cos(phi) * Math.cos(theta); var y = radiu ...

Implement a horizontal scrollbar for your table in HTML

I need to implement a horizontal scroll bar for my table. Here is the HTML code: Even though I have utilized Bootstrap, the horizontal scroll bar is not working for this particular module. It works fine in other modules. The tbody data is added after an ...

`JQuery fadeOut seems to have a limitation where it only applies to the

I have a group of divs, each containing an anchor tag that triggers a JavaScript function (which uses AJAX to delete a row from a table). Here's an example setup: <div id="container"> <div><a id="btn" onclick="deleteRow()">Delet ...

Tips for arranging various information into a unified column within an Antd Table

Is there a way to display multiple data elements in a single cell of an Ant Design table, as it currently only allows insertion of one data element? I am attempting to combine both the 'transactionType' and 'sourceNo' into a single cell ...

Trigger/cease cron job with the click of a button within a Node.js Express application

I have been working on a project that involves starting and stopping a cron scheduler when a user interacts with a button on the front end. Essentially, clicking the start button initiates the cron job, while clicking the stop button halts the timer. It&ap ...

What is the reason behind the discrepancy in the results produced by the JavaScript `Intl.Collator.prototype.compare()` method compared to a standard UTF-16 comparison when

Today, I encountered a strange issue while working with the JavaScript / ECMAScript Internationalization API that has left me puzzled. It seems that comparing two specific characters - the forward-slash (/) and the underscore (_) - using different methods ...

Guidelines for releasing Node.js microservice client as a stand-alone package within the repository

For my current web application project, I have chosen to implement the client <-> api <-> [microservices] pattern. To challenge myself, I am developing my microservices in Clean Architecture with node.js using Typescript. Although I have alrea ...

Executing logical operations within a Higher Order Component based on a given prop collection

My application involves a higher order component that performs some logic and passes the result down as a prop to a functional component for displaying data. In my main component, I pass the 'percentage' prop down to my HOC: <Match input ...

Prevent selection of weekend dates in Angular Bootstrap datepicker with a personalized directive

I have integrated the Angular Bootstrap datepicker plugin into my Angular application. To customize the date pickers in my app, I created a custom directive. In certain places, I need to disable weekends in the date picker. I have added the functions to d ...