Introduction :
Software Automation Testing has evolved a lot in the past 4 to 5 years.With the evolution of Automation Testing and Software Testing Practices , testers are expected to perform automation testing across various browsers incase of Web Automation Testing.Thus it becomes sometimes too tedious to run same set of test cases across multiple browsers.Chrome is one such example.
Lets start to automate a sample script for Chrome Browser :
You can download the chrome driver from here
Add the below piece of code in your Eclipse/IntelliJ IDEA Editor
1 2 3 4 5 6 7 |
public class Test { public static void main(String[] args) { Webdriver driver = new ChromeDriver(); } } |
Run as a Java Program, you should get the below output :
1 2 3 4 5 6 7 8 9 |
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:199) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109) at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:116) at LoginTest.main(LoginTest.java:19) |
The error clearly states that user has not added the chrome driver executable path in the System property.
Now change the above piece of code to something like below
1 2 3 4 5 6 7 8 |
public class Test { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","/Users/stevangomes/Documents/StevanOffice/Jar_Files/chromedriver"); Webdriver driver = new ChromeDriver(); } } |
Again run as Java program, Chrome browser will open up.The main advantage of running testcases on different browsers is that it helps us in creating a better framework with Selenium Grid where we are expected to run different test cases parallely.
Leave a Reply