Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda