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.tutoraspire.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.
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.
For windows, click on the “chromedriver_win32.zip” download.
The downloaded file would be in zipped format. Unpack the contents in a convenient directory.
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.
Step5. Now it is time to code. We have embedded comments for each block of code to explain the steps clearly.
The Eclipse code window will look like this:
Step6. Right click on the Eclipse code and select Run As > Java Application.
Step6. The output of above test script would be displayed in Chrome browser.