rodude123
rodude123

Reputation: 300

Selenium python eror Conne

I am trying to run python selenium tests in Jenkins CI. The python test works fine on a local end but not on the server. When I run on the server I get this error

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
Test/UIFrontend/setupBrowser.py:35: in setupDriver
    driver.get("http://localhost:{0}/".format(port))
/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py:333: in get
    self.execute(Command.GET, {'url': url})
/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py:321: in execute
    self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7f1beb4312e8>
response = {'status': 500, 'value': '{"value":{"error":"unknown error","message":"unknown error: net::ERR_CONNECTION_REFUSED\\n  (Session info: headless chrome=87.0.4280.66)","stacktrace":"#0 0x557fbae916a9 \\u003Cunknown>\\n"}}'}

    def check_response(self, response):
...
... 
...
...
        if exception_class == ErrorInResponseException:
            raise exception_class(response, message)
        elif exception_class == UnexpectedAlertPresentException:
            alert_text = None
            if 'data' in value:
                alert_text = value['data'].get('text')
            elif 'alert' in value:
                alert_text = value['alert'].get('text')
            raise exception_class(message, screen, stacktrace, alert_text)
>       raise exception_class(message, screen, stacktrace)
E       selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_CONNECTION_REFUSED
E         (Session info: headless chrome=87.0.4280.66)
"""Set up the webdriver to be used with other selenium tests.
"""
import os
import time

from selenium import webdriver


def setupDriver(options=None):
    """- Set up the webdriver to be used with other selenium tests.
    
    - Test fails if FRONT_PORT environment variable is not defined.

    - Loads Apollo and logs in

    Args:
        options (ChromeOptions, optional): Give custom ChromeOptions rather than using the one provided.

    Returns:
        webdriver: returns driver to be used with tests
    """
    if not options:
        options = webdriver.ChromeOptions()
        options.add_argument('--no-sandbox')
        options.add_argument('--headless') # have to be headless because of 

    if os.environ.get('FRONT_PORT'):
        port = str(os.environ.get('FRONT_PORT'))
    else:
        print("Environment variable FRONT_PORT not defined")
        assert False, "Environment variable FRONT_PORT not defined"

    driver = webdriver.Chrome('chromedriver', options=options)
    driver.set_window_size(1920, 1080)
    print("http://localhost:{0}/".format(port)) 
    driver.get("http://localhost:{0}/".format(port)) #errors out here
    time.sleep(1)
    driver.find_element_by_id("username-input").send_keys("username")
    driver.find_element_by_id("password-input").send_keys("password")
    driver.find_element_by_xpath(
        "/html/body/div/div/section/div/div/" +
        "div/div/form/div[4]/button").click()
    return driver

I have no idea what this means. If you need more info please let me know. Also, the Jenkins CI is run on an external server meaning the tests have to be headless.

Upvotes: 0

Views: 751

Answers (1)

PDHide
PDHide

Reputation: 19979

The error is :

selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_CONNECTION_REFUSED

Meaning chrome couldn't connect to the website. This might be because the server cannot connect to the internet

you can recreate this exception in locat by turning of network and connecting to some website

enter image description here

SO verify whether jenkins CI have acceess to that website you are testing

Upvotes: 1

Related Questions