Django Jenkins处理到Selenium服务器时引发WebDriverException

我通过命令启动Selenium服务器中心


java -jar selenium-server-standalone-2.33.0.jar -role hub

和Selenium服务器节点通过命令


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')

之后一切都还好。但是,当我尝试开始进行詹金斯测试时:


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')

我收到以下错误,包含在追溯中:


WebDriverException:消息:u'\ n \ n \ n错误:无法检索到所请求的URL \ n \ n \ n \ n


错误

\ n

所请求的网址无法检索

\ n \ n

\ n \ n \ n

尝试检索URL时遇到以下错误:a href =“ http:// localhost:4444 / wd / hub / session” localhost:4444 / wd / hub / session ap \ n \ n \ n


与127.0.0.1的连接失败。


\ n

\ n \ n系统返回:(111)连接被拒绝

\ n \ n

远程主机或网络可能已关闭。请重试该请求。


\ n \ n

您的缓存管理员是网站管理员。


\ n \ n

\ n \ n \ n

\ n \ n

由localhost(squid / 3.1.6)于2013年6月10日星期一格林尼治标准时间生成


\ n \ n \ n'

这是怎么回事?为什么从Jenkins测试连接到Selenium服务器无法正常工作?


python==2.7.3

Django==1.5

django-jenkins==0.14.0

selenium==2.33.0


胡说叔叔
浏览 151回答 1
1回答

MMMHUHU

我以这种方式解决了问题(使用了phantom-js而不是HTMLUNIT,因为它是唯一剩余的稳定版本的代码)。from django.test import LiveServerTestCasefrom selenium import webdriverfrom os import environclass 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
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python