Tips for verifying multiple elements in NightwatchJS

I am working with NightwatchJS and I have a requirement to verify if all elements with a specific class name are visible or not. My code snippet looks something like this:

module.exports = {
    //some tests

    'page changes to English': (browser) => {
        browser.click('label[for="switch-language"]').pause(1000);
        browser.elements('css selector', '.fr', results => {
            for (let i = 0; i < results; ++i) {
                browser.expect.element(results[i]).to.be.visible;
            }
        });
    }
};

However, upon running the test, I receive an output stating that No assertions ran.

Answer №1

Juhi Saxena's insightful response on the linked discussion helped me solve my issue. Below is the code snippet I used to address the problem, in case it may be helpful for others facing a similar challenge:

module.exports = {
    //some tests

    'page changes to English': browser => {
        browser.click('label[for="switch-language"]').pause(1000);
        browser.elements('css selector','.fr', areDisplayed.bind(null, browser, false));
        browser.elements('css selector','.en', areDisplayed.bind(null, browser, true));
    }
};

function areDisplayed(browser, expected, elements) {
    elements.value.forEach(element => {
        browser.elementIdDisplayed(element.ELEMENT, result => {
            browser.assert.equal(result.value, expected);
        });
    });
}

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

A step-by-step guide on storing JSON data into a variable using NodeJS

Just starting out with Node.js and running into an issue. I need to figure out how to extract and save data from a JSON object retrieved from the GitHub API. var http = require("http"); var express = require('express'); var app = express(); var ...

Exploring VueJS watchers: How to get started?

Struggling to grasp the concept of Watchers in VueJS, particularly when trying to implement them for tracking tab changes and resetting values. Even though I have set up a watch with parameters like `oldValue` and `newValue`, their usage remains unclear to ...

Querying Mongodb with current time parameters

I'm attempting to create a mongo query that retrieves all active listings based on the current date { $and: [ { start_time: { $lte: { $currentDate: { $type: "date" } } } } ...

What is the best way to ensure consistency in a value across various browsers using Javascript?

I am currently developing a feature on a webpage that displays the last update date of the page. The functionality I am aiming for is to select a date in the first input box, click the update button, and have the second box populate the Last Updated field ...

What is the process of parsing an array with $.parseJSON()?

In my test.php file, I receive an array from a MySQL query. $rows = Array ( [0] => Array ( [name] => nikhil ) [1] => Array ( [name] => akhil )) I then convert this array into a JSON format string and echo it out. $jsonstring = json_encode($r ...

Can you guide me on utilizing filter in an Apps Script array to retrieve solely the row containing a particular user ID within the cell?

I am using an Apps Script that retrieves data from four different columns in a spreadsheet. However, it currently fetches all the rows instead of just the row that matches the randomly generated 8-digit user ID. function doGet(req) { var doc = Spreadshe ...

When a page with parameters is reloaded, React fails to initiate

I'm encountering an issue with my application in development mode on localhost. When I try to reload the app on a route with parameters, for example: localhost:8080/item/2 React fails to initialize and only a blank page is displayed. However, if I ...

Toggling back and forth between two divs using a pair of buttons

I've been experimenting with switching between two divs using two buttons, but I can't seem to get it right. I've searched all over the internet, but nothing has worked for me so far. Can you please point out what I might be doing wrong? Als ...

Looking to optimize iframing for various screen dimensions

Apologies for the basic question. I am looking for a way to make my iframe responsive on all screen sizes, adjusting both height and width accordingly. Could anyone provide guidance? The current iframe code I have is as follows: <iframe name="ROL_ ...

The map function is mistakenly returning double the amount of the object it should be returning

My program is fetching data from an API, but when I try to map the array for interesting data, it downloads the same object multiple times. For the first search, it downloads the object twice and for subsequent searches, it downloads the object six times. ...

Is there a way to initiate a jquery function upon loading the page, while ensuring its continued user interaction?

On my webpage, there is a JavaScript function using jQuery that I want to automatically start when the page loads. At the same time, I want to ensure that users can still interact with this function. This particular function involves selecting a link tha ...

Infinite loop always occurs with Ui-router FromState being constantly reset

My page is experiencing continuous refreshing and calling $stateChangeStart after the first call to $state.go. I believe this issue may be related to the StateProvider configuration. Can anyone offer suggestions on what might be going wrong? Check out thi ...

pagination functionality incorporated into element ui tables

Issue with Element UI: when a checkbox is selected and the page is changed, the selected rows' checkboxes are removed. I need to retain the selection items while paging so that users can select items from multiple pages without losing the selections f ...

Live Update Google Sheet Data to JSON Without Reloading Web Page

This particular function is executing smoothly. My main concern lies in updating a DOM element without reloading the webpage, if any alterations are made to the data on a Google sheet I am utilizing a JSON file from Google sheets: https://spreadsheets.g ...

Utilizing JavaScript to retrieve a JSON file from a GitHub Pages server

I'm currently working on my website hosted on GitHub pages, which only supports static websites but allows the use of JavaScript. I have a JSON file on the GitHub server that my website runs from and I need to fetch and process it using JavaScript. He ...

Exploring how to compare time in hh:mm format using JavaScript

After switching to 24-hour format for my strings, I'm confused as to why the times are not comparing correctly. What am I doing incorrectly? function convertToTwentyFourHourTime(amPmString) { var d = new Date("1/1/2013 " + amPmString); ...

What is the reason behind one function triggering a re-render of a component while the other does not in Next.js?

I am currently working on a Next.js web application where one of the pages contains two functions that utilize useState() to add or remove emails from an array. const [invites, setInvites] = useState([]) // other code const lmao = () => { console.lo ...

What could be causing my jQuery event handler to not work properly when connected to numerous elements?

I have implemented jquery to dynamically add multiple "addTask" form elements to a "ul" on the webpage every time a link is clicked. $('span a').click(function(e){ e.preventDefault(); $('<li>\ <ul>\ ...

When Vue detects a change in declared parameters from an empty string, it automatically sends a

Within my application, I am making a request to the backend app and receiving a response with an ID such as { 'id': '12345'}. This ID is then saved as loadId within the data object: export default { name: 'SyncProducts', d ...

Using Angularjs to dynamically generate and submit tables

I can't seem to figure out this specific situation Data: $scope.MyItem = [ { "__v": 0, "myItemId": "55ed819caefe18e81ffbd2d2", "itemId": "56fec8abb192c870117ed393", "january": 1, "february": 1, ...