top of page

Selenium NPM Tutorial

First Test In Selenium JavaScript

How To Write A Selenium Test In JavaScript ?

Prerequisites :
Install Selenium JavaScript setup on an editor => Follow Guide

Writing a Selenium Test in JavaScript :
  • 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.) and open it in editor.

  • Create a new folder as 'tests' in the project folder.

  • Create a '.js' file named 'FirstTest.js' in the folder tests.

  • The FirstTest.js file will be as :

* Create an asynchronous function.

async function firstTest

* Import selenium-webdriver and chromedriver.

let webdriver =require("selenium-webdriver");


* Launch the web browser(chrome).​

let driver=new webdriver.Builder().forBrowser("chrome").build();

* Navigate to the url ''.

* Quit the browser.

await driver.get("");

await driver.quit();

* Call the function.


  • To run,navigate to the folder tests and then use command "node filename.js", i.e. "node FirstTest.js".

Refer next page Concept Of MochaJS And ChaiJS In Selenium
bottom of page