Selenium Test With Chrome Browser

Executing Selenium WebDriver Script With Chrome Browser

In this post, we see How to run a selenium web driver script with a chrome browser.
To execute selenium test in chrome browser we need to have Chromedriver.exe and Selenium WebDriver.

I hope you have already installed Selenium WebDriver inside the project.

Chromedriver.exe is an executable file, which is responsible to start the server on your system . All your tests communicate to this server to run your test. 

 

Steps To execute Test on Chrome Browser : - 

1. Download Chrome Driver 
Click Here, This website details out all the features that are available in the chrome driver. Before download Read carefully about the chrome driver version, and For which chrome version it is going to support.



Download chromedriver binary according to the OS of System. Click Here to redirect on the index page of the chrome driver version page.
After download move physically in a folder 

2. Download Selenium WebDriver 
Click Here to download the selenium web driver and import it inside your project.

3. Launching Chrome Browser using Selenium WebDriver
  1.  Set System setProperty
     The path of the driver executable must be set by the webdriver.chrome.driver system property 
  2.  Create an object of ChromeDriver class 
  3. Use selenium pre-define method and execute test 

Example:-

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class ChromeDriverTest {
public static void main(String[] args) throws IOException {

System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");

WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

System.out.println("Page title is: " + driver.getTitle());
TakesScreenshot screenshot=(TakesScreenshot)driver;
//Call method to capture screenshot
File src=screenshot.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("D:\\data123.png"));
driver.quit();

}
}



In my case I have used for this test :

  1. Selenium 3.12.0 version
  2. chrome browser 74 ( Latest )
  3. Chromedriver binary 2.38

Issues 

Most of the time you will get org.openqa.selenium.WebDriverException:java.net.SocketException:Connection to reset
this is happening due to version mismatch of Desktop Chrome version and ChromeDriver.exe. Just make sure that you are using the latest chrome browser version and latest chromedriver binary file and also Both should be compatible with Selenium WebDriver Version.


I hope you have enjoyed this article if yes then share with your friends and Let me know your feedback in the comment section.

Post a Comment

Previous Post Next Post