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

后端 未结 13 1521
太阳男子
太阳男子 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 10:47

    I had the same problem, I was able to execute selenium scripts through local but when tried executing on Jenkins got error "unknown error: cannot find Chrome binary".

    Here is my solution which worked on Jenkins server: 1. Download and enable Xvfb before start of selenium script on jenkins. For more info read here https://wiki.jenkins.io/display/JENKINS/Xvfb+Plugin 2. I am having ubuntu 16.xx os on local and jenkins server. 3. Try to keep chromedriver in "usr/bin" folder only otherwise you may get error.

    try {
    
                if(service == null){
                    service = new ChromeDriverService.Builder()
                            .usingDriverExecutable(new File("/usr/bin/chromedriver"))// set the chromedriver path
                           .usingAnyFreePort()
                            .withEnvironment(ImmutableMap.of("DISPLAY", ":15"))
                            .withSilent(true)
                            .build();
                    service.start();
                }
    
                System.out.println("Reading chrome driver");
                System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.addArguments("--headless");
                WebDriver driver = new ChromeDriver(chromeOptions);
                driver.get("https://google.com");
                driver.quit();
     }
            catch(Exception ex){
            System.out.println(ex.getMessage());
            }
    
    
    0 讨论(0)
  • 2020-12-29 10:50
    • Check the OS of the Agent Node.
    • Check how Jenkins Access the agent Node. if its via JNLP and the OS is below Window 7, through Admin right install the Chrome in C:/Program Files(x86) where Jenkins can access the chrome.exe and set binaries using below code:
    ChromeOptions options = new ChromeOptions();
    if(System.getProperty("os.name").equals("Windows Server 2012 R2")){
        File ChromeExePath =new File("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe");
        if (ChromeExePath.exists()){
            options.setBinary(ChromeExePath);
        }
    }
    
    ChromeDriver driver = new ChromeDriver(options);
    
    0 讨论(0)
  • 2020-12-29 10:50

    Please check your binary path if still not works then

    you should have installed chrome in your machine

    and your chromedriver.exe version should accordingly (like if you have chrome 87.0 ver then download chromedriver.exe for ver 87.0)

    download form it from https://chromedriver.chromium.org/downloads

    and given new chromedriver.exe path to your script.

    This works fine for me

    0 讨论(0)
  • 2020-12-29 10:57

    It worked for me. I have coded as below

    ChromeOptions chromeOptions= new ChromeOptions(); 
    
    chromeOptions.setBinary("C:\\Users\\kannanu\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
    System.setProperty("webdriver.chrome.driver",ChromeExePath);
    ChromeDriver driver = new ChromeDriver(chromeOptions); 
    driver.get("http://newtours.demoaut.com/");
    
    0 讨论(0)
  • 2020-12-29 10:59

    I was having similar issue in JS, it got fixed after installing npm i chromedriver

    0 讨论(0)
  • 2020-12-29 11:01
    ChromeOptions chromeOptions= new ChromeOptions();
    chromeOptions.setBinary("C:\\Program Files (x86)\\Google\\Chrome Beta\\Application\\chrome.exe");
    System.setProperty("webdriver.chrome.driver","C:\\STUDY\\Selenium\\CHROMEDRIVERS\\chromedriver.exe");
    
    ChromeDriver driver = new ChromeDriver(chromeOptions);
    driver.get("http://newtours.demoaut.com/");
    
    0 讨论(0)
提交回复
热议问题