Selenium + Node
Introduction to Selenium Webdriver Introduction to Node.js Installation and Environment set up NPM – Package Manage for Node.js Directory layout of Selenium Webdriver Node.js package Chrome Chrome with options Chrome in Mobile Emulation IE Firefox Element identification methodsAssertions in Selenium in Node.js Interacting with elements in Selenium in Node.js Basic Browser window automation Sending keys in Selenium in Node.js Synchronization in Selenium Check if Element exists Working with Tables using Selenium Performing advanced actions using Selenium in Node.js Executing JavaScript in Selenium in Node.js Working with multiple Browser Windows or tabs Working with multiple frames Handling alerts Common exceptions in Selenium Taking a screenshot in selenium Mocha – Unit testing framework Selenium gridInstallation of Selenium in node
You need to follow below steps to set up the environment for running Selenium tests using Node.js- Download and install Node.js
- Install Selenium Webdriver package for Node.js
- Download the drivers for various browsers like IE, Chrome, Firefox etc
- Write the tests in Java Script and Execute it.
Downloading and Installing Node.js
Just visit official Node.js website and download the Node.js installer for windows. Double click on that installer file and follow on-screen instructions to install the Node.js. After installation is completed, update the system path to include the location of Node.js installation directory. Node.js in System Path Node.js in System Path To ensure that Node.js is installed correctly, open the command prompt and execute below command. Checking Node.js Version Checking Node.js Version As you can see, I have got v4.4.7 installed on my system.Installing Selenium Webdriver Package for Node.js
Next you have to install the Selenium Webdriver package for Node.js. For that, just execute below command in a command prompt.
npm install selenium-webdriver
Downloading driver files for browsers
After that download the driver applications for each browsers and update the system path to point to the location where you have placed the drivers.- https://chromedriver.storage.googleapis.com/index.html
- https://selenium-release.storage.googleapis.com/index.html
- https://go.microsoft.com/fwlink/?LinkId=619687
- https://github.com/mozilla/geckodriver/releases/
- https://selenium-release.storage.googleapis.com/index.html
Writing and running the first script using Node.js
Then write the sample selenium code as shown in below example and save the file as launchChrome.js
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
driver.get('https://www.softpost.org');
driver.quit();
To execute the above file, you need to fire below command in a command prompt.
node launchChrome.js
There are many Node.js packages out there for browser automation using Selenium. But we we would be using selenium-webdriver official package. Here is the list of other node.js packages for selenium automation. Synchronized Selenium Webdriver – https://www.npmjs.com/package/webdriver-sync Another way is by using node-fibers and wd-synch libraries as explained at Webdriver.ioWeb development and Automation testing
solutions delivered!!