从Eclipse

时间:2017-05-26 08:23:42

标签: java eclipse apache selenium browserstack

我们正在将BrowserStack用于项目。

我们正在测试的门户网站已列入我们的IP列表。

我们在代理服务器上访问互联网。

在代码段下面运行时:

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);
....

我们收到以下错误:

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
.........

如何解决此问题?

2 个答案:

答案 0 :(得分:0)

以下是您的问题的答案:

我发现代码块中没有任何重大问题。但是,您需要注意以下几点:

  1. 当您WebDriver driver = new RemoteWebDriver(new URL(URL), caps);时,请记得import java.net.URL;
  2. 我观察到您将基本异常处理为public static void main(String[] args) throws Exception,而您可能会认为public static void main(String[] args) throws MalformedURLException
  3. 是精确的
  4. 您提到了We are using BrowserStack for a project,但您尚未提及是否使用BrowserStack AutomationBrowserStack Running local tests
  5. 假设您使用的是BrowserStack Automation,则需要从代码中删除caps.setCapability("browserstack.local", "true");
  6. 如果您使用BrowserStack Running local tests,则需要在代码中提及caps.setCapability("browserstack.local", "true");
  7. 假设您正在使用BrowserStack Automation,这里有您自己的代码块以及一些在&#34; BrowserStack Automation&#34;上成功执行的简单调整:

    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();
    
    }
    
    }
    
  8. 如果这回答你的问题,请告诉我。

答案 1 :(得分:0)

在系统变量下的ngx-bootstap中设置代理,它将开始工作。我遇到了同样的问题,它通过为_JAVA_OPTIONS的http和https提供代理来解决。