【问题标题】:Django Jenkins raises WebDriverException when processed to Selenium serverDjango Jenkins 在处理到 Selenium 服务器时引发 WebDriverException
【发布时间】:2013-06-05 17:20:57
【问题描述】:

我通过命令启动 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')

之后一切正常。 但是当我尝试开始 Jenkins 测试时:

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

无法检索请求的 URL

\n\n
\n\n\n

在尝试检索网址: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 日星期一 04:36:42 GMT 生成

\n\n\n'

发生了什么事?为什么从 Jenkins 测试连接到 Selenium 服务器不起作用?

python==2.7.3
Django==1.5
django-jenkins==0.14.0
selenium==2.33.0

更新:如果我使用 Firefox WebDriver 而不是 HTMLUNIT,Firefox 在行后打开

cls.selenium = WebDriver(desired_capabilities=capabilities, proxy=p)

,但稍后会引发上述异常。

已解决 我只是添加到setUpClass() 方法:

import os
. . .
    def setUpClass(cls):
        os.environ['NO_PROXY'] = '127.0.0.1'

【问题讨论】:

  • 只是一种可能...您有系统管理员权限吗?
  • @zen11625 你可以发布你的方式作为答案。这个问题没有更多的答案。谢谢

标签: python django selenium jenkins selenium-webdriver


【解决方案1】:

我以这种方式解决了问题(使用 phantom-js 而不是 HTMLUNIT,因为它是唯一剩下的稳定版本的代码)。

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

【讨论】:

    猜你喜欢
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-22
    • 2017-01-24
    • 1970-01-01
    相关资源
    最近更新 更多