TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Selenium Webdriver Running Test on Chrome Browser

Selenium Webdriver Running Test on Chrome Browser with Introduction, features, selenium basic terminology, what is selenium, selenium limitations, selenium vs qtp, tool suite, selenium ide, ide-installation, ide-features, ide-first test case, ide-commands, ide-creating test cases manually, ide-login test etc.

<< Back to SELENIUM

Selenium WebDriver- Running test on Chrome Browser

In this section, you will learn how to run your Selenium Test Scripts on Chrome Browser.

Chrome browser implements the WebDriver protocol using an executable called ChromeDriver.exe. This executable start a server on your system which in turn is responsible for running your test scripts in Selenium.

Let us consider a test case in which we will try to automate the following scenarios in Google Chrome browser.

  • Launch Chrome browser.
  • Maximize the browser.
  • Open URL: www.TheDeveloperBlog.com
  • Scroll down through the web page
  • Click on "Core Java" link from the Java Technology section.

We will create our third test case in the same test suite (Demo_Test).

Step1. Right click on the "src" folder and create a new Class File from New > Class.

Give your Class name as "Third" and click on "Finish" button.


Selenium WebDriver- Running test on Chrome Browser
Selenium WebDriver Running test on Chrome Browser

Step2. Open URL: https://sites.google.com/a/chromium.org/chromedriver/downloads in your browser.

Step3. Click on the "ChromeDriver 2.41" link. It will redirect you to the directory of ChromeDriver executables files. Download as per the operating system you are working currently on.


Selenium WebDriver Running test on Chrome Browser

For windows, click on the "chromedriver_win32.zip" download.


Selenium WebDriver Running test on Chrome Browser

The downloaded file would be in zipped format. Unpack the contents in a convenient directory.


Selenium WebDriver Running test on Chrome Browser

Step4. Set a system property "webdriver.chrome.driver" to the path of your ChromeDriver.exe file and instantiate a ChromeDriver class.

Here is a sample code to do that.

// System Property for Chrome Driver 
	System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe");
	
       // Instantiate a ChromeDriver class. 	
	WebDriver driver=new ChromeDriver();

Step5. Now it is time to code. We have embedded comments for each block of code to explain the steps clearly.

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Third {

	public static void main(String[] args) {
	
		   // System Property for Chrome Driver 
		System.setProperty("webdriver.chrome.driver", "D:\\ChromeDriver\\chromedriver.exe");
		
	         // Instantiate a ChromeDriver class. 	
		WebDriver driver=new ChromeDriver();
		
		   // Launch Website
		driver.navigate().to("http://www.TheDeveloperBlog.com/");
		
		 //Maximize the browser
	      driver.manage().window().maximize();
		
		  //Scroll down the webpage by 5000 pixels
		JavascriptExecutor js = (JavascriptExecutor)driver;
		js.executeScript("scrollBy(0, 5000)"); 
		
		 // Click on the Search button
		driver.findElement(By.linkText("Core Java")).click();	

	}

}

The Eclipse code window will look like this:


Selenium WebDriver Running test on Chrome Browser

Step6. Right click on the Eclipse code and select Run As > Java Application.


Selenium WebDriver Running test on Chrome Browser

Step6. The output of above test script would be displayed in Chrome browser.


Selenium WebDriver Running test on Chrome Browser




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf