Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda