1。在Linux上执行的用例脚本,偶尔会停止,但是脚本日志本身没有捕获到异常,
geckodriver的相关日志:
2.脚本、Firefox等进程还在,但是没有往下执行了。
3.脚本日志记录了最后一个正常执行的Firefox、geckodriver的pid,这些pid是倒数第二个用例的所起的pid。在自动化测试后台记录的最后一个用例,没有开始插入请求信息。所以可能是启动Firefox了,但是Firefox没响应,需要进一步定位。
3.尝试更新selenium、Firefox、geckodriver版本。
原来的版本信息:
selenium:3.12 (import selenium;help(selenium))
geckodriver:0.20.1
Firefox:56.0.2 (firefox --version)
更新后的版本信息:
selenium:3.14
geckodriver:0.20.1
Firefox:60.0.1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
今天又出现这个问题了,但是看geckodriver的日志,发现了以前未出现过的错误。
1538259743546 Marionette FATAL Remote protocol server failed to start: Error: Could not bind to port 39668 (NS_ERROR_SOCKET_ADDRESS_IN_USE) (chrome://marionette/content/server.js:87:17) JS Stack trace: set acceptConnections@server.js:87:17 start@server.js:116:5 init/<@marionette.js:537:9 1538259743558 addons.xpi WARN Exception running bootstrap method shutdown on activity-stream@mozilla.org: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIObserverService.removeObserver]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: resource://activity-stream/lib/SnippetsFeed.jsm :: uninit :: line 185" data: no] Stack trace: uninit()@resource://activity-stream/lib/SnippetsFeed.jsm:185 onAction()@resource://activity-stream/lib/SnippetsFeed.jsm:201 _middleware/</<()@resource://activity-stream/lib/Store.jsm:49 Store/this[method]()@resource://activity-stream/lib/Store.jsm:28 uninit()@resource://activity-stream/lib/Store.jsm:151 uninit()@resource://activity-stream/lib/ActivityStream.jsm:300 uninit()@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///usr/local/firefox/browser/features/activity-stream@mozilla.org.xpi!/bootstrap.js:73 shutdown()@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///usr/local/firefox/browser/features/activity-stream@mozilla.org.xpi!/bootstrap.js:169 callBootstrapMethod()@resource://gre/modules/addons/XPIProvider.jsm:4436 observe()@resource://gre/modules/addons/XPIProvider.jsm:2287 init/<()@jar:file:///usr/local/firefox/omni.ja!/components/marionette.js:542 JavaScript error: jar:file:///usr/local/firefox/omni.ja!/components/marionette.js, line 547: TypeError: this.server is null JavaScript error: resource://gre/modules/ProfileAge.jsm, line 174: Error: Unable to fetch oldest profile entry: Unix error 2 during operation lstat on file /tmp/rust_mozprofile.90aSkqvMJnop (No such file or directory) *** UTM:SVC TimerManager:registerTimer called after profile-before-change notification. Ignoring timer registration for id: telemetry_modules_ping
提示Marionette绑定不了39668端口。然后查了下这个端口的信息,local Address和foreign address都用了一样的端口。local Address是geckodriver绑定的端口,
foreign Address是Marionette绑定的端口。
所以暂时把今天脚本中断的原因定为,geckodriver和Marionette的端口冲突了?
措施:1.也没找到对应的解决方法,先把geckodriver更新为0.22.0,Firefox更新为62.0
2.或者后续可以加个shell脚本之类的,监控如果Xvfb、geckodriver的进程时间超过10mins没有更新,则kill掉相应的进程,然后继续执行被终止及之后的用例?
还可以怎么定位问题?
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
补充:之前的部署步骤
- 安装pyvirtualdisplay
- pip install pyvirtualdisplay
- 安装Xvfb(作为后端)
- yum install xorg-x11-server-Xvfb
- 安装Firefox
- cd /usr/local
- wget https://ftp.mozilla.org/pub/firefox/releases/56.0.2/linux-x86_64/en-US/firefox-56.0.2.tar.bz2
- tar xjvf firefox-56.0.2.tar.bz2
- ln -s /usr/local/firefox/firefox /usr/bin/firefox
- 下载geckodriver
- wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz
- 解压geckodriver-v0.19.1-linux64.tar.gz
- tar xvzf geckodriver-*.tar.gz
- 在环境变量目录/usr/bin/中添加geckodriver的硬链接
- ln -s /usr/local/geckodriver /usr/bin/geckodriver
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
后续:原来的脚本用例设计其实有问题,每个用例都重新启动一遍浏览器,上百个用例频繁打开启动,应该就是这样导致偶尔启动不了。现在改成把启动浏览器的操作封装成一个方法,每次执行脚本就只调用一遍那个方法,即执行完所有用例再关闭浏览器和Xvfb。(自己瞎折腾的,只能慢慢优化了)
参考:https://blog.csdn.net/yinshuilan/article/details/79730239
关于geckodriver和Marionette:http://toolsqa.com/selenium-webdriver/how-to-use-geckodriver/
http://t-coes.com/blog/2017/08/14/launch-firefox-browser-selenium-3-0-geckodriver/