Cannot find Chrome binary when executing a selenium (testng) test in jenkins on windows 7 Cannot find Chrome binary when executing a selenium (testng) test in jenkins on windows 7 selenium selenium

Cannot find Chrome binary when executing a selenium (testng) test in jenkins on windows 7


I think you need to install chrome in your instance. for that you follow this basic commands

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpmsudo yum install ./google-chrome-stable_current_*.rpmgoogle-chrome &


It is possible that chrome is installed on your AppData (especially if your are on Windows 7). I am guessing Jenkins could not access the binary from your user directory. Make sure the directory you have Chrome on, is accessible to Jenkins, or try reinstalling chrome again to program files directory.

On the other hand, you can simply instruct Chromedriver where to look for Chrome Binary,

ChromeOptions chromeOptions= new ChromeOptions();chromeOptions.setBinary("C:\\ThePAthtoChrome.exe");ChromeDriver driver = new ChromeDriver(chromeOptions);


The problem is these lines in your code:

File file = new File("C:/Selenium-driver/chromedriver.exe"); System.setProperty("webdriver.chrome.driver", file.getAbsolutePath()); 

This is a massive anti-pattern that I regularly see. The webdriver.chrome.driver environmental variable was designed so that you could install your chromedriver binaries on multiple systems in different places, and then set the environmental variable on each system so that if a selenium test is ever run on that system it will automatically pick up the location of the binary.

By hard coding this environmental variable via code you are ignoring any preconfigured environmental variable that was set up when the build agent was built, you are not using it in the way it was intended.

If you insist on doing it this way you should always check to see if the env variable is already set before you set it, this way you will not overwrite the existing env variable. You will also need to make sure that the file path you have hard coded exists on your build agent (the secondary cause of your error is that it doesn't) so that if the env variable isn't set, you are actually setting a valid path to the chromedriver binary.