python - "IOError: [Errno 35] Resource temporarily unavailable"与 PhantomJS、python、 Selenium 、单元测试

标签 python macos selenium phantomjs python-unittest

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

More detailed gist here: 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

最佳答案

已修复!一位同事向我指出了这个相关问题:http://trac.edgewall.org/ticket/2066#comment:1我在那里修改了补丁,使 sys.__stderr__sys.__stdout__ 具有 block 标志。在 phantomjs WebDriver 实例化后立即调用该函数允许将 stderr 发送到 stderr。

关于python - "IOError: [Errno 35] Resource temporarily unavailable"与 PhantomJS、python、 Selenium 、单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22669734/

相关文章:

Ascii 文件中的 Python BOM 错误

linux - 在 Mac OS X 上编译源代码 - 缺少 ether.h

macos - 在 MacOSX(Macbook Pro)上以编程方式读取 CPU 温度(+ 其他传感器数据)

macos - 使用高 CPU 时通知。通过 AppleScript 还是 Automator?

python - 在循环中第二次调用“driver.get(url)”后,Selenium出现“错误:已超过最大重试次数”,其中“url”的值每次迭代都会更改

javascript - Selenium - ElementNotVisibleException。元素在 Safari 9.1 中可见,但在 10.1 中不可见?

java - 尽管有 --no-sandbox 选项,Chromedriver 不会以 root 身份运行

python - 使用单引号运行子进程命令

python - 使用 **kwargs 和装饰器来防止重复代码是否可以接受?

python - 指示 Sphinx 使用特定版本的 Python