Basic test with Selenium

To run a basic test with Selenium, you need a few things installed: node, mocha, and selenium-webdriver. Follow the normal install procedure for those.

Mocha is a command line program, and can be run with:

mocha [FILENAME.JS]

I include the “-t 0” parameter to ignore timeout warnings.

A sample script to launch chrome, navigate to a site, and get the title of the page:

var webdriver = require(‘selenium-webdriver’)
var chrome = require(‘selenium-webdriver/chrome’)

var driver = new webdriver.Builder()
.forBrowser(‘chrome’)
.build();

describe(‘Sample test’, function(){
it(‘gets TITLE from the site’, function(){
driver.get(‘http://google.com/’)
driver.getTitle().then(function(title)}
console.log(‘title is:’, title)
})
driver.quit();
});
});

If the test does not run, you may need to install the Chrome webdriver executable.