2
我在使用selenium
和PhantomJS驅動程序運行單元測試時遇到問題。它似乎與PhantomJS流程中stderr/stdout的資源爭用有關。錯誤是:「IOError:[Errno 35]資源暫時不可用」,使用PhantomJS,python,selenium,unittest
$ python -m unittest selenium_failure.SeleniumTestCase [] [{u'timestamp': 1395857498698, u'message': u'{"log":{"version":"1.2","creator":{"name":"PhantomJS","version":"1.9.7"},"pages":[{"startedDateTime":"2014-03-26T18:11:38.347Z","id":"https://www.google.com/","title":"Google","pageTimings":{"onLoad":294}}],"entries":[{"startedDateTime":"2014-03-26T18:11:38.344Z","time":127,"request":{"method":"GET","url":"https://www.google.com/","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"User-Agent","value":"Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.7 Safari/534.34"},{"name":"Accept","value":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Date","value":"Wed, 26 Mar 2014 18:11:37 GMT"},{"name":"Expires","value":"-1"},{"name":"Cache-Control","value":"private, max-age=0"},{"name":"Content-Type","value":"text/html; charset=UTF-8"},{"name":"Set-Cookie",E ====================================================================== ERROR: test_that_something_fails (selenium_failure.SeleniumTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "selenium_failure.py", line 16, in test_that_something_fails print repr(self.selenium.get_log('har')) IOError: [Errno 35] Resource temporarily unavailable ---------------------------------------------------------------------- Ran 1 test in 2.398s FAILED (errors=1)
更詳細的要點在這裏:https://gist.github.com/lucaswiman/9788422
import unittest
import logging
from selenium.webdriver import phantomjs
import sys
class SeleniumTestCase(unittest.TestCase):
def setUp(self):
self.selenium = phantomjs.webdriver.WebDriver()
def tearDown(self):
self.selenium.quit()
def test_that_something_fails(self):
self.selenium.get('https://www.google.com')
print repr(self.selenium.get_log('browser'))
print repr(self.selenium.get_log('har'))
raise AssertionError()
的錯誤是可重複使用的OS X是要點,而不是在Ubuntu 12.04。我相信這不是特定於OS X的,因爲我們在Ubuntu上運行集成測試時看到類似的錯誤,儘管我沒有能夠以獨立的形式重現它。
- 的Python 2.7.6
- 硒== 2.35.0
- [email protected]