"IOError:[Errno 35]资源暂时不可用"与PhantomJS,python,selenium,unittest一起使用 [英] "IOError: [Errno 35] Resource temporarily unavailable" with PhantomJS, python, selenium, unittest

查看:103
本文介绍了"IOError:[Errno 35]资源暂时不可用"与PhantomJS,python,selenium,unittest一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用selenium和PhantomJS驱动程序运行单元测试时遇到问题.它似乎与PhantomJS进程中stderr/stdout的资源争用有关.错误是:

I'm having an issue with running unit tests using selenium and the PhantomJS driver. It seems to be related to resource contention for stderr/stdout in the PhantomJS process. The error is:


$ 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

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上的集成测试中遇到了类似的错误,尽管我无法以孤立的形式复制它.

The error is reproducible with that gist on OS X, but not on Ubuntu 12.04. I believe it's not specific to OS X, since I've seen a similar error for our integration tests on running on Ubuntu, though I haven't been able to reproduce it in an isolated form.

  • Python 2.7.6
  • selenium == 2.35.0
  • phantomjs@1.9.7

推荐答案

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

Fixed! A coworker pointed me to this related issue: http://trac.edgewall.org/ticket/2066#comment:1 I modified the patch there to make sys.__stderr__ and sys.__stdout__ have the block flag. Calling that function immediately after the instantiation of the phantomjs WebDriver allowed the stderr to be sent to stderr.

这篇关于"IOError:[Errno 35]资源暂时不可用"与PhantomJS,python,selenium,unittest一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