为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

胡说叔叔 2021-03-22 14:19:52
我通过命令启动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 webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesserver =  'http://localhost:4444/wd/hub'dc = DesiredCapabilities.HTMLUNITbrowser = webdriver.Remote(server, dc)browser.get('http://localhost:8000')之后一切都还好。但是,当我尝试开始进行詹金斯测试时:from django.test import TestCase, LiveServerTestCasefrom selenium.webdriver.common import proxyfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesfrom selenium.webdriver.remote.webdriver import WebDriverclass 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.3Django==1.5django-jenkins==0.14.0selenium==2.33.0
查看完整描述

1 回答

?
MMMHUHU

TA贡献1834条经验 获得超8个赞

我以这种方式解决了问题(使用了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


查看完整回答
反对 回复 2021-03-31
  • 1 回答
  • 0 关注
  • 150 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号