How To Install & Set Up Nightwatch.js For E2E Testing | Nightwatch.js Tutorial
In the second session of our Nightwatch.js tutorial series, πππ©ππ¬ πππ‘π’π€ππ«π² demonstrates how to install and set up Nightwatch.js to test across multiple browsers.
You'll learn how to configure multiple browsers for cross-browser testing, securely manage globals and environment variables to avoid exposing sensitive data, and understand the differences between single and parallel runs.
Additionally, Tapas explains the significance of test workers and how they can boost your test execution efficiency.
π― What You'll Learn:
β Nightwatch.js installation and setup
β Configuration file deep dive (nightwatch.conf.js)
β Multi-browser testing setup (Chrome, Safari, Firefox, Edge)
β Environment variables & secrets management
β Global variables configuration
β Single vs Parallel test execution
β Test workers' configuration
β Page Object Model setup
By the end of this session, youβll be able to set up Nightwatch.js effectively, ensuring a smooth testing experience across different environments.
00:00 Introduction
01:34 Prerequisites
03:15 Installing Nightwatch
08:00 Understanding Nightwatch Scaffolding
10:50 Nightwatch Configuration
13:59 Running a Test
15:22 Running Tests on Multiple Browsers
17:04 Single vs Parallel Test Execution
18:54 Using Globals
21:30 Environment Variables
24:22 Conclusion & Next Steps
In this second episode of the NightwatchJS series, the instructor guides viewers through the complete setup and configuration of NightwatchJS for a project. The session begins with installing NightwatchJS using NodeJS and npm, highlighting prerequisites like NodeJS, a code editor (e.g., VS Code), a web browser, and optionally a terminal.
The installation process is explained step by step, covering both new and existing projects, and guiding users through initial configuration options such as project purpose, language (JavaScript or TypeScript), and target browsers. The instructor emphasizes best practices, including separating test files from source code to maintain modularity and simplify CI/CD integration.
Once installed, the video dives into the folder structure created by NightwatchJS, including folders for custom assertions, custom commands, examples, page objects (POM), templates, and the test folder. Each folderβs purpose is explained: custom assertions for project-specific conditions, custom commands for reusable actions, examples for reference, POM for maintaining clean, modular test code, and templates for creating standard test structures.
The importance of the nightwatch.conf.js configuration file is highlighted, detailing paths for tests, page objects, custom commands, and assertions, as well as global variables, plugin support, and test worker settings for single versus parallel runs. The instructor demonstrates configuring browser capabilities, starting with Chrome and Edge, and explains how to add Safari and Firefox.
Key Mac-specific instructions are provided for running tests on Safari, including enabling remote automation in developer settings. The video also covers running tests in parallel using test workers, allowing simultaneous execution across multiple browsers.
The session introduces globals for sharing values across test suites, showing how to define them directly in the configuration file or through a separate global file. Examples include a global team variable accessible via browser.globals.
The tutorial then covers environment variables for storing sensitive information, such as LambdaTest username and access keys, demonstrating how to access these variables both in configuration files and within test scripts using process.env.
Throughout the session, the instructor runs multiple example tests to illustrate configuration changes, browser selection, parallel execution, and access to globals and environment variables.
Nightwatch.js Tutorial For Test AutomationβComplete Guide With Examples
Tapas Adhikary
Tapas is a passionate content creator with 18+ years of experience in Software Development and User Interface Engineering. Bringing forth expertise in software systems design, development, and delivery. Equipped with a diverse and promising skill set. Proficient in various platforms and languages. Able to effectively self-manage during independent projects and collaborate as part of a productive team.