Django Jenkins raises WebDriverException when processed to Selenium server

I start Selenium server hub by command

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

and Selenium server node by command

  • How to track Django model changes with git?
  • Django media files under GIT
  • Maintaining 3rd Party Django Apps as Git submodules
  • installing django-templated-email
  • Error Killed: 9 after command “git add .”
  • How to preserve the file permission in git?
  • java -jar selenium-server-standalone-2.33.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=htmlunit
    

    Then i’m trying to execute code:

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

    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: Message: u’\n\n\nERROR: The requested URL could not be retrieved\n\n\n\n

    ERROR

    \n

    The requested URL could not be retrieved

    \n\n


    \n\n\n

    The following error was encountered while trying to retrieve the URL: a href=”http://localhost:4444/wd/hub/session” localhost:4444/wd/hub/session ap\n\n\n

    Connection to 127.0.0.1 failed.

    \n

    \n\nThe system returned: (111) Connection refused

    \n\n

    The remote host or network may be down. Please try the request again.

    \n\n

    Your cache administrator is webmaster.

    \n\n
    \n\n\n


    \n\n

    Generated Mon, 10 Jun 2013 04:36:42 GMT by localhost (squid/3.1.6)

    \n\n\n’

    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
    

    UPDATE: If i’m using Firefox WebDriver instead of HTMLUNIT, Firefox opens after line

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

    , but later raises above-described exception.

    RESOLVED
    I simply add to setUpClass() method:

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

  • How do I programmatically simulate resolving a merge conflict with GitPython?
  • git concurrency errors when running multiple jenkins jobs accessing/committing the same repo
  • Promote all builds to master on Jenkins
  • Cloning a private repo using HTTPS with gitpython
  • Renaming job in jenkins/hudson
  • How can I use just created build in downstream job
  • One Solution collect form web for “Django Jenkins raises WebDriverException when processed to Selenium server”

    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
    
    Git Baby is a git and github fan, let's start git clone.