Testing JavaScript With Selenium & Mocha

Mocha is a JavaScript testing framework that, along with the Chai library, allows the test writer to test code using Node.js and have expected outcomes in order to pass the test.

So far, I have covered how to use Selenium Web-Driver to automate usage of a web application on Chrome. It is not a big stretch to imagine how we can combine the automation of a web application with selenium and check for expected outcomes using Mocha and Chai!

Some different use cases I have implemented in my internship include:

  • Testing for presence of certain elements
  • Testing for absence of certain elements
  • Testing for expected behavior such as video encoding, video playback, and video filtering

One can imagine how the sky is the limit with this amazing tools! You can test for almost anything in JS, no matter how niche, with the mixture of Selenium, Mocha, and Chai.