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

186
Visualizações
Custom commands or utility classes/functions?

I'm working with a team that has a project in Nightwatch.js. They are defining commands for almost everything:

  • Datetime functions as commands (return current day, array of days in a period, etc.)
  • SQL queries to get data as commands

To me, some of these fit better to utility classes, but they prefer to have them as commands, so they can access them via browser.Command.

What's the correct approach or recommendation? All in commands looks odd to me, but also the codes look more clean, as you don't need to do imports.

Thanks,

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This question will probably get closed for being opinion based, but anyway.

I would agree that not all utilities should be commands. I would generally see the scope of command to be more to do with acting on things in the browser as the user would, or a way to group user actions, e.g. in a typical system I would see commands like -

  • login(), which would group the clicking into text fields and entering the username password and eventually clicking the login button.
  • addUser(), which would maybe be a small, but repetitive group of commands to add a user to an admin panel for example.
  • dragTo(x), which would maybe handle some drag and drop functionality.

etc.

I wouldn't see date utils etc as commands, but as you say, just utility functions, that are more about the underlying implementation of the test, and not how the user would interact with the system.

Although not Nightwatch, maybe take some advice from the Best Practices of Custom Commands from Cypress - https://docs.cypress.io/api/cypress-api/custom-commands#Best-Practices

about 4 years ago · Juan Pablo Isaza Relatório
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