3
votes

The script from https://www.browserstack.com/automate/python

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

desired_cap = {
    'browser': 'Chrome',
    'browser_version': '62.0',
    'os': 'Windows',
    'os_version': '10',
    'resolution': '1024x768',
    'name': 'Bstack-[Python] Sample Test'
}

driver = webdriver.Remote(
    command_executor='http://servinc1:[email protected]:80/wd/hub',
    desired_capabilities=desired_cap)

driver.get("http://www.google.com")
if not "Google" in driver.title:
    raise Exception("Unable to load google page!")
elem = driver.find_element_by_name("q")
elem.send_keys("BrowserStack")
elem.submit()
print driver.title
driver.quit()

failed with

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='hub.browserstack.com', port=80): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))

on a system with a localhost HTTP proxy. The proxy is configured with the {http,https}_proxy environment variables: using requests works:

import requests
r = requests.get('https://api.github.com/events')

and allowing connections to hub.browserstack.com also works.

The aim is to use BrowserStack with a local proxy. How is this fixed?

2

2 Answers

1
votes

So for now the workaround seems to be the answer: allow all connections to hub.browserstack.com to pass the firewall. E.g.

iptables -I OUTPUT 1 -p tcp --dport 443 -d hub.browserstack.com  -j ACCEPT
0
votes

Since your use-case involves sending traffic to the BrowserStack Hub using proxy, you will need to specify the proxy details in your code snippet as below-

//Set the appropriate proxy environment variable (HTTP_PROXY if it is a HTTP proxy, HTTPS_PROXY if it is a HTTPS proxy, etc.) before running the tests.
//You can set this as follows:

export HTTP_PROXY='http://<proxyhost>:<proxyport>'

You can read more on this here- https://www.browserstack.com/automate/python#proxy