Google+

Executing Selenium 2 Automation Scripts on Chrome Browser

In order to execute the Selenium 2 automation scripts on Chrome browser, we need ChromeDriver.

ChromeDriver is not an inbuilt driver in Selenium:

Unlike FirefoxDriver, ChromeDriver is not an inbuilt driver in Selenium. Instead we have to download the 'chromedriver.exe' file separately, apart from downloading Selenium Jar files.



Executing Selenium 2 Automation Scripts on Chrome Driver

In order to execute the Selenium 2 Automation scripts, we need to configure the Java project using the Selenium 2.53.1 version Jar files. Selenium 2.53.1 version is the last version available in Selenium 2. For compatibility, we need to use the latest versions of Chrome Browser and Chrome Driver.

Lets practically execute Selenium 2 Automation Scripts on latest Chrome Browser using the latest version of ChromeDriver:

1.Create a new Java Project in Eclipse IDE as shown below:



2. Create a 'libraries' folder in the project as shown below:



3. Go to http://www.seleniumhq.org/download/ and click on 'Previous Releases' option as shown below:


4. In the resultant page, click on '2.53' link option as shown below:


5. In the resultant page, click on 'Selenium-java-2.53.1.zip' link option as shown below:


6. Observe that a Zip file will be downloaded and extract the download Zip file as shown below:


7. Open the extracted folder and copy the two jar files as shown below:



8. Paste the copied Jar files into the 'libraries' folder in Java Project as shown below:



9. Open the 'lib' folder inside the extracted folder as shown below:



10. Copy all the Jar files inside the 'libs' folder as shown below:


11. Paste all the Jar files into the 'libraries' folder in Java Project as shown below:



12. Now configure the Jar files in the 'libraries' folder. Right click on the Java Project and select 'Build Path > Configure Build Path' option as shown below:



13. In the resultant 'Properties' dialog, select 'libraries' tab and 'Add Jars' button as shown below:




14. In the resultant dialog, select all the Jar files under the 'libraries' folder and click on 'OK' and 'Apply' buttons until all the dialogs gets closed as shown below:



15. Observe that all the Selenium Jar files got configured and displayed as shown below:




16. Create a new Class in the Java Project as shown below:



17. Create a driver object for ChromeDriver class as shown below:



18. Hover the mouse over the above error message and select the below displayed items to resolve the errors:


19. Observe that the errors got resolved and write the remaining Selenium code to navigate to http://www.omayo.blogspot.com, click on 'Selenium143' link on the page and close the browser as shown below:



20. Install the latest Chrome browser, open the Chrome browser and browse 'chrome://help/' as below to check whether the latest chrome browser is installed:



21.  Execute the above Selenium code and observe that the code wont be executed on Chrome browser, instead we get an exception as shown below:



22. From the above error message, its clearly mentioned that we have to set the 'webdriver.chrome.driver' property. We will write the below code to set the required property:



23. Copy the 'webdriver.chrome.driver' from the error message and paste it as shown below:



24. Now, create a 'drivers' folder in the Java Project as shown below:



25. Go to http://www.seleniumhq.org/download and click on the latest version link the of Google Chrome Driver as shown below:



26. In the resultant page, click on the windows 32 bit version as shown below:



27. Extract the downloaded Zip file and open the extracted folder as shown below:



28. Copy the chromedriver.exe in the above opened folder as shown below:



29. Paste the copied exe file into the 'drivers' folder as shown below:



30. Now provide the path of the pasted 'chromedriver.exe' under the drivers folder in the Selenium code as shown below:



31. Now, we have the Java Project configured with Selenium 2.53.1 Jar files, the latest Chrome browser and latest chromedriver.exe file along with its path set in the Selenium code. Lets execute the Selenium 2 Automation code as shown below:



32. On executing the above code, Chrome browser will be launched, User will be navigated to http://www.omayo.blogspot.com application, 'Selenium143' link on the page will be clicked and hence the user will be navigated to http://www.selenium143.blogspot.com page and finally the browser will close.

Conclusion:

In order to execute the Selenium 2 automation scripts on Chrome browser, we need to use the last version of Selenium 2 i.e. Selenium 2.53.1, latest Chrome Browser and chromedriver.exe along with chromedriver.exe's path set in the Selenium code.

No comments:

Blog Index