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

178
Views
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 answers
Answer question

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 Report
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!