3

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:key@hub.browserstack.com: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?

serv-inc
  • 29,557
  • 9
  • 128
  • 146

2 Answers2

1

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
serv-inc
  • 29,557
  • 9
  • 128
  • 146
  • I am facing similar issue while connecting to sauce labs from windows, it would be of great help if you could suggest how to fix this for windows PC – Rohit May 22 '20 at 06:51
  • If you have a similar problem @Rohit, the solution depends on your firewall and proxy configuration. – serv-inc May 26 '20 at 09:14
0

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

Ozone17
  • 118
  • 5
  • I was not clear enough: the `http_proxy` variable is already set. What should be done if setting the environment variable does not help? Are there any next steps? – serv-inc May 27 '19 at 06:35