PhantomJS、Python、Selenium、unittest中出现“IOError:[Errno 35]资源暂时不可用”的错误。

3
我在使用Selenium和PhantomJS驱动运行单元测试时遇到了问题。似乎与PhantomJS进程中stderr / stdout的资源争用有关。错误信息如下:
$ 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)
----------------------------------------------------------------------
跟踪信息:
  File "selenium_failure.py", line 16, in test_that_something_fails
    print repr(self.selenium.get_log('har'))
IOError: [Errno 35] 资源暂时不可用
---------------------------------------------------------------------- 共运行1个测试,用时2.398秒
FAILED(错误=1)
更详细的gist信息在这里: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
  • selenium==2.35.0
  • phantomjs@1.9.7
1个回答

2

已修复!我的同事向我提到了这个相关的问题:http://trac.edgewall.org/ticket/2066#comment:1。我修改了那里的补丁,使sys.__stderr__sys.__stdout__带有块标志。在幻象WebDriver实例化后立即调用该函数,就可以将stderr发送到stderr。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接