0

We are using BrowserStack for a project.

The portal we are testing is whitelisted for our IP.

And we access internet behind proxy.

While running below code snippet:

public class DemoClass {

public static final String USERNAME = "<Username>";
public static final String AUTOMATE_KEY = "<Key>";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY 
+ "@hub-cloud.browserstack.com/wd/hub";

public static void main(String[] args) throws Exception {
 String baseUrl;
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browser", "IE");
caps.setCapability("browser_version", "7.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "XP");
caps.setCapability("browserstack.debug", "true");
caps.setCapability("browserstack.local", "true");
System.getProperties().put("http.proxyHost", "<Proxy URL>");
System.getProperties().put("http.proxyPort", "<Proxy Port>");
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
....

We are getting below error:

Exception in thread "main" 
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a 
new session. Possible causes are invalid address of the remote server or 
browser start-up failure.
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: '<HOSTNAME>', ip: '<HOST IP>', os.name: 'Windows 
7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver
at 
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:174)
at demopackage.DemoClass.main(DemoClass.java:31)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to hub-
cloud.browserstack.com:443 [hub-cloud.browserstack.com/5.255.92.202] failed: 
Connection refused: connect
.........

How to resolve this issue?

  • Can you please consider updating me the Selenium version you are using? Thanks – undetected Selenium May 26 '17 at 12:17
  • It looks like the proxy details you mentioned did not help. I noticed you have specified the Hub URL as HTTPS. Have you tried switching to HTTP and check if it works? Lastly, you can also try doing a cURL to the Hub URL as follows: curl -x: -L https://hub.browserstack.com/wd/hub/status. Try both HTTP and HTTPS. This will help confirm if you are able to connect to BrowserStack's Selenium Hub. – Mukesh Tiwari May 26 '17 at 12:54

2 Answers2

0

Here is the Answer to your Question:

I din't find any significant issue in your code block as such. But here are a few points you need to take care:

  1. When you do WebDriver driver = new RemoteWebDriver(new URL(URL), caps); remember to import java.net.URL;
  2. I have observed you handling the base exception as public static void main(String[] args) throws Exception rather you may consider to be precise by public static void main(String[] args) throws MalformedURLException
  3. You mentioned We are using BrowserStack for a project but you haven't mentioned whether you are using BrowserStack Automation or BrowserStack Running local tests.
  4. Assuming you are using BrowserStack Automation you need to remove caps.setCapability("browserstack.local", "true"); from your code.
  5. Incase you are using BrowserStack Running local tests you need to mention caps.setCapability("browserstack.local", "true"); in your code.
  6. Assuming you are using BrowserStack Automation, here is your own code block along with some simple tweaks which successfully executes on "BrowserStack Automation":

    package SeleniumGrid;
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    
    import java.net.MalformedURLException;
    import java.net.URL;
    
    public class Q44196893_IE_BrowserStack {
    
    public static final String USERNAME = "<Username>";
    public static final String AUTOMATE_KEY = "<Key>";
    public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
    
    
    public static void main(String[] args) throws MalformedURLException {
    
    
         String baseUrl;
         DesiredCapabilities caps = new DesiredCapabilities();
         caps.setCapability("browser", "IE");
         caps.setCapability("browser_version", "7.0");
         caps.setCapability("os", "Windows");
         caps.setCapability("os_version", "XP");
         caps.setCapability("browserstack.debug", "true");
         System.getProperties().put("http.proxyHost", "<Proxy URL>");
         System.getProperties().put("http.proxyPort", "<Proxy Port>");
         WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
         driver.get("http://google.com/");
         System.out.println("Title is : "+driver.getTitle());
         driver.quit();
    
    }
    
    }
    

Let me know if this Answers your Question.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Set your proxy in _JAVA_OPTIONS under system variables and it will start working. I faced the same issue and it get resolved by providing proxy for both http and https for _JAVA_OPTIONS.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135