Concept Of MochaJS And ChaiJS In Selenium
​
​
What Is Mocha And Chai ?
​
​
Mocha is a javascript test framework that runs tests on NodeJS and in the browser.It provides a modular way to write a structured code for testing the applications by classifying them into test suites and test cases modules for execution and produces a precise test report.
To enhance code reusability Mocha provides some kinds of hooks (before,after,beforeEach,afterEach,beforeAll,afterAll).
​
It comes in the form of a Node package via 'npm' supporting a set of JavaScript assertion libraries.
Mocha is compatible for Chai which is an assertion library.
​
Mocha has two modes for running tests,either by command line(CLI) or programmatically(Mocha API).But we will be further focusing on CLI method.
​
How to Install and Setup Mocha-Chai ?
​
Prerequisites :​​
Install Selenium JavaScript setup on an editor => Follow Guide
​
​
Installing Mocha-Chai Via NPM
-
Open VS code,go to the File,click on Open folder.
-
Now browse to that project folder where setup has done for selenium javascript(In my case it's SeleniumJS.) to open it in editor.
-
Open terminal in the editor.
-
Navigate to the project folder directory using 'cd' command.
-
To install mocha-chai,run command : 'npm install mocha chai'.
-
Wait for the installation.
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
-
Once installed,the package.json file would be updtaed with newly added dependencies which are for mocha and chai.
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
-
Also,mocha and chai libraries would be added in .bin folder of package node_modules.
-
Now mocha-chai setup has been done.
​
​
​​
​
Refer next page Selenium Test In Mocha-Chai Framework