天天看點

「Selenium Grid 3」- Node xxxxx has no free slots(close() vs quit()) @20210420

問題描述

在使用 Selenium Grid 3 進行自動化測試的過程中,出現“啟動停滞”問題(在經過漫長等待後,Selenium Node 才能啟動浏覽器,開始自動化測試)。

檢視 Selenium Hub 日志,發現如下資訊:

Sep 28 04:25:41 selenium-hub java[4609]: 04:25:41.020 DEBUG [ProxySet.getNewSession] - Available nodes: [http://172.31.253.104:24663]
Sep 28 04:25:41 selenium-hub java[4609]: 04:25:41.020 DEBUG [BaseRemoteProxy.getNewSession] - Trying to create a new session on node http://172.31.253.104:24663
Sep 28 04:25:41 selenium-hub java[4609]: 04:25:41.021 DEBUG [BaseRemoteProxy.getNewSession] - Node http://172.31.253.104:24663 has no free slots
      

問題原因

在自動化測試代碼中,我們沒有正确的退出浏覽器(WebDriver),占用 Selenium Node 資源,長此以往導緻 Selenium Node 無法配置設定資源進行新的測試。

應該使用 webDriver.quit() 關閉浏覽器,而不是使用 webDriver.close() 關閉浏覽器。

webDriver.close()

close() is a webdriver command which closes the browser window which is currently in focus.During the automation process, if there are more than one browser window opened, then the close() command will close only the current browser window which is having focus at that time. The remaining browser windows will not be closed.

webDriver.quit()

quit() is a webdriver command which calls the driver.dispose method, which in turn closes all the browser windows and terminates the WebDriver session. If we do not use quit() at the end of program, the WebDriver session will not be closed properly and the files will not be cleared off memory. This may result in memory leak errors.

解決辦法

修改代碼,将在自動化測試中的 webDriver.close() 改為 webDriver.quit()

附加說明

相關文章

參考文獻