0

I set up a java HttpServlet code to run Selenium chromedriver(Ubuntu 16.4) ,if call more than 30 times at the same time,I find some chromedriver process do not exit,and the exception shows "No such session",I hope there is a way I can quit all chromedriver process and raise concurrency.Thanks

WebDriver driver = null;
try {
    DesiredCapabilities caps = DesiredCapabilities.chrome();
    ChromeOptions options = new ChromeOptions();

    options.addArguments("ignore-certificate-errors");

    options.addArguments("disable-gpu");
    options.addArguments("no-sandbox");         
    options.addArguments("--disable-impl-side-painting");//Paint content on the main thread instead of the compositor thread.

    options.addArguments("--test-type", "--start-maximized", "no-default-browser-check"); 
    caps.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
    caps.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new ChromeDriver(caps);

    driver.get(url);
    webDriverWait = (WebDriverWait) new WebDriverWait(driver, timeOutInSeconds, interval);

} catch (Exception e) { //can not catch
    PageSource = e.getMessage();            
    System.err.println(PageSource);
} finally {
    if(null != driver){
        driver.close();
        driver.quit();
        driver = null;
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Walker
  • 1
  • if call more than 30 times at the same time(no matter the memory is 4GB or 16GB),there is have the same issue – Walker Mar 08 '18 at 03:48

3 Answers3

0

Use a process killer to flush out orphan chromedriver.exe from OS process scheduler. ex-

pkill chrome

Save this in a shell file on your ubuntu machine. Invoke it remotely after calling driver.quit();

Manmohan_singh
  • 1,776
  • 3
  • 20
  • 29
0

There are a couple of things which you need to take care as follows :

  • As you mentioned in your question about concurrency, Selenium alone may not be the best fit. You need to use look into JMeter or SoapUI and they integrates with Selenium pretty perfect.
  • There are some redundant code in your script which are never used and you may consider to remove them :

    webDriverWait = (WebDriverWait) new WebDriverWait(driver, timeOutInSeconds, interval);
    
  • Your program will never move within catch{} as there won't be any exception raised. Hence, PageSource will never get printed in the console.

  • Functionally, driver.close(); and driver.quit() sounds similar but have significant difference between them and you need to use them as per your usecase / requirement. You will find a detailed discussion here.
  • If your program successfully spans a new ChromeDriver process and ChromeBrowser instance, in your finally{} block you need to invoke only driver.quit() as follows :

    finally 
    {
          driver.quit();
    }       
    
  • If you still find dangling ChromeDriver process you may require to induce an additional step to clean up them. You will find a detailed discussion here.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I had changed my code like " driver.quit();" , And I use JMeter to test concurrency,I found the problem is still there – Walker Mar 16 '18 at 09:29
0

With Chrome 66 and the chromedriver 2.38, we had a similar problem on Windows machines. After a test suite, the chromedriver would shutdown properly (driver.quit) but there were many Chrome.exe processes left running.

In our case, the fix was to remove the no-sandbox option. This option is not recommended and we should not have used it in the first place. It was a silly copy/paste from a web example. Once the option was removed all processes would close.

I suggest you try removing the no-sandbox argument in your options list.