处理到Selenium服务器时,Django Jenkins引发WebDriverException [英] Django Jenkins raises WebDriverException when processed to Selenium server
问题描述
我通过命令启动Selenium服务器集线器
I start Selenium server hub by command
java -jar selenium-server-standalone-2.33.0.jar -role hub
和Selenium服务器节点命令
and Selenium server node by command
java -jar selenium-server-standalone-2.33.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=htmlunit
然后我试图执行代码:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
server = 'http://localhost:4444/wd/hub'
dc = DesiredCapabilities.HTMLUNIT
browser = webdriver.Remote(server, dc)
browser.get('http://localhost:8000')
此后一切都可以。
但是当我试图启动Jenkins测试:
Everything is ok after this. But when i'm trying to start Jenkins test:
from django.test import TestCase, LiveServerTestCase
from selenium.webdriver.common import proxy
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.remote.webdriver import WebDriver
class SeleniumTest(LiveServerTestCase):
@classmethod
def setUpClass(cls):
p = proxy.Proxy({
'proxyType': proxy.ProxyType().MANUAL,
'httpProxy': '127.0.0.1:4444',
})
capabilities = DesiredCapabilities().HTMLUNIT
cls.selenium = WebDriver(desired_capabilities=capabilities, proxy=p)
super(SeleniumTest, cls).setUpClass()
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super(SeleniumTest, cls).tearDownClass()
def test_javascript_basket(self):
self.selenium.get('http://localhost:8000')
我正在追踪错误,包含在追溯中:
I'm getting following error, contained in traceback:
WebDriverException:消息:u'\\\
\\\
\ERROR:请求的URL不能已检索\\\
\\\
\\\
\\\
错误
\\\
无法检索请求的URL
\\\
\\\
\\\
\\\
\\\
尝试检索URL时遇到以下错误:a href =http:// localhost:4444 / wd / hub / sessionlocalhost:4444 / wd / hub / session ap\\ \\ n\\\
\\\
连接到127.0.0.1失败。
\\\
\\\
系统返回:(111 )拒绝连接
远程主机或网络可能已关闭。请再次尝试该请求。
The remote host or network may be down. Please try the request again.
您的缓存管理员是网站管理员。
Your cache administrator is webmaster.
生成星期一,2013年6月10日04:36:42 GMT由localhost(squid / 3.1.6)
Generated Mon, 10 Jun 2013 04:36:42 GMT by localhost (squid/3.1.6)
发生了什么事?为什么从Jenkins连接到Selenium服务器测试不起作用?
What's going on? Why connect to Selenium server from Jenkins test isn't working?
python==2.7.3
Django==1.5
django-jenkins==0.14.0
selenium==2.33.0
更新:如果我正在使用Firefox WebDriver而不是HTMLUNIT,则Firefox将在
UPDATE: If i'm using Firefox WebDriver instead of HTMLUNIT, Firefox opens after line
cls.selenium = WebDriver(desired_capabilities=capabilities, proxy=p)
,但稍后提及例外。
RESOLVED
我只需添加到 setUpClass()
:
import os
. . .
def setUpClass(cls):
os.environ['NO_PROXY'] = '127.0.0.1'
推荐答案
我以这种方式解决了问题(使用了一个 phantom-js 而不是 HTMLUNIT ,因为它是只有剩下的稳定版本的代码)。
I solved the problem this way (used a phantom-js instead of HTMLUNIT, because it's the only remaining stable version of code).
from django.test import LiveServerTestCase
from selenium import webdriver
from os import environ
class SeleniumTestCase(LiveServerTestCase):
__test__ = False
@classmethod
def setUpClass(cls):
environ['NO_PROXY'] = '127.0.0.1' # The key point
cls.selenium = webdriver.PhantomJS(service_args=['--proxy-type=none'])
super(SeleniumTestCase, cls).setUpClass()
@classmethod
def tearDownClass(cls):
cls.selenium.close()
cls.selenium.quit()
super(SeleniumTestCase, cls).tearDownClass()
class TestFoo(SeleniumTestCase):
def setUp(self):
# do something before every test method runs
pass
def test_foo(self):
# test
pass
这篇关于处理到Selenium服务器时,Django Jenkins引发WebDriverException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!