Issue arises when Protractor is unable to compare a variable with a web element due to unresolved promises

My strategy for this examination was to extract the inner text of an element, modify it, and then verify that the change had taken place by comparing the element with the variable.

var fixedValue = element(by.xpath('/html/body/section/div/section/section[2]/div[1]/ul/li[4]/a/span[2]')).getText();
var totalValue = element(by.xpath('/html/body/section/div/section/section[2]/div[1]/ul/li[1]/a/span[2]')).getText();
var progressValue = element(by.xpath('/html/body/section/div/section/section[2]/div[1]/ul/li[3]/a/span[2]')).getText();

Modify elements then validate changes

expect(element(by.xpath('/html/body/section/div/section/section[2]/div[1]/ul/li[3]/a/span[2]')).getText()).toEqual(progressValue);

Unfortunately, my console displayed a failed assertion message

Expected '17' to equal NaN 

This issue seems to be due to the fact that the promise of the first variable has not been fulfilled yet, leaving nothing to compare against.

Therefore, I'm wondering how I can instruct the expectation to take into account the initial variable value.

Answer №1

Protractor was designed with the intention of simplifying tasks like this. For instance, you can easily locate text using by.binding() or by.model(), which handle the process of waiting for promises, server requests, and more to be completed.

To better understand how to do this, check out the tutorial page and pay close attention to step 1.

If you've attempted these methods without success, or if they don't fully address your specific situation, consider editing your question to provide additional details. It's generally advisable to avoid writing tests in a manner that is prone to breaking (such as when refactoring views). In my experience, utilizing page objects has proven to be very beneficial.

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

Configuring IP Whitelisting for Firebase Cloud Functions with MongoDB Cluster

What is the process for including my Firebase Cloud Functions in the IP whitelist of my MongoDB cluster? Error Message: ...

Create an mp3 file using the arrayBuffer functionality

Struggling with StackOverflow, I attempted to record audio from a Raspberry Pi using Node.js (1). The audio stream is then sent through a WebSocket server (code omitted for simplicity), where a Vue.js WebSocket listens to the stream. My goal is to save thi ...

What is the best way to incorporate this HTML and script into a React component?

After receiving the embedded HTML and script from a platform, I discovered that a button triggers the script. It was originally designed to be embedded on a website, but I am attempting to integrate it into a React application. Here is the code provided fo ...

Tips for displaying or concealing table rows with form fields on a php site by utilizing jquery/ajax and a drop-down menu selection

Is there a way to hide or unhide table rows with form fields in a php website based on a dropdown selection using jquery/ajax? The current script I have only hides the field, leaving blank rows. How can I also hide the respective table rows? Thank you for ...

Issue: Package 'cairo' not located on EC2 Bitnami MEAN server

Setting up my MEAN application on a Bitnami server has been quite a challenge. During the installation of dependencies, I encountered an error that I just can't seem to resolve. Despite following the instructions provided in the error message, I am st ...

Utilizing the power of Ionic Native with AngularJS 1 for Cordova SQLite Integration

I am interested in implementing DeepLinking in my hybrid application using ionic-native. Currently, I have a functioning project with an SQLite database that has been tested on both iOS and Android platforms. However, when I include ionic.native in my app ...

extracting information from an HTML table about a child

I am attempting to extract table data from a specific website. Below is a snippet of the HTML content available at this link: : <div class="warn-data"> <table> <thead> <tr> ...

Wheelnav.js implementing a dynamic bouncing animation

I'm currently in the process of working on a pie menu with wheelnav.js and everything is going smoothly so far. However, I can't seem to find any information in the wheelnav.js documentation on how to eliminate the bouncing effect when a menu cho ...

What is the best way to incorporate a function within a $.click (jquery) event that utilizes an id directly from the clicked element?

It seems that my title may not be very clear, but I have a jQuery code snippet that is causing some issues. The problem stems from the fact that when I click on an image with the class 'slideimg', I expect a function named slideDo to be executed, ...

jQuery dropdown menu button impacts the entire webpage

I created this jQuery code to modify the drop menu elements, but it ended up affecting the entire page. How can I resolve this issue? $(".dropmenuac").on("click",function(){ $(".dropmenulist").css("opacity",& ...

`AngularJS Integration in Liferay`

Utilizing AngularJS globally within Liferay Portal is a strategy I would employ. The flexibility of AngularJS allows for dynamic views in web applications, enhancing the readability and development speed of the environment. I prefer leveraging the declara ...

The undefined dispatch function issue occurs when trying to pass parameters from a child component to React

There is an action that needs to be handled. It involves saving a new task with its name and description through an API call. export const saveNewTask = (taskName, taskDescription) => async dispatch => { console.log(taskName, taskDescription); c ...

Retrieving Ajax Data Using C#

I am struggling to send data through Ajax to a C# file. Whenever I check the received data, it always comes back as null. Could there be an issue in my code? Javascript file $(".save").click(function () { var ss = "Helloo!"; $.ajax({ typ ...

Which scraping tool should be used to extract web data: Scrapy, Selenium, or Mechanize

Looking to gather data from a website, I noticed it displays about 50 records in tabular form. To access more data, the user needs to click a button that triggers an ajax call to retrieve and display the next 50 records. While Selenium webdriver (Python) ...

Sorting tables with jQuery UI sortable() and rowspan功能

Can jQuery UI's sortable() be configured to sort rows based on their "containing" element only? I have a table with rowspanned cells that should only be sorted within their respective spanned columns. var $sortable = $('.nested-sortable tbody&ap ...

Implementing jQuery functionality on elements that are generated dynamically

I'm facing a challenge when working with dynamic elements in jQuery and I really could use some help. Let me provide an example from my current project: main.js $(function () { renderPlaceList(places); setupVoting(); } The two functions are ...

Establishing a user session with Node.js

I am new to the world of node.js and JavaScript in general. I have a piece of code that currently handles login functionality by checking if a user exists in a MYSQL database. This part is functioning correctly. Now, I wish to improve this feature by crea ...

Tips for building a custom error handling function specifically designed for parsing and handling errors in

Is there a way to reduce redundancy in my code, such as: let name = ""; try { name = data[" "][0][" "][0][" "][0][" "][1][" "][0][" "][1]["C"]; } catch (error) { if (error instanceof TypeError) { console.log("name TypeError"); } } I have consid ...

Ways to receive JavaScript console error messages to aid in debugging your code

Currently, I am developing a Web Application and facing an issue with capturing console errors. Specifically, I need to capture errors related to network connectivity issues, such as when the network is down or slow causing responses from the server to be ...

Tips for passing input fields from a React Function component to a function

How can I retrieve the values from 4 input fields in my react functional component using a function called contactMeButtonPressed? The inputs include name, email, company name, and message when the contact me button is clicked. Do I need to implement stat ...