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

AngularJS: Iterating through all isolated scope directive templates and performing a click event on one of them

Here is the HTML code I am working with: <div ng-repeat="mydata in data" class="ng-scope ng-binding"> <p class="ng-binding">{{mydata.postdata}}</p> <div my-rating rating-value="rating" data-cat="post" data-id="mydata.id" >& ...

Switching between different elements in an array using React

I've got a collection of appointments and I need to create a React view that will show them one by one. Users should be able to navigate through the appointments using arrow buttons. Here's an example of what the data looks like: const arr = [ ...

Objects vanish 10 seconds after appearing [Angular2, *ngFor]

My Angular2 template is quite straightforward: <span *ngFor="let item of items"> {{ item.description }} </span> Here is the TypeScript logic for it: let list = new Map(); for(let j = 0; j < 100; j++) { list.set(j, { description: j.toS ...

Executing a JavaScript function using document.write()

When I try to click on the SWF part1 links within the document.write() function in order to call the openswf function, nothing happens. Here is my code: <html> <a href="#" onclick="Popup();">show popup</a> <script> functio ...

Guide to adding new data to a JSON array

I'm currently working on implementing a punishment system using discord.js where the actions taken against users are logged by the Discord bot in a JSON file. The structure of the punishment data is as follows: { "username": "baduser# ...

onpageshow event behaves as expected exclusively on webkit browsers (triggers function solely when visible on the screen)

I am inserting an HTML file using an object tag. The encompassing div of the object tag is hidden with a display:none property. However, I encounter an issue where the onpageshow event that I placed on the body tag of the HTML object behaves differently a ...

Utilizing shared enums in Angular services

My services contain an enum that I need to share with another service's method. How can I pass this enum as a parameter effectively? home.factory('myService', ['$dialogs', '$resource', function ($dialogs, $resource) { ...

Issues with the orderBy function are causing unexpected behavior

After creating 3 groups - priority 1, 2, and 3 with orderBy:priorty for each pushed task to go into their designated group, I noticed some strange behavior within the groups where they don't sort properly when more data is added. <input ng-model=" ...

AngularJS not displaying loader during AJAX request

While utilizing ajax requests with $http, there seems to be a delay due to the server operation taking longer than expected. I have implemented a loader to display while processing the request, but unfortunately it is not showing up on the page. Even after ...

Using PHP, Ajax, and JavaScript, display interactive data from the server in a dynamic modal popup listbox within a Tinymce-WordPress

Currently, I am in the process of developing a WordPress plugin using TinyMCE. The main functionality involves a button that triggers a popup modal with some list boxes. These list boxes need to be populated with values fetched from the server. To accompli ...

I am unable to create a visual representation using the data obtained from the API

After utilizing Redux-Saga to fetch data from an API, I encountered difficulties accessing the updated state. This issue may stem from attempting to retrieve the data before it has been fully loaded into the redux state. //saga.js import axios from ' ...

Error with redirect in Ajax request

I have a question regarding an Ajax issue (not using jQuery)... I am trying to extract the URL from a blog that has an RSS feed in XML format. I am attempting to access the link using Ajax, which is working fine most of the time. However, sometimes I enco ...

Incorporating a Custom CKEditor5 Build into an Angular Application

I am currently in the process of developing an article editor, utilizing the Angular Integration for CKEditor5. By following the provided documentation, I have successfully implemented the ClassicEditor build with the ckeditor component. Below are the ess ...

JavaScript event manually triggered not propagating within an element contained in an iFrame context

I am currently developing a WYSIWYG designer that enables users to choose colors through [input type="color"] fields. The interface includes inputs on the left side and an iFrame on the right side displaying the generated preview. Normally, when ...

JavaScript and Angular are used to define class level variables

Hello, I'm currently diving into Angular and have encountered an issue with a class level variable called moratoriumID in my component. I have a method that makes a POST request and assigns the returned number to moratoriumID. Everything seems to work ...

Mastering the Art of Modifying HTML with Node.js

Is it possible to manipulate HTML using Node.js? 1. First, I need to retrieve data from a database. 2. Then, I need to modify or add HTML code within Node. In essence, the goal is to fetch data and integrate it into an HTML file. The JavaScript snippet ...

CSS3 Animation: Facing issue with forwards fill behavior in Safari when using position and display properties

After creating a CSS3 animation to fade out an element by adjusting its opacity from 1 to 0 and changing the position to absolute and display to none in the last frames, I encountered an issue. In Safari, only the opacity is maintained while the position a ...

Serialize a form while keeping the submitted data private

Is there a way to achieve serialization without triggering the submit function for an ajax call? I've searched extensively for a solution to this issue without any luck. The java script function is invoked when a button within the form is clicked. do ...

Understanding the process of parsing JSON response using JavaScript

I am facing an issue with reading a JSON object in JavaScript. I have received this JSON object as a response and now I need to create a jstree based on it. Here is my JavaScript code: var repoId = $('#frmHdnV').val(); // variable to hold req ...

Automatically selecting a row within Material-UI's data grid using React code

Currently, I am in the process of developing a React web application and utilizing DataGrid from Material-UI by Google. The grid displays based on the user's selection from a select list (e.g., if the select list consists of fruits and the user choose ...