Encountering a org.apache.http.conn.HttpHostConnectException error when trying to access a URL through the Eclipse

For our current project, we have integrated BrowserStack into our testing process.

The portal we are testing has been whitelisted for our IP address.

We are also accessing the internet behind a proxy.

However, when running the following 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 encounter the following 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
.........

What is the solution to this problem?

Answer №1

Below is the Response to your Inquiry:

After reviewing your code block, I did not identify any major issues. However, here are some key points that you should consider:

  1. Ensure that you import java.net.URL; when using
    WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
  2. Instead of handling the base exception as
    public static void main(String[] args) throws Exception
    , it may be more precise to use
    public static void main(String[] args) throws MalformedURLException
  3. You mentioned utilizing BrowserStack for a project, but it is important to specify whether you are using BrowserStack Automation or BrowserStack Running local tests.
  4. If you are using BrowserStack Automation, make sure to remove
    caps.setCapability("browserstack.local", "true");
    from your code.
  5. For BrowserStack Running local tests, include
    caps.setCapability("browserstack.local", "true");
    in your code.
  6. Assuming you are working with BrowserStack Automation, below is your modified code block which should effectively run 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();
    
    }
    
    }
    

Feel free to reach out if this addresses your concerns.

Answer №2

To solve the problem, simply configure your proxy settings within the system variables under the _JAVA_OPTIONS parameter. I encountered a similar issue and managed to resolve it by specifying proxies for both http and https in the _JAVA_OPTIONS environment variable.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Running a selenium test with a stand-alone connection to chrome.exe

After encountering issues with Chrome 44, as discussed in this Stack Overflow thread, I followed RobW's suggestion to use a standalone chrome.exe with the required version. However, I am now unsure of how to integrate it with my Selenium and Java test ...

Using Selenium Webdriver with Python for navigating through classified ads on leboncoin, encountering difficulty in selecting a dropdown list and input box

Continuing my journey on the Python/Selenium learning curve. Selenium Webdriver - Python - leboncoin - Issue with selecting a button containing an accent After successfully logging in to the site and selecting the button, I aim to populate the fields for ...

Selenium works well with transactionless database cleaning in Rails/RSpec/Capybara, but Webkit does not support it

After configuring my RSpec environment to use a truncation cleaning strategy for Capybara tests, I encountered an issue with Webkit as the Javascript driver. Surprisingly, when using Selenium, everything works smoothly. The relevant RSpec configuration wi ...

How to use @FindBy annotation to close a notification alert in Selenium?

Sample Can someone assist me with adding an annotation to dismiss this notification? ...

Decompressing JSON data type document

I am currently facing an issue with deserializing a Json string to a custom class. Here is the structure of my json data: externDossierNr:"foo10" internDossierNr:"2016010" rapport:File testarray:Array[3] testword:42 __proto__:Object The fields externDoss ...

"Implementing setters with the AutoValue extension in gson: A step-by-step guide

Recently, I discovered the potential of using the AutoValues (GSON) extension to significantly accelerate our json data parsing process. To my surprise, it resulted in parsing our json twice as quickly. However, there's a dilemma I'm facing - wh ...

Using Python and Selenium to interact with dropdown menus in the browser

Being new to this, I've reviewed some of the examples provided here but despite their simplicity, I'm still struggling to make it work. The website I am trying to navigate is: www.webauto.de Below is my code for selecting a car make, model, and ...

Acquiring specific strings from an element retrieved by Selenium using Python

My project involves using selenium in python to scrape a website and extract elements with specific classes 'left' and 'right'. The selenium method returns an object that, when printed iteratively, displays a series of text. left = dri ...

Consistently encountering the message 'Error: timeout of 2000ms exceeded' while using Selenium

Good morning, Currently, I am in the process of learning how to use Selenium with JavaScript (specifically using Mocha). I have created a very basic test that is causing some issues during runtime. Whenever I run the test, a new instance of Chrome opens a ...

Python (Selenium) - Guide on extracting and storing data from multiple pages into a single CSV file

I am facing a challenge with scraping data from a web page that contains a table spanning multiple pages. I am using Python with selenium for this task. The website in question is: The issue I am encountering is related to navigating through the pages of ...

Selenium script encountered a error while boot layer was being initialized

Just starting with selenium and trying to execute my first test case in eclipse, but encountering some errors along the way. Error popped up during initialization of boot layer java.lang.module.FindException: Unable to infer module descriptor for C:& ...

Using selenium can be time-consuming especially when it is unable to locate the elements

My algorithm uses chromedriver to scan numerous web pages and locate a specific element using "find_elements_by_xpath" on each page. Lines = driver.find_elements_by_xpath( '//*[@id="top"]/div[contains(@style, "display: block;")]/& ...

NUnit's Keyword Driven framework organization

Currently, I am working on creating a simple keyword-driven framework in NUnit with Selenium. However, I am facing an issue in determining how to structure the framework as NUnit executes every method marked with the [Test] attribute. For instance: Core b ...

Verify if the value is larger or smaller in WireMock

I am currently in a scenario where I must verify the amount and generate an appropriate response based on its value. If the amount is greater than or equal to 100, then a specific response should be returned. For amounts less than 100, an error response n ...

Failed to find the element using Selenium

Can anyone help me find the username input section on the following website: ? I've included the code snippet I used below: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import ...

Issue encountered with the maven-surefire-plugin version 2.19.1 during testing in project ABC: Provider exception with java/sql/Date: java.sql.Date

Issue 1 - org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project XYZ: Exception in provider: java/sql/Date: java.sql.Date Problem 2 - 4144777 [pool-1-thread-1 for channel id=9] DEBUG freemarker.cache - Couldn't find tem ...

Having difficulty retrieving the values from the 'App.config' file within the Unit testing project using Nunit

In my 'nunit' project created in Visual Studio, I have a simple test but no default 'App.config' file. Therefore, I manually created an 'App.config' file and marked it 'Copy always' from the properties option. When ...

Searching for an element in Python using Selenium can be done by using different methods such as finding

Having trouble retrieving the specific element below. I've attempted multiple methods including by class and CSS selector. <a href="http://www.google.ca" target="_blank" class="btn visit__link"> "Visit this Webpage" <br> "for more content ...

Guidelines for extracting specific text data from a label element with Selenium and Python

I am working on iterating through a variety of checkboxes in order to verify their presence within a given list, and then click on them if they match the criteria. Here is an example of the HTML element that I have managed to extract: <label> < ...

Tips for bypassing captcha and avoiding Selenium detection

I wrote a Python script that logs into a specific page (sso.acesso.gov.br) using certain credentials and then typically solves a captcha using the 2Captcha API. However, recently I have been encountering an error after solving the captcha, even when I do ...