Git Product home page Git Product logo

nightwatch-demo's Introduction

Trialling Nightwatch.js ๐Ÿฆ‰

Intro

Nightwatch is a JavaScript-based, end-to-end (e2e) testing framework which typically can be used to mimic a user interacting with a website or webpages. I've used it here to test user interactions such as:

  • button or link clicks
  • modal activation
  • asserting text/headings
  • taking screenshots as a before and after check.

Basic Setup ๐Ÿ› ๏ธ

  1. Make a new directory, say on your desktop and change into that directory.
  2. Ensure you have node and NPM installed.
  3. Some commands to install and run Nightwatch from your terminal (on MAC in VS Code: control + ~):
npm init -y
npm --version
npm install nightwatch --save-dev
npx nightwatch
npm install chromedriver --save-dev 
  1. We need to do some setup with the nightwatch.conf.js file. Namely, tell Nightwatch where our test scripts should be accessed from and the name of the browserName value. So in nightwatch.conf.js:
  • Pass in the folder name of the test scripts. In our case, we called the folder 'tests'.
  • Pass in the browser name under the desiredCapabilities object. In our case, it was 'chrome'.
module.exports = {
src_folders: ['tests'],
...
desiredCapabilities: {
        browserName : 'chrome'
      },
...
}
  1. Create in your code editor, a folder containing your tests and of course it should match the src_folders value.
  2. Ensure your version of browser (using Chrome for this repo) matches the driver version. Check out the debugging section below.

Back in terminal:

npx nightwatch run
npx nightwatch enterYourTestFileNameHereAndFilePath.test.js

Useful Resources ๐Ÿ“š

Debugging ๐Ÿ›

  • // debugger;

  • // .perform(() => {debugger})

  • node --inspect -brk node_modules/.bin/nightwatch -- tests/homepage.test.js

  • node --inspect -brk node_modules/.bin/nightwatch -- --tag smoke-homepage

  • chrome://inspect/#devices

  • Under Remote Target, click inspect link. Then run the script execution (play btn top-right)

  • Adding debugger in the script automatically stops the execution at the line where this keyword is written.

  • Alternatively, using the .perform() closure above also stops the script.

  • Using the debugger tool is useful in checking state of interactive components right before an execution event.

Maintaining Versions ๐Ÿงฐ

After returning to this project twice about 6 months aprt, my Chrome Browser was incompatible with the Webdriver used to run the browser context. Went to (ChromeDriver website)[https://chromedriver.chromium.org/downloads] and matched their version number with my browser version: download the chromedriver zip file and drag and drop chromedriver.exe into node_modules/.bin/ folder. I had an issue with Chrome Version 115 but no equivalent web driver. Went here (115 version) [https://googlechromelabs.github.io/chrome-for-testing/#stable] downloaded this: https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/115.0.5790.102/mac-x64/chromedriver-mac-x64.zip

nightwatch-demo's People

Watchers

Will avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.