Home >>Selenium Tutorial >Selenium WebDriver Running test on Chrome Browser

Selenium WebDriver Running test on Chrome Browser

WebDriver Running test on Chrome Browser

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

Chrome browser follows the WebDriver specification using an executable named ChromeDriver.exe. This executable begins a server on your machine which is in effect liable for running your Selenium test scripts.

Let's call a test case in which we'll attempt to simplify the following Google Chrome browser.

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

Our third test case will be built inside the same test suite (Demo_Test).

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

Offer your name of Class as "Third" and press the "Finish" button.

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

Step 3. Click on the link called "ChromeDriver 2.41." It will lead you to the executables files directory at ChromeDriver. Update as per currently running operating system.

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

The file that you access will be in zipped format. Unpack the contents in an correct directory.

Step 4. Set a "webdriver.chrome.driver" system property to the path of your ChromeDriver.exe file, and instant a ChromeDriver account.

Here is a sample code to do that.

// System Property for Chrome Driver   
// Instantiate a ChromeDriver class.       
WebDriver driver=new ChromeDriver();  

Step 5. It is now time to write. For each block of code we've inserted comments to illustrate 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  
         //Maximize the browser  
          //Scroll down the webpage by 3000 pixels  
JavascriptExecutor js = (JavascriptExecutor)driver;  
        js.executeScript("scrollBy(0, 3000)");   
         // Click on the Search button  
        driver.findElement(By.linkText("Core Java")).click();     
    }    }  

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

No Sidebar ads