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

后端 未结 13 1520
太阳男子
太阳男子 2020-12-29 10:22

I have a basic login test with selenium and testng. When executed from eclipse, it works as expected and invoke Google Chrome. If executed from TESTNG command line, it works

相关标签:
13条回答
  • 2020-12-29 11:02

    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.

    0 讨论(0)
提交回复
热议问题