Testing infinite scrolling with the help of protractor

It seems like the infinite scrolling feature in ng-grid is not exactly infinite, but it's the closest comparison I could come up with for what I am observing.

In our application, we are using ng-grid to display data in a table with approximately 170 items (rows). However, when inspecting the repeater created by ng-grid in the browser, I noticed that it only loads and displays 35 items at a time. As you scroll down the list, the older rows at the top are removed from the DOM while new rows are added at the bottom. This behavior deviates from traditional infinite scrolling where more rows would usually be appended seamlessly.

To clarify, there are always 35 'ng-repeat=row in rendered rows' elements present in the DOM regardless of how far you have scrolled down the page.

This setup poses a challenge when trying to test the functionality. I need to retrieve and store the text of all 170 items in the list. However, methods like

element.all(by.binding('item.name'))
, by.repeater, or by.css do not work as they can access only the currently visible 35 items on the page.

Therefore, my question is how can I access and extract all 170 items as an object that can then be iterated through to gather their respective texts and store them in an array?

In other instances where we had fewer than 35 items displayed, I used bindings to create an object, followed by asynchronous processing to fetch and store the text of each row (see code snippet below for a modified example).

//column data contains only 35 rows, i need all 170.
var columnData = element.all(by.binding('row.entity.name')),
    colDataTextArr = [],
    prevOrderArray = ['item1', 'item2'... 'item 169', 'item 170'];

function getColumnData(columnData, colDataTextArr, prevOrderArray){
   columnData.then(function(colData){
        //using async to go over each row
       async.eachSeries(colData, function(colDataRow, nRow){
          //get the text for the current async row
         colDataRow.getText().then(function(colDataText){
           //add each rows text to an array
           colDataTextArr.push(colDataText);
           nRow()
         });
       }, function(err){
         if(err){
           console.log('Failed to process a row')
         }else{
           //perform the expect 
           return expect(colDataTextArr).toEqual(prevOrderArray);
         }
       });
     });
   }

Additionally, I acknowledge that iterating through 170 rows and storing the text in an array may not be the most efficient approach. Therefore, any suggestions for a better method are welcome.

I'm relatively new to JavaScript and web testing, so if I'm not using the correct terminology or if my explanation is unclear, please let me know, and I'll be happy to provide further clarification.

Answer №1

In my opinion, thoroughly testing each and every row in the grid may be excessive. It might suffice to verify that you are able to retrieve values for a few initial rows. If comprehensive testing is necessary, consider utilizing the evaluate() function.

http://angular.github.io/protractor/#/api?view=ElementFinder.prototype.evaluate

Although there isn't a specific code example provided on the API page, a sample implementation could resemble the following:

// Identify the element where an angular expression evaluation is required
element(by.css('grid-selector')).evaluate('rows').then(function(rows){
  // Access the value of the 'rows' scope variable bound to the element
  expect(rows[169].name).toEqual('some name');
});

Please inform me about the outcome if you decide to try this approach.

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

Exploring the capabilities of HTML5's file API along with Octokit.js to work with

I have been trying to create a form that allows users to upload binary data to GitHub using octokit.js. However, every time I attempt to do so, the data ends up corrupted on the GitHub side. Here is a minimal working example: http://jsfiddle.net/keddie/7r ...

Forbidden access error in codeigniter with Ajax request 403

I'm struggling to send a value via Ajax to a Controller file in Codeigniter, but unfortunately I haven't been successful. Despite researching this issue and finding that it has been asked many times before, I still can't seem to find a solut ...

What causes the session storage to be accessed across various browser sessions?

Scenario While working on an application, I discovered an intriguing behavior in Chrome 62 on Windows 10 related to defining values in sessionStorage. Surprisingly, changing a value in one tab affected other tabs that shared the same key. Initially, I b ...

Encountered a problem initializing Rangy.js on Internet Explorer

Currently, I am developing an angular application that utilizes textAngular along with rangy-core and rangy-selectionsaverestore. However, I am encountering some errors specifically on the latest version of Internet Explorer: Module 'WrappedSelection ...

