Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Nightwatch: Unable to get the updated array value in the assertion

Using Nightwatch with JS. Below is the Page object which I am using. Under commands, I initialized an empty array, "deletedPlans". Then further in the code, I'm pushing values to it. In the end, in the assertion, I am trying to print the updated array value in the message, but it prints nothing, taking the array value as empty. Whereas, inside the function where I've commented, it prints the array value perfectly. What wrong I am doing?

module.exports = {
url:'/xyz',

elements: {     
deleteAction:{
    selector: '//span[text()="Delete"]',
    locateStrategy: 'xpath'
  },
PlanTitleVerify:{
    //some selector
  }
},

commands:[{

deletePlan: async function (browser){
 var myPage = this
 var deletedPlans =[]
        
    browser 
     .elements('xpath', '//div[@class="ant-card-head-title"]//span', function (elements) {
  
        elements.value.forEach(element => {
          let key = Object.keys(element)[0];
          let ElementIDvalue = element[key];
  
          browser.elementIdText(ElementIDvalue, function (result) {    
            let planName = result.value
            deletedPlans.push(planName) //Adding value to array
            
            console.log("Plan to be deleted:" + deletedPlans) //Here value gets printed      
                
           myPage
            .pause(2000)
            .click('@deleteAction')
           })         
        })           
     })
      //Here 'deletedPlans' value is printed as blank. 
myPage.assert.not.elementPresent('@PlanTitleVerify', 'Deleted plans are:' + deletedPlans)
    },
  }]
};

Output:

Plan to be deleted: ABCD(let's say)

Deleted plans are:

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!