Developing a continuous running test loop

Currently, I have a code that runs fine, but I am looking to modify it to run in a loop that counts the number of elements with the class="socal" and tests each link.

module.exports = {
    'Unitel Fitness - click' : function (browser) {
    browser
        .url('http://m.unitel.ao/fit/')
        .execute('scrollIntoView(alignToBottom)')
        .waitForElementVisible('.socal>span:nth-child(1) a', 6000)

        .moveToElement('.socal>span:nth-child(1) a', 3, 3)
        .pause(6000)
        .click(".socal>span:nth-child(1) a")
        .pause(6000)
        .keys(['\uE006'])

        .window_handles(function (result) {
            var handle = result.value[1];
            browser.switchWindow(handle);
            browser.pause(1000);
            //browser.assert.urlContains('facebook');
            browser.closeWindow();
        })
        .end();
    }
};

After upgrading the code, it is still not functioning as desired. The error message reads as follows: (I have attempted to provide more time for the process)

Number of links: 4 i val before execute: 1 i val before execute: 2 i val before execute: 3 i val before execute: 4 ? Timed out while waiting for element <.socal>span:nth-child("+ i +") a> to be present for 8000 milliseconds. - expected "visible" but got: not found

module.exports = {
                'Social links' : function (browser) {
        browser
            .url('http://m.unitel.ao/fit/')
            .execute(function(){
                        return document.querySelectorAll(".socal>span").length;
                    },

            function(links) {
                total_links = links.value;

                console.log("Number of links: " + total_links);

                for (var i = 1; i <= total_links; i++) {
                    console.log("i val before execute: " + i);

                    browser.execute('scrollIntoView(alignToBottom)');
                    //browser.waitForElementVisible('.socal>span:nth-child("+ i +") a', 8000);

                    //call back function
                    browser.waitForElementVisible('.socal>span:nth-child("+ i +") a', 5000, function() {

                    browser.moveToElement('.socal>span:nth-child("+ i +") a', 3, 3);
                    browser.pause(8000);
                    browser.click(".socal>span:nth-child("+ i +") a");
                    browser.pause(6000);
                    browser.keys(['\uE006']);

                    browser.window_handles(function (result) {
                        var handle = result.value[1];
                        browser.switchWindow(handle);
                        browser.pause(8000);
                        //browser.assert.urlContains('facebook');
                        browser.closeWindow();
                    })
                        });
                }
            })

               // .end();
            }
};

Answer №1

Instead of using a loop, consider obtaining a collection and utilizing the .length property. Not only is this approach more efficient, but it also improves performance.

client.getElements(classSelector, function(collection) {      
            return collection.length;
});

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

What method is most effective for duplicating objects in Angular 2?

Is it just me, or does Angular 1.x have methods on the global angular object like angular.copy and angular.shallowCopy that are missing in Angular 2? It seems like there is no equivalent version in Angular 2 documentation. If Angular 2 doesn't plan on ...

The JMeter JSR223 Sampler and WebDriver Sampler do not support the Javascript language

I am currently working on integrating Selenium Webdriver Sampler with JMeter. Although I have been following tutorials, I have encountered an issue where the script language dropdown in the sampler screen does not include an option for JavaScript, prevent ...

Access the global window variable from index.html within a Vue component

In my Vue project, I am incorporating an Stencil.js component in the following manner: index.html: <script type="module" src="https://xxxxxx.s3-eu-west-1.amazonaws.com/topbar.esm.js"> </script> <script> window.addEventLis ...

Move the items downwards to occupy any empty space vertically

Just a quick overview of the code I'm working with (I am using Material UI in React). This container is meant to hold chat messages exclusively. const ChatContainer = ({ chatMessages }) => { const classes = useStyles(); return ( <Paper ...

Is there a way to automatically change specific characters as a user types in an input field?

I'm facing an issue with replacing some characters dynamically. The goal is to ensure that user-input text is URL-friendly for constructing a URL: function slugify(string) { const a = "àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïí ...

