Running Protractor tests can be frustratingly sluggish and frequently result in timeouts

After spending most of the afternoon struggling with this test, I've tried different approaches but none seem to work. The task at hand is searching for users within the company, generating a table, and selecting the user that matches the name. Currently, I use td.text-center which is not an ideal solution as it could break if there are other users with the same name in the system.

The second attempt seems to be the best solution, but it always returns an error saying the element is not found. Has anyone found a reliable way to locate TD elements within a table? The method I usually use works in other tables, just not this one...

  this.editUser = function(name) {

        // Original Code Block
        //browser.actions().mouseMove(element(by.css('td.text-center'))).perform();
        //var editUserBtn = element(by.css('.user-action-open'));
        //editUserBtn.click().then(function() {
        //    var editDetails = element(by.cssContainingText('li > a', 'Edit Details'));
        //    browser.wait(EC.visibilityOf(editDetails), 3000);
        //    editDetails.click();
        //});


        // Attempt 2

        // browser.actions().mouseMove(element(by.css('td.text-center'))).perform();
        //browser.sleep(3000);
        //var edit = element.all(by.repeater('user in users')).filter(function(rowElement){
        //    return rowElement.element.all(by.css('td[ng-bind="user.Firstname"]')).getText().then(function(text){
        //        return text.trim() == name;
        //    });
        //}).first();
        //browser.actions().mouseMove(edit).perform();


        // Currently just times out and doesn't find the element.

        var editUserButton = $('.user-action-open');
        browser.wait(EC.visibilityOf(editUserButton), 20000).then(function() {
            editUserButton.click().then(function() {
                var editDetails = element(by.cssContainingText('li > a', 'Edit Details'));
                browser.wait(EC.visibilityOf(editDetails), 3000);
                editDetails.click();
            });
        });
    }

Answer №1

