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

问题描述

在使用 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()

附加说明

如果使用 webDriver.close() 将会发现:虽然没有正在运行的自动化测试任务,Selenium Node 依旧存在正在运行的 chromedriver 进程。这就是因为没有正确关闭(webDriver.quit()) WebDriver 而出现的问题。

参考文献

python - How do I close the browser window at the end of a Selenium test? - Software Quality Assurance & Testing Stack Exchange
What is close() and quit() commands in Selenium Webdriver? | Zyxware Technologies
selenium close browser- How to close the whole browser window by keeping the WebDriver active? - Intellipaat Community

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值