$npx -y skills add LambdaTest/agent-skills --skill nightwatchjs-skillGenerates NightwatchJS E2E tests in JavaScript. Integrated test runner with Selenium WebDriver, built-in assertions, and page objects. Use when user mentions "Nightwatch", "NightwatchJS", "nightwatch.conf.js". Triggers on: "Nightwatch", "NightwatchJS", "nightwatch test".
| 1 | # NightwatchJS Automation Skill |
| 2 | |
| 3 | ## Step 1 — Execution Target |
| 4 | |
| 5 | ``` |
| 6 | ├─ "cloud", "TestMu", "LambdaTest" → Cloud: nightwatch.conf.js with LT env |
| 7 | ├─ "local" → Local: ChromeDriver/GeckoDriver |
| 8 | └─ Default → Local, mention cloud option |
| 9 | ``` |
| 10 | |
| 11 | ## Core Patterns |
| 12 | |
| 13 | ### Basic Test |
| 14 | |
| 15 | ```javascript |
| 16 | module.exports = { |
| 17 | 'Login with valid credentials': function(browser) { |
| 18 | browser |
| 19 | .url('http://localhost:3000/login') |
| 20 | .waitForElementVisible('#email', 5000) |
| 21 | .setValue('#email', 'user@test.com') |
| 22 | .setValue('#password', 'password123') |
| 23 | .click('button[type="submit"]') |
| 24 | .waitForElementVisible('.dashboard', 10000) |
| 25 | .assert.containsText('.welcome', 'Welcome') |
| 26 | .assert.urlContains('/dashboard') |
| 27 | .end(); |
| 28 | }, |
| 29 | |
| 30 | 'Login with invalid credentials shows error': function(browser) { |
| 31 | browser |
| 32 | .url('http://localhost:3000/login') |
| 33 | .waitForElementVisible('#email', 5000) |
| 34 | .setValue('#email', 'wrong@test.com') |
| 35 | .setValue('#password', 'wrong') |
| 36 | .click('button[type="submit"]') |
| 37 | .waitForElementVisible('.error-message', 5000) |
| 38 | .assert.containsText('.error-message', 'Invalid credentials') |
| 39 | .end(); |
| 40 | } |
| 41 | }; |
| 42 | ``` |
| 43 | |
| 44 | ### Page Objects |
| 45 | |
| 46 | ```javascript |
| 47 | // pages/loginPage.js |
| 48 | module.exports = { |
| 49 | url: '/login', |
| 50 | elements: { |
| 51 | emailInput: '#email', |
| 52 | passwordInput: '#password', |
| 53 | loginButton: 'button[type="submit"]', |
| 54 | errorMessage: '.error-message', |
| 55 | }, |
| 56 | commands: [{ |
| 57 | login(email, password) { |
| 58 | return this |
| 59 | .setValue('@emailInput', email) |
| 60 | .setValue('@passwordInput', password) |
| 61 | .click('@loginButton'); |
| 62 | } |
| 63 | }] |
| 64 | }; |
| 65 | |
| 66 | // tests/loginTest.js |
| 67 | module.exports = { |
| 68 | 'Login test': function(browser) { |
| 69 | const login = browser.page.loginPage(); |
| 70 | login.navigate() |
| 71 | .login('user@test.com', 'password123'); |
| 72 | browser.assert.urlContains('/dashboard'); |
| 73 | } |
| 74 | }; |
| 75 | ``` |
| 76 | |
| 77 | ### Assertions |
| 78 | |
| 79 | ```javascript |
| 80 | browser.assert.visible(selector); |
| 81 | browser.assert.not.visible(selector); |
| 82 | browser.assert.containsText(selector, 'text'); |
| 83 | browser.assert.urlContains('/path'); |
| 84 | browser.assert.titleContains('Page Title'); |
| 85 | browser.assert.elementPresent(selector); |
| 86 | browser.assert.cssClassPresent(selector, 'active'); |
| 87 | browser.assert.value('#input', 'expected'); |
| 88 | browser.assert.attributeEquals(selector, 'href', '/link'); |
| 89 | browser.assert.elementsCount('li', 5); |
| 90 | ``` |
| 91 | |
| 92 | ### TestMu AI Cloud Config |
| 93 | |
| 94 | For full capabilities and shared reference, see [reference/cloud-integration.md](reference/cloud-integration.md). |
| 95 | |
| 96 | ```javascript |
| 97 | // nightwatch.conf.js |
| 98 | module.exports = { |
| 99 | test_settings: { |
| 100 | default: { |
| 101 | launch_url: 'http://localhost:3000', |
| 102 | desiredCapabilities: { browserName: 'chrome' } |
| 103 | }, |
| 104 | lambdatest: { |
| 105 | selenium: { |
| 106 | host: 'hub.lambdatest.com', |
| 107 | port: 80 |
| 108 | }, |
| 109 | desiredCapabilities: { |
| 110 | browserName: 'chrome', |
| 111 | browserVersion: 'latest', |
| 112 | 'LT:Options': { |
| 113 | platform: 'Windows 11', |
| 114 | build: 'Nightwatch Build', |
| 115 | name: 'Login Tests', |
| 116 | user: process.env.LT_USERNAME, |
| 117 | accessKey: process.env.LT_ACCESS_KEY, |
| 118 | video: true, console: true, network: true |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | }, |
| 123 | page_objects_path: ['pages/'], |
| 124 | }; |
| 125 | ``` |
| 126 | |
| 127 | ## Setup: `npm install nightwatch --save-dev` |
| 128 | ## Run: `npx nightwatch` or `npx nightwatch --env lambdatest` |
| 129 | |
| 130 | ## Deep Patterns |
| 131 | |
| 132 | For advanced patterns, debugging guides, CI/CD integration, and best practices, |
| 133 | see `reference/playbook.md`. |