The while loop is missing a value assignment for an integer

I am attempting to retrieve page number values from the method getPageNumber(), where the page number is being printed in the console. However, that value is not being used in the While loop. Even when I try to print pageNum, it returns a promise. Refer to the console output. https://i.sstatic.net/7mUuv.png

it('TS-06, should be able to navigate to Manage Users Screen',function(){
        clientAdminPortal.clickMenuInSideBar("User Management");

        manageUsers.at().then(function() {
            console.log("---> Navigated to Manage Users Screen");

        });

        expect(manageUsers.isVisible(manageUsers.searchTxtBox)).toBeTruthy();
    });

 it('TS-10, verify Activate Button is viewed for all users',function(){
        var i=1;
        var check=false;
        var pageNum=manageUsers.getPageNumber();
        while(i<pageNum){
        console.log("check");
        i++;
 }
});

this.getPageNumber=function(){
        return this.pgnumCount.then(function(number){
            console.log(number.length);
            return number.length;
        });
    };

Answer №1

In order to handle the asynchronous behavior of this.getPageNumber() which returns a promise, it is essential to consume the promise using then(), as demonstrated below:

it('TS-10, check if Activate Button is visible for all users', function () {
    var i = 1;
    var check = false;

    manageUsers.getPageNumber().then(function (pageNum) {
        while (i < pageNum) {
            console.log("verified");
            i++;
        }
    });

});

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

The use of WebSockets in conjunction with text encoding techniques

After reviewing the material, I came across this information: The WebSocket API allows for the use of a DOMString object, which is transmitted in UTF-8 format, or it can also accept an ArrayBuffer, ArrayBufferView, or Blob objects for binary data transf ...

Converting JSON information into a JavaScript array of objects

I have a JSON file containing placeholder articles for testing purposes. I'm using jQuery to parse the data from the JSON file and create an array of objects with the retrieved information. Take a look at my JSON file: { "news": [ { ...

Input a new function

Trying to properly type this incoming function prop in a React Hook Component. Currently, I have just used any which is not ideal as I am still learning TypeScript: const FeaturedCompanies = (findFeaturedCompanies: any) => { ... } This is the plain fun ...

Tips on sending parameters from a PHP script to a Javascript file

I am struggling with my new journey into the world of JavaScript. I have been attempting to pass a parameter from a PHP file to a JavaScript file, but for some reason, it's just not working. Here's the code snippet: The JavaScript file is named ...

Assistance with changing styles

Hey there, I could really use some assistance. I've created a style switcher, but I'm struggling to figure out how to replace the stylesheet properly. Currently, my code empties the <head> element when what I really need is for it to simply ...

Encountering a TypeError with react-rte in Next.js: r.getEditorState is not a valid function

In my Next.js project, I am using a React RTE component. It is displaying correctly, but when I navigate to another component and then return using the browser's back button, I encounter the following error: Unhandled Runtime Error TypeError: r.getEd ...

outside vue component access method is not recommended

I am a newcomer to Vue.js and have implemented a comment feature similar to the one described here. However, due to certain constraints, I had to make adjustments. I used a Vue component but encountered an issue where it couldn't access a method insid ...

Converting JSON data from an XML document using PHP

While I have a decent understanding of xml and json parsing, I'm facing an issue with this particular site. Here is what I have tried: $json_string="http://meteo.arso.gov.si/uploads/probase/www/plus/timeline/timeline_radar_si_short.xml"; $json = fil ...

What is the process for showing a button once a typewriter animation has completed?

Is there a way to implement a typewriter effect that types out a text line and then displays a button once the animation is complete? Here is the CSS code for the typewriter effect: .welcome-msg { overflow: hidden; /* Ensures the content is not revea ...

How can I effectively separate the impact of Next.js onChange from my onClick function?

The buttons in my code are not functioning properly unless I remove the onChange. Adding () to my functions inside onClick causes them to run on every keystroke. How can I resolve this issue? In order to post my question, I need to include some dummy text. ...

Main navigation category as parent and secondary category as a child menu in WordPress

Hello there, I am looking to create a navigation menu with parent categories displayed horizontally and child categories as corresponding submenus. For example, The parent categories would be Apple, Orange, and Mango Under Apple, we would have apple1, ...

Loading data into a database using JSON format with JavaScript

I need to extract data from a JSON String stored in a JavaScript variable and use it to generate an SQL script. How can I loop through the JSON string to produce an output like the following? INSERT INTO table VALUES ('$var1', '$var2', ...

Node.js meets Blockly for a dynamic programming experience

Can anyone help me figure out how to run blockly on Node.js and have the code execute directly on the server without having to save the XML first and then run it in the background? I've attempted to use various npm modules but haven't found one t ...

Turning a string array into a basic array can be achieved through a few simple steps

While I am aware that this question has been posed multiple times, my scenario is slightly unique. Despite exhausting numerous methods, I have yet to discover a suitable workaround. $array = ["9","8","7","6","5"]; //result of javascript JSON.stringify() ...

What is the best way to retrieve information from a database using JSON with PHP, JQUERY, and

Trying to retrieve data from a MySQL database and pass it to a JavaScript file has been quite a challenge. Despite searching extensively online, the examples I found didn't work in my specific scenario. .html file <!DOCTYPE html PUBLIC '-//W ...

Managing the challenges of handling numerous AJAX post errors stemming from multiple form submissions

I am currently developing a PHP application that will be used to present multiple choice questions as well as text-based questions. The functionality I have implemented involves using Javascript code to submit user responses via ajax to the PHP server. He ...

Tips for leveraging _.union function from lodash to eliminate duplicate elements from several arrays in a TypeScript project

I attempted to use import _ from 'lodash-es' and _.union(user.users.map(user => user.city)). However, the result was not as expected, such as: ["city_id1", "city_id2", "city_id3", "city_id4"] What is th ...

Utilize Javascript to create a function that organizes numbers in ascending order

Is there a way to modify this code so that the flip clock digits appear in ascending order rather than randomly? $( '.count' ).flip( Math.floor( Math.random() * 10 ) ); setInterval(function(){ $( '.count' ).flip( Math.floor( Math.rand ...

How to Disable a Dynamically Generated <li> Element Using jQuery on Click Event

Script Query: Creating <li> Elements Dynamically echo '<div class="pagination"><ul>' . "\n"; // Previous Post Link. if ( get_previous_posts_link() ) { printf( '<li>%s</li>' . "\n", get_previ ...

Chrome is blocking my ajax cross-origin request, causing it to be cancelled

I have been working on a Google Chrome extension and encountering an issue with my ajax requests. Every time my extension sends a request, it ends up getting cancelled for some unknown reason. The following code snippet seems to be functioning properly: ...