How can a command in a test be executed that is located within a specific "section" in Nightwatch?

I've been utilizing nightwatch for my test automation. Within my page object, I have a "section" containing various commands. However, when attempting to call these commands in the test script, I encountered an error stating "section is not a function". Please see my page object and test script below.

Page Object
sections:{
    Profile:{
        myprofile:'#myprofile',
        elements:{
            firstName:{
                selector:'//a [contains(text(),\'firstName\')]',
                locateStrategy:'xpath'
            }
        },
        commands:[{
            clickRedeem(){
                return this
                    .click('@myprofile')
            },
            clickMerchandise(){
                return this
                    .click('@firstName')
            }
        }]
    }
},

In the test script, the command is called as follows:

this.profileTest.section('@myprofile').clickProfile(); but it results 
in an error message:  this.profileTest.section is not a function  

I attempted the suggested solution provided. Details are outlined below.

redeemMenu:{
    selector:'#myprofile',
    elements:{
       merchandiseMenu:{
            selector:'//a [contains(text(),\'Merchandise\')]',
            locateStrategy:'xpath'
        },
    },
    commands:[{
        clickRedeem(){
            return this
                .waitForElementVisible('@redeemMenu')
                .click('@redeemMenu')
        },
        clickMerchandise(){
            return this
                .waitForElementVisible('@merchandiseMenu')
                .click('@merchandiseMenu')
        },


    }]
},



test

var profileSection = await this.profileTest.section.redeemMenu 
profileSection.clickRedeem()


Error: Element "redeemMenu" was not found in "redeemMenu". Available 
elements: merchandiseMenu

Answer №1

Here are a couple of mistakes to correct:

  1. The incorrect property was used, so you should change

    myprofile:'#myprofile'
    

    to

    selector: '#myprofile'
    
  2. An incorrect selector was utilized

    var profileSection = this.profileTest.section.redeemMenu
    
  3. For executing the command:

    profileSection.clickRedeem()
    

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

Is there a way to update a div element with an image without having to refresh

Currently working on a project for my studies where I am reading the x and y coordinates from a touch pad and drawing it in real time using PHP. I have created a draw page that takes these coordinates and displays them on an image, which is then shown on ...

In what way are these fonts being displayed through the utilization of a .js file?

Why are people opting for unique fonts on their browsers using .js files instead of graphics? For example, like typekit? ...

How to extract query string parameters using node.js

I'm currently working on fetching query string parameters from a URL using the node.js restify module. This is an example of the URL I am dealing with: Here is the relevant code snippet: server.use(restify.bodyParser()); server.listen(7779, functi ...

Setting a single value for several identifiers within a JSON object

I'm new to JSON and I'm curious if it's possible to have a name/value pair with multiple names. Essentially, I want to be able to search for either name and retrieve the same value without having to update the value in two different places. ...

What methods can be employed to stop tests from being included in rollup bundles?

I am currently in the process of creating a react component package and I would like to know how to prevent my tests folder from being included in the dist file that is generated by rollup. After running rollup -c, my directory structure looks like this: ...

Implementing an Angular theme in a project using Node.js, MySQL, and Express

I'm a beginner with node, angular, and express. I've managed to create a REST API using node+express+mysql, but now I need help integrating the blur-admin theme into my existing project. Despite getting the theme to run separately with gulp, I&ap ...

What is the technique for anchoring elements at the top of the page when scrolling?

There is a common design feature where the sidebar on the left starts at a lower position on the page, but as you scroll it moves up to the top and remains fixed in place instead of disappearing off the screen. This is a popular design trend that I have ...

I am experiencing issues with utilizing Array Filters in my Node.js backend when working with MongoDB

Utilizing it with Node.js in my backend. Encountered the following query: db.conversations.update( { convoId: convoId }, { $set: { "ids.$[elem].read" : true } }, { arrayFilters: [ { "elem.id": userId } ] }, (err, data) => { if(err) { ...

Experiencing difficulties in transmitting images/files to API through reactjs and Material UI upload component

Recently, I tackled the task of creating an image upload component by utilizing an upload component from Material UI. While I have experience with this process using a simple HTML file input in the past, I found myself feeling a bit perplexed this time aro ...

There is no assigned value in scope for the shorthand property. You must either declare one or provide an initializer

I'm just starting out with TypeScript. Encountering the error 'No value exists in scope for the shorthand property 'firstName'. Either declare one or provide an initializer.' while using Prisma with Next.js to create a new user in ...

Transforming color images into black and white using JavaScript

     I have implemented this code to convert colored images to grayscale. function applyGrayscaleEffect() {         var imageData = contextSrc.getImageData(0, 0, width, height);         var data = imageData.data;         var p1 = 0.99;   ...

PHP script failing to execute if/else statement during AJAX request

I am currently developing a website that heavily relies on Ajax, and I have chosen to use codeigniter for its construction. On the site, there is a form with the post method, and this form is submitted using an Ajax request that calls a function containi ...

Node.js tutorial: Building routes with regex and implementing redirects

Can anyone provide guidance on how to utilize route and redirect URLs with parameters in Node.js using Express? If the URL is xyz/?s=test, it should redirect to indexRouter. If the URL is xyz/, it should also redirect to indexRouter. I'm facing issu ...

Python Selenium encountered a problem with clicking on an element due to its position not being

Having an issue with scraping a website using selenium in Python. Every time I attempt to click on a dropdown button inside a div tag, I encounter the error message 'Element is not clickable at point (1341, 240)'. Can someone provide assistance? ...

System for Node.js execution replay logging

Running a straightforward script that performs various tasks can be tedious when trying to debug errors. The log messages scattered throughout the code clutter the file, requiring more and more console.log entries for detailed information. Instead of fill ...

Prevent selection of rows in the initial column of DataTables

I am working on a basic datable, the code can be found here JS: var dataSet = [ ["data/rennes/", "Rennes", "rennes.map"], ["data/nantes/", "Nantes", "nantes.map"], ["data/tours/", "Tours", "tours.map"], ["data/bordeaux/", "Bordeaux", ...

Steps for sending data to a modal window

Consider this scenario: I have a function that retrieves some ids, and I utilize the following code to delete the corresponding posts: onClick={() => { Delete(idvalue[i]) }} Nevertheless, I am in need of a modal confirmation before proceeding with the ...

Discover the method for two form fields to submit data to a distant page, located two pages away

Currently, I'm trying to figure out the best approach for having two fields submitted to a page that is located two pages away. To provide more context, let me elaborate on the situation. On the initial page, there will be two fields - workshop title ...

Is it possible to terminate a Windows process directly from a Protractor specification?

Dealing with the timing bug in Firefox's Plugin container can be quite a headache. I'm looking for a solution to kill it before closing the browser. Ideally, something like: Runtime().getRuntime().exec("taskkill /f /im WefFault.exe") But I ne ...

The TinyMCE editor's input box lost focus while on a popup dialog

Whenever I attempt to access the TinyMCE editor in a dialog box popup and click on "Insert link", the "Insert link" dialog box pops up but I can't type anything into the text field. I suspect that the issue may stem from having a dialog box open with ...