├── .gitignore
├── .gitpod.yml
├── Jenkinsfile
├── README.md
├── nightwatch.conf.js
├── nightwatch.json
├── package.json
├── reports
├── CHROME_71.0.3578.30_Windows NT_googleTest.xml
├── MICROSOFTEDGE_42.17134.1.0_10_googleTest.xml
└── SAFARI_13605.3.8_macOS_googleTest.xml
└── tests
└── googleTest.js
/.gitignore:
--------------------------------------------------------------------------------
1 | //exclude below files/dir
2 |
3 | node_modules/*
4 | reports/*
5 | lambda_api.log
6 | package-lock.json
--------------------------------------------------------------------------------
/.gitpod.yml:
--------------------------------------------------------------------------------
1 | # List the start up tasks. You can start them in parallel in multiple terminals. See https://www.gitpod.io/docs/config-start-tasks/
2 | tasks:
3 | - init: npm install # runs during prebuild
4 | command: ./node_modules/.bin/nightwatch -e chrome tests
5 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env groovy
2 |
3 | node {
4 | withEnv(["LT_USERNAME=Your LambdaTest UserName",
5 | "LT_ACCESS_KEY=Your LambdaTest Access Key",
6 | "LT_TUNNEL=true"]){
7 |
8 | echo env.LT_USERNAME
9 | echo env.LT_ACCESS_KEY
10 |
11 | stage('setup') {
12 |
13 | // Get some code from a GitHub repository
14 | try{
15 | git 'https://github.com/LambdaTest/nightwatch-selenium-sample.git'
16 |
17 | //Download Tunnel Binary
18 | sh "wget http://downloads.lambdatest.com/tunnel/linux/64bit/LT_Linux.zip"
19 |
20 | //Required if unzip is not installed
21 | sh 'sudo apt-get install --no-act unzip'
22 | sh 'unzip -o LT_Linux.zip'
23 |
24 | //Starting Tunnel Process
25 | sh "./LT -user ${env.LT_USERNAME} -key ${env.LT_ACCESS_KEY} &"
26 | sh "rm -rf LT_Linux.zip"
27 | }
28 | catch (err){
29 | echo err
30 | }
31 |
32 | }
33 | stage('build') {
34 | // Installing Dependencies
35 | sh 'npm install'
36 | }
37 |
38 | stage('test') {
39 | try{
40 | sh './node_modules/.bin/nightwatch -e chrome,edge tests'
41 | }
42 | catch (err){
43 | echo err
44 | }
45 | }
46 | stage('end') {
47 | echo "Success"
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Run Selenium Tests With Nightwatch On LambdaTest
2 |
3 |
4 |
5 |
6 |
7 |
8 | Blog
9 | ⋅
10 | Docs
11 | ⋅
12 | Learning Hub
13 | ⋅
14 | Newsletter
15 | ⋅
16 | Certifications
17 | ⋅
18 | YouTube
19 |
20 |
21 |
22 |
23 |
24 | *Learn how to use Nightwatch framework to configure and run your JavaScript automation testing scripts on the [LambdaTest Selenium cloud platform](https://www.lambdatest.com/selenium-automation/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample).*
25 |
26 | [
](https://accounts.lambdatest.com/register)
27 |
28 | ## Table of Contents
29 |
30 | * [Pre-requisites](#pre-requisites)
31 | * [Run Your First Test](#run-your-first-test)
32 | * [Executing the Test](#executing-the-test)
33 | * [Running Your Parallel Tests Using Nightwatch Framework](#running-your-parallel-tests-using-nightwatch-framework)
34 | * [Testing Locally Hosted or Privately Hosted Projects](#testing-locally-hosted-or-privately-hosted-projects)
35 |
36 | ## Pre-requisites
37 |
38 | Before getting started with Automated Scripts using Selenium with Nightwatch framework on LambdaTest Automation, you need to:
39 |
40 | * Download and install **NodeJS**. You should be having **NodeJS v6** or newer. Click [here](https://nodejs.org/en/) to download.
41 | * Make sure you are using the latest version of **JavaScript**.
42 | * Install **npm** from the official website by clicking [here](https://www.npmjs.com/).
43 | * Download [Selenium JavaScript bindings](https://www.selenium.dev/downloads/) from the official website. Latest versions of **Selenium Client** and **WebDriver** are ideal for running your JavaScript automation testing script on LambdaTest’s Selenium Grid.
44 |
45 | ### Installing Selenium Dependencies and tutorial repo
46 |
47 | Clone the LambdaTest’s [nightwatch-selenium-sample repository](https://github.com/LambdaTest/nightwatch-selenium-sample) and navigate to the code directory as shown below:
48 | ```bash
49 | git clone https://github.com/LambdaTest/nightwatch-selenium-sample
50 | cd nightwatch-selenium-sample
51 | ```
52 | Install the required project dependencies using the command below:
53 | ```bash
54 | npm i
55 | ```
56 |
57 | ### Setting up Your Authentication
58 | Make sure you have your LambdaTest credentials with you to run test automation scripts on LambdaTest Selenium Grid. You can obtain these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/build/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample) or through [LambdaTest Profile](https://accounts.lambdatest.com/login/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample).
59 |
60 | Set LambdaTest `Username` and `Access Key` in environment variables.
61 | * For **Linux/macOS**:
62 | ```bash
63 | export LT_USERNAME="YOUR_USERNAME" export LT_ACCESS_KEY="YOUR ACCESS KEY"
64 | ```
65 | * For **Windows**:
66 | ```bash
67 | $env:LT_USERNAME='YOUR_USERNAME'
68 | $env:LT_ACCESS_KEY='YOUR ACCESS KEY'
69 | ```
70 |
71 | ## Run Your First Test
72 |
73 | ### Sample Test with NightwatchJS
74 |
75 | **Test Scenario:** This is a simple Nightwatch automation script that tests a sample to-do list app. The code marks two list items as done, adds a list item and then finally gives the total number of pending items as output. Check out [googleTest.js](https://github.com/LambdaTest/nightwatch-selenium-sample/blob/master/tests/googleTest.js) to view the sample test script for running your first test.
76 |
77 | ### Configuration of Your Test Capabilities
78 |
79 | Below is the `nightwatch.conf.js` file where we will be declaring the desired capabilities. Since we are using remote webdriver, we have to define which browser environment we want to run the test. We do that by passing browser environment details to LambdaTest Selenium Grid via desired capabilities class.
80 |
81 | ```js
82 | //nightwatch.conf.js
83 |
84 | module.exports = (function(settings) {
85 | console.log(settings["test_settings"]["default"]["username"])
86 | if (process.env.LT_USERNAME) {
87 | settings["test_settings"]["default"]["username"] = process.env.LT_USERNAME;
88 | }
89 | if (process.env.LT_ACCESS_KEY) {
90 | settings["test_settings"]["default"]["access_key"] = process.env.LT_ACCESS_KEY;
91 | }
92 | if (process.env.SELENIUM_HOST) {
93 | settings.selenium.host = process.env.SELENIUM_HOST;
94 | }
95 | if (process.env.SELENIUM_PORT) {
96 | settings.selenium.host = process.env.SELENIUM_PORT;
97 | }
98 | return settings;
99 | })(require('./nightwatch.json'));
100 | ```
101 | > You can generate capabilities for your test requirements with the help of our inbuilt **[Capabilities Generator tool](https://www.lambdatest.com/capabilities-generator/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)**.
102 |
103 | ## Executing the Test
104 |
105 | The tests can be executed in the terminal using the following command
106 | ```bash
107 | npm run single
108 | ```
109 | Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on [LambdaTest automation dashboard](https://automation.lambdatest.com/build/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample). LambdaTest Automation Dashboard will help you view all your text logs, screenshots and video recording for your entire automation tests.
110 |
111 | ## Running Your Parallel Tests Using Nightwatch Framework
112 |
113 | ### Executing Parallel Tests with Nightwatch
114 |
115 | To run parallel tests using **Nightwatch**, we would have to execute the below command in the terminal:
116 | ```bash
117 | npm run parallel
118 | ```
119 | Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on [LambdaTest automation dashboard](https://automation.lambdatest.com/build/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample).
120 |
121 | ## Testing Locally Hosted or Privately Hosted Projects
122 |
123 | You can test your locally hosted or privately hosted projects with [LambdaTest Selenium grid cloud](https://www.lambdatest.com/selenium-automation/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample) using LambdaTest Tunnel app. All you would have to do is set up an SSH tunnel using LambdaTest Tunnel app and pass toggle `tunnel = True` via desired capabilities. LambdaTest Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are made live.
124 |
125 | >Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information.
126 |
127 | Here’s how you can establish LambdaTest Tunnel.
128 |
129 | >Download the binary file of:
130 | * [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip)
131 | * [LambdaTest Tunnel for Mac](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip)
132 | * [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip)
133 |
134 | Open command prompt and navigate to the binary folder.
135 |
136 | Run the following command:
137 | ```bash
138 | LT -user {user’s login email} -key {user’s access key}
139 | ```
140 | So if your user name is lambdatest@example.com and key is 123456, the command would be:
141 | ```bash
142 | LT -user lambdatest@example.com -key 123456
143 | ```
144 | Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below :
145 |
146 | **Tunnel Capability**
147 | ```js
148 | const capabilities = {
149 | tunnel: true,
150 | }
151 | ```
152 |
153 | ## Additional Links
154 |
155 | * [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/selenium-automation-capabilities/)
156 | * [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/)
157 | * [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/)
158 |
159 | ## Tutorials 📙
160 |
161 | Check out our latest tutorials on JavaScript automation testing 👇
162 |
163 | * [How To Perform Automation Testing With Cucumber And Nightwatch JS?](https://www.lambdatest.com/blog/automation-testing-with-cucumber-and-nightwatchjs/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
164 | * [E2E Headless Browser Testing Using Nightwatch JS](https://www.lambdatest.com/blog/headless-browser-testing-using-nightwatchjs/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
165 | * [Nightwatch Vs Protractor: Which Testing Framework Is Right For You?](https://www.lambdatest.com/blog/nightwatch-vs-protractor/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
166 | * [Running Your First Test With NightWatchJS](https://www.lambdatest.com/blog/nightwatch-js-tutorial-selenium-webdriver/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
167 | * [Introduction To Nightwatch.js For Selenium Testing](https://www.lambdatest.com/blog/introduction-to-nightwatch-js-for-selenium-testing/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
168 | * [Nightwatch.js Tutorial For Test Automation Beginners – With Examples](https://www.lambdatest.com/blog/nightwatch-js-tutorial-for-test-automation-beginners/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
169 |
170 | ## Documentation & Resources :books:
171 |
172 | Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing.
173 |
174 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
175 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
176 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
177 |
178 | ## LambdaTest Community :busts_in_silhouette:
179 |
180 | The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎
181 |
182 | ## What's New At LambdaTest ❓
183 |
184 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/)
185 |
186 | ## About LambdaTest
187 |
188 | [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs.
189 |
190 | ### Features
191 |
192 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments.
193 | * Real-time cross browser testing on 3000+ environments.
194 | * Test on Real device cloud
195 | * Blazing fast test automation with HyperExecute
196 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale.
197 | * Smart Visual Regression Testing on cloud
198 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more.
199 | * Automated Screenshot testing across multiple browsers in a single click.
200 | * Local testing of web and mobile apps.
201 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems.
202 | * Geolocation testing of web and mobile apps across 53+ countries.
203 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports
204 |
205 | [
](https://accounts.lambdatest.com/register)
206 |
207 | ## We are here to help you :headphones:
208 |
209 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
210 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=nightwatch-selenium-sample)
211 |
--------------------------------------------------------------------------------
/nightwatch.conf.js:
--------------------------------------------------------------------------------
1 | module.exports = (function(settings) {
2 | console.log(settings["test_settings"]["default"]["username"]);
3 |
4 | if (process.env.LT_USERNAME) {
5 | settings["test_settings"]["default"]["username"] = process.env.LT_USERNAME;
6 | }
7 |
8 | if (process.env.LT_ACCESS_KEY) {
9 | settings["test_settings"]["default"]["access_key"] = process.env.LT_ACCESS_KEY;
10 | }
11 |
12 | if (process.env.SELENIUM_HOST) {
13 | settings.selenium.host = process.env.SELENIUM_HOST;
14 | }
15 | if (process.env.SELENIUM_PORT) {
16 | settings.selenium.host = process.env.SELENIUM_PORT;
17 | }
18 | console.log(settings);
19 | return settings;
20 | })(require('./nightwatch.json'));
21 |
--------------------------------------------------------------------------------
/nightwatch.json:
--------------------------------------------------------------------------------
1 | {
2 | "src_folders": [
3 | "tests"
4 | ],
5 | "output_folder": "reports",
6 | "page_objects_path": "",
7 | "globals_path": "",
8 | "selenium": {
9 | "start_process": false,
10 | "server_path": "",
11 | "log_path": "",
12 | "host": "hub.lambdatest.com",
13 | "port": 80,
14 | "cli_args": {
15 | "webdriver.chrome.driver": "",
16 | "webdriver.ie.driver": "",
17 | "webdriver.firefox.profile": ""
18 | }
19 | },
20 | "test_workers": {
21 | "enabled": true,
22 | "workers": "auto"
23 | },
24 | "test_settings": {
25 | "default": {
26 | "request_timeout_options": {
27 | "timeout": 1000000
28 | },
29 | "launch_url": "https://lambdatest.com",
30 | "selenium_port": 80,
31 | "selenium_host": "hub.lambdatest.com",
32 | "silent": false,
33 | "screenshots": {
34 | "enabled": true,
35 | "path": ""
36 | },
37 | "username": "",
38 | "access_key": "",
39 | "skip_testcases_on_fail": false,
40 | "desiredCapabilities": {
41 | "LT:Options": {
42 | "build": "Nightwatch-Selenium-Sample",
43 | "visual": false,
44 | "console": false,
45 | "network": false
46 | }
47 | }
48 | },
49 | "chrome": {
50 | "desiredCapabilities": {
51 | "LT:Options": {
52 | "browserName": "Chrome",
53 | "browserVersion": "latest",
54 | "project": "Untitled",
55 | "w3c": true,
56 | "plugin": "node_js-nightwatch_js"
57 | }
58 | }
59 | },
60 | "safari": {
61 | "desiredCapabilities": {
62 | "LT:Options": {
63 | "browserName": "Safari",
64 | "browserVersion": "latest",
65 | "project": "Untitled",
66 | "w3c": true,
67 | "plugin": "node_js-nightwatch_js"
68 | }
69 | }
70 | },
71 | "firefox": {
72 | "desiredCapabilities": {
73 | "LT:Options": {
74 | "browserName": "Firefox",
75 | "browserVersion": "latest",
76 | "project": "Untitled",
77 | "w3c": true,
78 | "plugin": "node_js-nightwatch_js"
79 | }
80 | }
81 | },
82 | "edge": {
83 | "desiredCapabilities": {
84 | "LT:Options": {
85 | "browserName": "MicrosoftEdge",
86 | "browserVersion": "latest",
87 | "project": "Untitled",
88 | "w3c": true,
89 | "plugin": "node_js-nightwatch_js"
90 | }
91 | }
92 | },
93 | "ie": {
94 | "desiredCapabilities": {
95 | "LT:Options": {
96 | "browserName": "Internet Explorer",
97 | "browserVersion": "latest",
98 | "project": "Untitled",
99 | "w3c": true,
100 | "plugin": "node_js-nightwatch_js"
101 | }
102 | }
103 | }
104 | }
105 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nightwatch-js",
3 | "version": "0.0.1",
4 | "description": "NightWatch examples for LambdaTest",
5 | "main": "",
6 | "scripts": {
7 | "single": "cross-env CONFIG_FILE=single ./node_modules/.bin/nightwatch -e chrome tests",
8 | "parallel": "cross-env CONFIG_FILE=parallel ./node_modules/.bin/nightwatch -e chrome,edge,safari tests"
9 | },
10 | "dependencies": {
11 | "@lambdatest/node-rest-client": "^1.0.5",
12 | "nightwatch": "^2.6.15"
13 | },
14 | "devDependencies": {
15 | "cross-env": "^7.0.3"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/reports/CHROME_71.0.3578.30_Windows NT_googleTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/reports/MICROSOFTEDGE_42.17134.1.0_10_googleTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/reports/SAFARI_13605.3.8_macOS_googleTest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/tests/googleTest.js:
--------------------------------------------------------------------------------
1 | var https = require("https");
2 | var lambdaRestClient = require("@lambdatest/node-rest-client");
3 | var lambdaCredentials = {
4 | username: process.env.LT_USERNAME,
5 | accessKey: process.env.LT_ACCESS_KEY
6 | };
7 | var lambdaAutomationClient = lambdaRestClient.AutomationClient(
8 | lambdaCredentials
9 | );
10 | module.exports = {
11 | "@tags": ["test"],
12 | TodoTest: function(client) {
13 | client
14 | .url("https://lambdatest.github.io/sample-todo-app/")
15 | .waitForElementPresent("body", 1000)
16 | .setValue("input[id=sampletodotext]", "Complete LambdaTest tutorial.")
17 | .click("input[id=addbutton]")
18 | .pause(1000)
19 | .end();
20 |
21 | },
22 | after: function(browser) {
23 | console.log("Closing down...");
24 | },
25 | afterEach: function(client, done) {
26 | if (
27 | process.env.LT_USERNAME &&
28 | process.env.LT_ACCESS_KEY &&
29 | client.capabilities &&
30 | client.capabilities["webdriver.remote.sessionid"]
31 | ) {
32 |
33 | lambdaAutomationClient.updateSessionById(
34 | client.capabilities["webdriver.remote.sessionid"],
35 | { status_ind: client.currentTest.results.failed ? "failed" : "passed" },
36 | function(error, session) {
37 | console.log(error)
38 | if (!error) {
39 | client.pause(1000)
40 | done();
41 | }
42 | }
43 | );
44 | } else {
45 | console.log("Test Run Successfully!");
46 | client.pause(1000)
47 | done();
48 | }
49 | }
50 | };
51 |
--------------------------------------------------------------------------------