How to Run NightwatchJS Browser Automation Tests on LambdaTest
In the fourth part of our Nightwatch.js tutorial series, 𝐓𝐚𝐩𝐚𝐬 𝐀𝐝𝐡𝐢𝐤𝐚𝐫𝐲 builds on everything we've learned so far, setting up Nightwatch, writing tests, and running them locally and takes it to the next level: executing browser automation on the LambdaTest cloud Selenium grid.
00:00 – Introduction: What You’ll Learn
02:14 – Getting Started with Nightwatch.js for Browser Automation
14:43 – Running Tests: Automation Results on LambdaTest
20:48 – Resources & Next Steps
Setting Up LambdaTest and Gathering Credentials
The tutorial begins with a walkthrough of setting up your LambdaTest environment for use with NightwatchJS. Users are guided to sign up or log in to LambdaTest, navigate to the Credentials section in the sidebar, and copy their username and access key. These are required for authenticating test runs on the cloud. The host emphasizes keeping these credentials secure and shows how to regenerate the access key from the Account Settings if needed. These credentials are later injected as environment variables rather than being hardcoded into the test files.
Installing Required Dependencies
Before running tests on the cloud, two essential Node.js dependencies are installed:
@lambdatest/node-rest-client - connects NightwatchJS to LambdaTest’s Selenium Grid.
cross-env — enables setting and using environment variables across different OS environments. These are installed using Yarn or npm with the --dev flag so that they’re only required during development. This setup ensures that the project remains lightweight while maintaining a clean environment for automation.
Configuring NightwatchJS for Cloud Execution
The existing configuration file nightwatch.conf.js is refactored into a new nightwatch.json file for cleaner and more modular configuration management. The .json file includes all core settings like source folder paths, test environment configurations, and global parameters. The key benefit is that the JSON format allows for easier maintenance and avoids mixing logic and configuration in one place. The .js configuration file then simply imports this JSON file, injects credentials from environment variables, and exports the merged configuration for NightwatchJS to use.
Defining Test Settings and Desired Capabilities
The test settings in the nightwatch.json file define which browsers and operating systems the tests should run on. The video demonstrates setting up desired capabilities for multiple browsers Chrome, Firefox, Safari, Edge, and Internet Explorer each containing information such as browser name, version, platform, and specific LambdaTest options. These configurations also include timeout durations, screenshot settings, and Selenium host details. Sensitive information like the LambdaTest username and access key are left blank here and filled in dynamically through environment variables during test execution.
Updating Scripts for Test Execution
In the package.json file, the tutorial creates two scripts for test execution:
Single run script – Executes tests in one browser (Chrome) using the default settings.
Parallel run script – Runs tests simultaneously across multiple browsers (Chrome, Safari, Edge). Both scripts use the cross-env package to pass environment variables (LT_USERNAME and LT_ACCESS_KEY) before initiating the tests. This method ensures a flexible and secure setup that can easily be integrated into CI/CD pipelines.
Running Tests and Monitoring Execution
With the setup complete, the video demonstrates executing the test runs using commands like yarn single or npm run parallel. Once triggered, NightwatchJS connects to LambdaTest’s Selenium Grid, and the tests begin running on cloud browsers. On the LambdaTest dashboard, users can monitor test progress in real-time, view each session’s details, and watch video recordings of the automation steps. Each session includes logs of actions like navigating to a URL, locating elements, performing searches, and verifying assertions.
Viewing Results and Debugging
After the tests complete, LambdaTest displays results including pass/fail status, assertions count, and detailed step-by-step logs. The host demonstrates accessing video replays of the test executions, which visually show actions such as navigating to the e-commerce site, performing a search, and verifying UI elements. These insights help users debug failed test runs quickly. LambdaTest also provides additional metadata such as browser version, OS, execution time, and session IDs, which are useful for documentation or further analysis.
Parallel Test Execution
The video then focuses on parallel testing, showing how multiple test sessions can run at the same time on different browsers and operating systems. This drastically reduces total execution time and increases test coverage. The host shows tests running concurrently on Chrome (Windows), Safari (macOS), and Edge (Windows). The LambdaTest dashboard displays all sessions with their respective statuses, and users can click on any session to analyze performance or identify inconsistencies between browsers.
Advantages of Cloud-Based Execution
Running NightwatchJS tests on LambdaTest’s cloud infrastructure allows developers to simulate multiple real-world user environments without maintaining a local device or browser farm. It supports scalability, faster feedback cycles through parallel execution, and easier integration with CI/CD systems. Additionally, by running tests in real browser instances, teams can ensure accurate and consistent results across different user platforms.
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.