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

Update the image and heading simultaneously when hovering over the parent div

I am looking to enhance the user experience on my website by changing the color of headings and images when a user hovers over a specific section. Currently, I have been able to achieve this effect individually for each element but not simultaneously. Any ...

What is the process for generating an alert box with protractor?

While conducting tests, I am attempting to trigger an alert pop-up box when transitioning my environment from testing to production while running scripts in Protractor. Can someone assist me with this? ...

Putting Jenkins, selenium-grid, and protractor to the test with end-to-end testing

Currently, I am in the process of setting up my testing environment using Jenkins, Selenium, and Protractor. To efficiently distribute tests across remote machines (nodes), I have opted to utilize the selenium-plugin (selenium grid). The initial progress i ...

Ensuring validation with Javascript upon submitting a form

Hey there, I'm looking to validate field values before submitting a form. Here's the code I have: <table width="600" border="0" align="left"> <tr> <script type="text/javascript"> function previewPrint() { var RegNumber = docum ...

`How can I validate a Firewall's web page using Powershell and the Selenium-Chrome Driver?`

In order to simplify the configuration process of work machines, I created a series of Powershell scripts that automate the tasks of disabling UAC, enabling autologon, and setting up Task Scheduler. This has saved us significant time by eliminating the nee ...

Do I have to divide the small functions in my Node.js controller into smaller ones?

When signing up users in my controller, do I need to break up the sign-up steps into individual asynchronous calls or is one big asynchronous call sufficient? Each step relies on the previous one: Validate user Create user Create group Add user to group ...

Unable to press a button

<button type="button" class="btn rd-button btn-ng-bs-animated clearfix" ng-disabled="false" ng-click="submitApplication(); $event.preventDefault();" is-submitting="isAppSubmitting" options="optionsSubmitBtn"> <div class="icons pull-left"> ...

Error 600: The element you have selected is not a valid target for this action. (Internet Explorer exclusive

I have been developing an AJAX calendar that functions perfectly in Chrome, Safari, and Firefox. However, I am encountering issues with Internet Explorer 9 and earlier versions. The error message I am receiving is SCRIPT 600: Invalid target element for th ...

Using the DRY principle in JavaScript to handle dynamic fields

Recently delving into Javascript, I encountered a dynamic field script that allows for adding and subtracting fields with the click of a button. The functionality is effective and serves its purpose well. $(document).ready(function() { var max_fields ...

Removing sourceMappingURL from an Angular Universal build: A step-by-step guide

Using this repository as my foundation, I have successfully resolved most of the plugin errors except for one that continues to elude me. It's puzzling because no other plugin anticipates a .map file in an SSR build since it is intended for productio ...

Retrieving queries from a sibling component using react-query: A step-by-step guide

I have a question regarding how to refetch a query from another sibling component using react-query. Let's consider Component A: import {useQuery} from "react-query"; function ComponentA(){ const fetchData = async () => data //re ...

Using Javascript to attach <head> elements can be accomplished with the .innerHTML property, however, it does not work with XML child nodes

Exploring new ways to achieve my goal here! I want to include one JS and one jQuery attachment for each head section on every page of my static website. My files are: home.html <head> <script src="https://ajax.googleapis.com/ajax/libs/jquer ...

Dynamically inserting a new row into a table with the power of jQuery

Currently working on dynamically adding rows to a table through jQuery in my project that follows MVC design pattern. I have set up a loop for the added rows, but need help with the script. Here is my code snippet for the loop : <?php $viewTableR ...

The issue with jquery slideToggle is that it mistakenly opens all divs instead of just the specific div that should

My website has a dynamic page with a variable number of <div> elements. The concept is that users can click on the + symbol, which is represented by an <img> tag, to display the corresponding div. Currently, my code includes: PHP/HTML $plus ...

Search for documents using jQuery on the page

Here is the layout of a page: HTML <div class="alert alert-dismissable"> <div class="form-group text-center"> <div id="Section"> <div class="row"> <div class="col-md-12"> ...

Guide to resolving the issue of DELETE error 404 not found in express.js

I enrolled in a MEAN Stack course and have been making progress. I can easily add new data and fetch existing data, but running into trouble when attempting to DELETE data. The error message reads as follows: "DELETE http://localhost:3200/posts/5e831685bf7 ...

Tips for displaying all documents within a MongoDB collection using the sharedb-cli command line tool

My client-demo is not working as expected. I am trying to retrieve all documents from the "file" collection, but I am getting null results. https://i.sstatic.net/Pw6sA.png When testing with the mongo shell, I can see that the document data actually exist ...

Verify that the user visits the URL in next.js

I need to ensure that a function only runs the first time a user visits a page, but not on subsequent visits. For example: When a user first opens the HOME page, a specific condition must be met. When they then visit the /about page, the condition for th ...

The timing of Angular 1.5 component $postLink execution becomes problematic when templateUrl is utilized

After reading through this article, I decided to dive into Angular's 1.5 component postLink event. To test it out, I created a plunker. Below is the code snippet for the tabs component: controller: function () { this.$onInit = function () { consol ...

What is the process for connecting a Wii Remote with Three.js?

Suppose I wanted to explore Wii Remote to browser interaction by connecting it to my Ubuntu laptop via Wiican and Wmgui using Bluetooth. What would be a simple program to achieve this? I have successfully used an Xbox Gamepad with Chrome, so I know that i ...