{"id":20420227,"url":"https://github.com/ghoshasish99/nightwatchjs","last_synced_at":"2026-05-10T17:44:50.714Z","repository":{"id":118153301,"uuid":"325764598","full_name":"ghoshasish99/NightwatchJS","owner":"ghoshasish99","description":"Automated Testing with NightwatchJS","archived":false,"fork":false,"pushed_at":"2021-02-07T02:12:06.000Z","size":52,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-15T14:35:13.119Z","etag":null,"topics":["javascript","nightwatchjs","selenium","testautomation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghoshasish99.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-31T09:29:08.000Z","updated_at":"2021-07-02T07:39:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"c31ac4a2-ca0b-41d9-a4ff-8e3271ec7160","html_url":"https://github.com/ghoshasish99/NightwatchJS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghoshasish99%2FNightwatchJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghoshasish99%2FNightwatchJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghoshasish99%2FNightwatchJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghoshasish99%2FNightwatchJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghoshasish99","download_url":"https://codeload.github.com/ghoshasish99/NightwatchJS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241963348,"owners_count":20049816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","nightwatchjs","selenium","testautomation"],"created_at":"2024-11-15T06:42:06.170Z","updated_at":"2025-12-01T17:03:04.849Z","avatar_url":"https://github.com/ghoshasish99.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NightwatchJS with Mocha\n\n[![Build Status](https://dev.azure.com/AutomationsTools/Execution/_apis/build/status/ghoshasish99.NightwatchJS?branchName=main)](https://dev.azure.com/AutomationsTools/Execution/_build/latest?definitionId=4\u0026branchName=main)\n\n### Nightwatch.js is a JavaScript based test automation framework that uses Selenium JavaScript bindings.\n\n### Getting started\n* To install nightwatch.js, run :   `npm install nightwatch --save-dev`\n* To install chromewebdriver, run : `npm install chromedriver --save-dev`\n* To install mocha, run :   `npm install mocha --save-dev`\n\nOr else, we can install all of these together using : `npm install nightwatch chromedriver mocha chai --save-dev`\n\nNightwatchJS generates a config file, `nightwatch.conf.js` which contains all the test configurations.\nMake the following changes in the `nightwatch.conf.js` file before executing your tests:\n```javascript\ntest_settings: {\n    default: {\n      disable_error_log: false,\n      launch_url: '',\n\n      screenshots: {\n        enabled: false,\n        path: 'screens',\n        on_failure: true\n      },\n\n      desiredCapabilities: {\n        browserName : 'chrome',\n        //To run in headless mode\n        chromeOptions : {\n          \"args\" : [\"headless\"]\n       }\n      },\n\n      webdriver: {\n        start_process: true,\n        server_path : require('chromedriver').path\n      }\n    }\n```\n### Nightwatch has native support for using the  BDD interface for writing tests. No further configuration is necessary.\nThe BDD interface lets you write tests in `describe` and `test` blocks. An example below :\n```javascript\ndescribe('Login and Registration', function() {    \n    test('login should fail with invalid credentials', function (browser) {\n        browser.url('http://awswrkshpalb-1570520390.us-west-2.elb.amazonaws.com:3000/cts-shop/login')\n          .setValue('#email',accountData.negativeLogin.username)\n          .setValue('#password',accountData.negativeLogin.password)\n          .click('form.login \u003e .MuiButtonBase-root \u003e .MuiButton-label')\n    });\n  after(browser=\u003ebrowser.end());\n});      \n```\nIt is important to note that the `browser` is available globally for usage.\n\n# Selectors/LocateStrategy\nNightwatch uses `css` as the default locator strategy.\nA shorthand like below can be easily used to identify an object\n```javascript\nmodule.exports = {\n    elements: {\n        firstname :'#dafirstname',\n        lastname :'#dalastname'\n  }\n};\n```\nOnce can also choose `xpath` as a selector. An example is shown below :\n```javascript\nmodule.exports = {\n    elements: {\n        btnConfirm :{\n          selector:  '//*[text()=\"Confirm\"]',\n          locateStrategy: 'xpath'\n        }\n  }\n};\n```\n# Page Object Model\nThe location of the page object files can be specified in the `page_objects_path` tag of the `nightwatch.conf.js` file.\nIn the page object file, one can export `elements` and custom `commands` specific to that page, like so :\n```javascript\nvar loginCommands = {\n    createAccount : function(fname,lname,email,password){\n        return this.click('@btncreateAccount1')\n            .setValue('@firstname',fname)\n            .setValue('@lastname',lname)\n            .setValue('@registeremail',email)\n            .setValue('@password',password)\n            .setValue('@confirmpassword',password)\n            .click('@btncreateAccount2')\n            .expect.element('@productSearch').to.be.visible;\n    }\n}\n\nmodule.exports = {\n    commands : [loginCommands],\n    url: 'http://awswrkshpalb-1570520390.us-west-2.elb.amazonaws.com:3000/cts-shop/login',\n    elements: {\n        email :'#email',\n        password :'#password',\n        btnSubmit :'form.login \u003e .MuiButtonBase-root \u003e .MuiButton-label',\n        loginerror :'[class=\"MuiTypography-root MuiTypography-caption MuiTypography-colorSecondary MuiTypography-alignCenter\"]',\n        btncreateAccount1:'div.login \u003e .MuiButtonBase-root \u003e .MuiButton-label',\n        firstname :'#firstname',\n        lastname :'#lastname',\n        registeremail :'#registeremail',\n        confirmpassword :'#confirmpassword',\n        btncreateAccount2:'form.register \u003e .MuiButtonBase-root \u003e .MuiButton-label',\n        productSearch :'input[aria-label=\"Product search\"]'\n    }\n  };\n```\nThis is then used by the actual test in this way :\n```javascript\ndescribe('Login and Registration', function() {   \n    test('Account Creation should be successful', function (browser) {\n      var homePage = browser.page.login();\n      homePage.navigate()\n          .createAccount(\"Ashish\",\"Ghosh\",\"Ashish@shop.com\",\"mypassword\")\n  });\n    after(browser=\u003ebrowser.end());\n});\n```\n`login` in the above code is the file name of the page object.\n\nTo run a Nightwatch test use `npx nightwatch`. This is assuming, you have specified the location of your test files in the `src_folders` tag of the `nightwatch.conf.js` file.\n\nTo know more on Nightwatch, go [this link](https://nightwatchjs.org/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghoshasish99%2Fnightwatchjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghoshasish99%2Fnightwatchjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghoshasish99%2Fnightwatchjs/lists"}