[英]Getting org.apache.http.conn.HttpHostConnectException while accessing a URL from Eclipse
We are using BrowserStack for a project. 我们正在将BrowserStack用于一个项目。
The portal we are testing is whitelisted for our IP. 我们正在测试的门户已被列入我们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? 如何解决这个问题?
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:
但是,您需要注意以下几点:
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
remember to import java.net.URL;
import java.net.URL;
public static void main(String[] args) throws Exception
rather you may consider to be precise by public static void main(String[] args) throws MalformedURLException
public static void main(String[] args) throws Exception
而您可能会考虑通过public static void main(String[] args) throws MalformedURLException
We are using BrowserStack for a project
but you haven't mentioned whether you are using BrowserStack Automation
or BrowserStack Running local tests
. We are using BrowserStack for a project
但没有提到您是使用BrowserStack Automation
还是正在BrowserStack Running local tests
。 BrowserStack Automation
you need to remove caps.setCapability("browserstack.local", "true");
BrowserStack Automation
,则需要删除caps.setCapability("browserstack.local", "true");
from your code. BrowserStack Running local tests
you need to mention caps.setCapability("browserstack.local", "true");
BrowserStack Running local tests
,则需要提及caps.setCapability("browserstack.local", "true");
in your code. Assuming you are using BrowserStack Automation
, here is your own code block along with some simple tweaks which successfully executes on "BrowserStack Automation": 假设您使用的是
BrowserStack Automation
,这是您自己的代码块,以及一些简单的调整,它们可以在“ 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. 让我知道这是否回答了您的问题。
Set your proxy in _JAVA_OPTIONS
under system variables and it will start working. 在
_JAVA_OPTIONS
系统变量下设置代理,它将开始工作。 I faced the same issue and it get resolved by providing proxy for both http and https for _JAVA_OPTIONS
. 我遇到了同样的问题,并且通过为
_JAVA_OPTIONS
提供http和https的代理来解决它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.