Instead of using a fixed wait time of 3 seconds, consider utilizing ExpectedConditions for more efficient waiting. By implementing a browser wait, the script will pause until the specified object reaches the desired state within the timeout period.

    let users = element.all(by.repeater('user in users');

    // The code snippet highlights an element.all method
    // It indicates that multiple first names could be associated with a user
    let firstName = element(by.css('td[ng-bind="user.Firstname"]'));

    browser.actions().mouseMove(element(by.css('td.text-center'))).perform();

    // Wait for the repeater to be present or time out in 3 seconds
    browser.wait(users.isPresent(), 3000);

    let edit = element.all(users).filter((rowElement) => {
      // Wait for the first name and check if it matches the specified name
      // Resolve the promise to true if the conditions are met
      return browser.wait(rowElement.firstName, 3000).then(() => {
        return rowElement.firstName.getText().then((text) => {
          return text.trim() == name;
        });
      });
    }).first();

    browser.actions().mouseMove(edit).perform();

The correct syntax for rowElement.firstName may need to be verified.


Implementing Promise Chaining

  // Wait for the repeater to be present or time out in 3 seconds
  browser.wait(users.isPresent(), 3000).then(() => {
    let edit = element.all(users).filter((rowElement) => {
      // Wait for the first name and check if it matches the specified name
      // Resolve the promise to true if the conditions are met
      return browser.wait(rowElement.firstName, 3000).then(() => {
        return rowElement.firstName.getText().then((text) => {
          return text.trim() == name;
        });
      });
    }).first();

    browser.actions().mouseMove(edit).perform();
  }).catch(err => {
    // Handle any errors or failure cases appropriately
    fail("did not find users"); 
  });

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

Guide on updating individual rows in Google App Script using data from a different sheet

I am trying to create a script that will pull a value from column[3] in the ZONE sheet to the active sheet, specifically in column 56 of the job sheet when the zonelist value matches the zone value in different sheets. The script should check the range fro ...

Issue with FullCalendar-v4 not displaying all-day events

I am facing an issue with my calendar where recurring events are displaying correctly, but single allDay events are not rendering, and I suspect it may be a field problem. I've attempted to set the event's start time as an iso date, but it doesn ...

Tips for keeping a login session active on multiple tabs

As I am in the process of developing a website, one issue I am facing is determining the most effective method to maintain user login sessions. Currently, I am utilizing Html5 web storage known as "session storage" to keep track of whether a user is logged ...

Under what circumstances is it possible to iterate through an empty array?

When defining arrays in JavaScript using Array(n), it creates an empty array. If I write the following code: Array(2).map((val) => console.log(val)) Nothing happens when running this code, but if I spread out the elements of the array into another a ...

Displaying only the validation messages that are accurate according to the Vuetify rules

<v-text-field label='New Password' class="required" v-model='password' type='password' :rules="passwordRules" required> </v-text-field> passwordRules: [ value => !!value || 'Pl ...

Utilizing the JavaScript map method to structure API response data

Here is the JSON data I have: { "result": [{ "name": "a", "value": 20, "max": 100, "sale_value": [{ "no": 1, "name": "aaaaa", "price": 200 }, { "no": 2, ...

JavaScript to resize images before uploading without displaying a preview

I'm searching for a way to prevent the need to upload large or heavy image files. I believe utilizing the HTML5 FileAPI library is the best solution for this task. All necessary features have been implemented (upload, re-ordering, etc.), so now I ju ...

Images that are automatically generated cannot be interacted with by clicking on them

I currently have 4 images loaded onto my website. Whenever I click on one of the images, it becomes highlighted as desired using the following code: JavaScript Function 1 : var ImageSelector = function() { var imgs = null; var selImg = null; retu ...

Pair participants within a game search array

I've been contemplating this issue extensively but I'm struggling to come up with a fast and efficient solution using JavaScript. I have an array of objects representing game searches for random players. The array might resemble the following: co ...

The loading of the module from was hindered due to an invalid MIME type restriction

Exploring a three.js example and encountering an issue when utilizing import within a JavaScript module. The error message displayed is: Loading module from “http://localhost:8000/build/three.module.js” was blocked because of a disallowed MIME type ( ...

Is it possible to have dual images as the background for an HTML div?

Is it possible to use two images for a DIV background in CSS? I have one image that is just the background color and another that is a logo. Here's the code snippet I am currently using: .header{ background-attachment: scroll; background-clip ...

Rearranging anchor tag order with the power of JQuery

Imagine I have five anchor tags <a id = "A" class = "Home">Home</a> <a id = "B" class = "Maps">Maps</a> <a id = "C" class = "Plans">Plans</a> <a id = "D" class = "Community">Community</a> <a id = "E" clas ...

Angular - Automatically create thumbnails for uploaded images and videos

I am working on an Angular application that allows users to upload files. My goal is to create thumbnail images for uploaded images and videos without saving them locally. Instead, I plan to pass them along with the original file data to another API. Howev ...

Version 5.0.4 of Mui, when used with makeStyles and withStyles, is experiencing issues with applying styles to Mui

I've been diving into a react project using Mui v5.0.4 and encountered an unexpected issue with my custom styles. Initially, everything was functioning smoothly, but suddenly the styles I had defined were no longer appearing as intended in components ...

Display items from two different collections next to each other by utilizing two ng-repeat directives

I have 2 collections: one for names and one for values. How can I display them using bootstrap columns and angularjs, similar to the image provided in the link below? View the image for reference My attempted code is shown below, however, it does not giv ...

Unable to fetch JSON data, resorting to ngResource

I am currently working on a small football application project, aiming to enhance my skills with Angular 1 before moving onto Angular 2. I encountered some difficulties while trying to fetch JSON data from a specific URL. Although there is no Angular JS e ...

Executing jQuery AJAX requests in a chain with interdependent tasks

I am struggling to grasp the concept of magic deferred objects with jQuery. Consider the following code snippet: function callWebService(uri, filter, callback) { var data = {}; if (filter && filter != '') data['$filter&apos ...

Creating the appearance of a white sheet of paper on a computer screen

I appreciate all the comments provided earlier. Looking back, I realize I should have been more thorough in my explanation. Hopefully, the updated version will make things clearer. On a broad level, my goal is to create a digital screen background that re ...

"activeStyle" attribute consistently being implemented on links within pagesindex.js

Just starting out with Gatsby/React and web development in general, so apologies if this is an easy fix. I'm facing an issue that I can't seem to solve. Currently, I'm working on my website's header and trying to create links to naviga ...

What are the different ways to position div containers using CSS?

So I have multiple div sections on my webpage, and they are arranged vertically in the following manner: However, I would like them to appear more like this: This is the structure of my HTML: <div id="main"> <div id="header"> ...