The parameters 'event' and 'payload' do not match in type

Upon running the build command, I encountered a type error that states: Type error: Type '(event: React.FormEvent) => void' is not assignable to type 'FormSubmitHandler'. Types of parameters 'event' and 'payload&apos ...

Showing the child component as undefined in the view

Within my Angular application, I encountered an issue involving a parent component named DepotSelectionComponent and its child component SiteDetailsComponent. The problem arises when an event called moreDetails is emitted to the parent component, triggerin ...

Discover the most effective method for identifying duplicate items within an array

I'm currently working with angular4 and facing a challenge of displaying a list containing only unique values. Whenever I access an API, it returns an array from which I have to filter out repeated data. The API will be accessed periodically, and the ...

Create a new array of objects by extracting specific properties from an existing array of objects

Consider the input array below: const initialArray = [{name: 'john', age: 12, height: 178, likes: 'music'}, {name: 'mike', age: 22, height: 181, likes: 'sport'}, {name: &ap ...

Understanding how objects are created using the reduce method

I'm curious about how the reduce function can transform an array into an object as shown in this example, particularly with the line: p[c[0]] = c[1]; Is this an unconventional syntax for creating key-value pairs that I haven't encountered before ...

Alter the command from 'require' to an 'import'

Utilizing https://www.npmjs.com/package/json-bigint with native BigInt functionality has been a challenge. In the CommonJS environment, the following code is typically used: var JSONbigNative = require('json-bigint')({ useNativeBigInt: true }); ...

Tips for transferring canvas information from JavaScript to Django using Ajax

Currently, I'm developing a Django application that allows users to activate their webcams and capture photos. These images are stored in a canvas, and my goal is to send this image to Django views so that it can be saved on the server. To trigger th ...

Angular 2 Mixup: Using Leaflet and Google Maps with Incorrect Tile Order

I am encountering an issue while working on Leaflet and Google within Angular 2. The problem lies in the Tilemill tiles not rendering properly as they are displaying in a strange order. Here is a screenshot of the current state: https://i.stack.imgur.com/ ...

Using Laravel: Validate username existence with jQuery AJAX before form submission

After creating a registration form with numerous fields, I encountered an issue when submitting data and receiving validation errors. The user would have to refill empty inputs, causing unnecessary delays. To streamline the process, I am looking to impleme ...

Issue with jQuery AJAX call: When submitting an HTML form, control is not being returned to the calling

I am facing an issue with my HTML form where it is loaded correctly into the DOM through a jQuery ajax call. The problem arises when I submit the form data to a PHP module using another jQuery ajax call. Even though the network traffic shows that the form ...

Retrieve information from Angular service's HTTP response

Calling all Angular/Javascript aficionados! I need some help with a service that makes API calls to fetch data: app.service("GetDivision", ["$http", function($http){ this.division = function(divisionNumber){ $http.post("/api/division", {division:di ...

Retrieve the parent object from the policy field type

Imagine you have a query that retrieves a list of products like the one below. query ProductList() { products() { name price stockQuantity isAvailable @client # This field exists only locally } } In addition, you've set up a type ...

What is the process behind Stackoverflow's "Congratulations, you've earned a new badge" popup window?

Possible Duplicates: Custom notify box similar to StackOverflow Creating popup message like StackOverflow How does StackOverflow implement the "You earned a new badge" window? (the orange one that pops up at the top of the screen, I believe it&ap ...

Ways to steer clear of using eval for converting strings to decimal values

I currently have the fraction "1/7" and I am looking to convert it into a decimal. While I know I can achieve this using eval("1/7"), I prefer not to use eval as it is considered harmful. Are there any alternative methods to accomplish this? ...

Tips for showcasing a blurry image in NextJS while it's in the process of being fetched?

Is there a way to achieve a similar effect like the one showcased below? https://i.sstatic.net/9unuN.gif I've managed to do something similar with Gatsby, but I'm curious if it's achievable with NextJS as well. ...