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/