Error: XYZ has already been declared in a higher scope in Typescript setInterval

I've come across an interesting issue where I'm creating a handler function and trying to set the current ref to the state's value plus 1: const useTimer = () => { const [seconds, setSeconds] = useState(0); const counterRef = useRef(n ...

Transform Promise-based code to use async/await

I'm attempting to rephrase this code using the async \ await syntax: public loadData(id: string): void { this.loadDataAsync() .then((data: any): void => { // Perform actions with data }) .catch((ex): v ...

Throw an error if the entry is not found in the Firebase database

I have an array containing various objects. Users should be able to access all objects using moduls/, and a specific one with moduls/$id. However, if the requested modul does not exist, the database should return an error to inform the client that there is ...

Tips for transmitting one or multiple data using jquery.ajax

I found this code on stackoverflow and it is working well for uploading multiple files. However, I am facing an issue where I cannot send additional parameters along with the file upload. Despite trying various methods, I have been unsuccessful in sending ...

Standardize date formatting in AngularJS

Retrieve the date in the shared format: {{ dateValue | date:{{dateFormat}} }} The following service is provided: app.service('formatting', function() { var format = new Object(); format.dateFormat = 'medium' var ...

The EJS view fails to render when called using the fetch API

Within my client-side JavaScript, I have implemented the following function which is executed upon an onclick event: function submitForm(event) { const data = { name, image_url }; console.log(data); fetch('/', { method: &apo ...

iOS Ionic Camera Plugin

I've encountered a common issue that I haven't been able to solve despite trying many solutions. While running my Ionic app on my IOS device, the camera plugin coding is returning undefined values and getting stuck before reaching the options va ...

Using Regex in Javascript to locate unfinished items that start and finish with brackets

Can anyone assist me in utilizing regex to identify any incomplete items that start with {{. I have attempted to search for instances in the string that begin with {{ and are followed by letters (a-Z) but do not end with }}. However, my attempts always re ...

Navigating through a predetermined list of HTML pages with next and previous options

Hey there, I'm in a bit of a quandary at the moment. I've been searching on Google for quite some time now, but unfortunately, I can't seem to find what I'm looking for. Hopefully, you guys can lend me a hand. What I'm trying to d ...

Initiate and terminate server using supertest

I've developed a server class that looks like this: import express, { Request, Response } from 'express'; export default class Server { server: any; exp: any; constructor() { this.exp = express(); this.exp.get('/' ...

JavaScript Age Calculator - Counting Days

Hey there! I've got an interesting problem. I currently have three text boxes on my webpage, and what I want to achieve is having a fourth text box generated when the user clicks a button. The content of this new text box should be filled with the dat ...

When working with jQuery, I encountered the error message "is not a function" because I mistakenly tried to use a function more than

While working on a pager, I encountered an issue with a function that is initially invoked when the document loads. However, when attempting to use it a second time, an error "is not a function" occurs. I am curious about the reason behind this phenomenon. ...

Footer Section (navigation) bounces up when scrolling to the beginning of the page

I am currently developing a fully web-based app-style layout. One issue I'm facing is that the navigation menu jumps slightly when I use my S3 to auto-scroll to the top by dragging. However, if I scroll up manually without lifting my finger, this pro ...

Error: myFunction has not been declared

Can anyone figure out what's going on here? http://jsfiddle.net/sVT54/ <button onclick="myFunction()">Click me</button> <p id="demo"></p> function myFunction() { document.getElementById("demo").innerHTML="Hello World"; } ...

Dropping challenging shapes in a block-matching game similar to Tetris

I'm currently working on a game similar to Tetris, but with a twist. Instead of removing just one line when it's full, I want to remove all connected pieces at once. However, I've run into a roadblock when trying to implement the hard-drop f ...

Trouble arises when accessing GET form in php/Ajax

I am in the process of creating a dynamic website. At the top, I have an input form that, when submitted, should display the output from an asynchronous request to a PHP page using echo to show what was submitted. Unfortunately, it's not functioning ...