-1

I am trying to run a selenium script to automate in browser stack mentioned here

http://seleniumworks.blogspot.in/2013/10/run-selenium-scripts-on-cloud.html

When I run this script in eclipse I am getting below error.

    [TestNG] Running:
  C:\Users\pramod.kg\AppData\Local\Temp\testng-eclipse--1068635842\testng-customsuite.xml

FAILED CONFIGURATION: @BeforeClass setUp
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: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10'
System info: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
    at bro.setUp(bro.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to hub.browserstack.com:80 [hub.browserstack.com/5.255.93.10] failed: Connection timed out: connect
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:143)
    at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:89)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:134)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
    ... 28 more
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
    ... 41 more

SKIPPED CONFIGURATION: @AfterClass tearDown
SKIPPED: testSimple

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================

[TestNG] Time taken by org.testng.reporters.jq.Main@40ee1aeb: 163 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@4ca6c0c9: 807 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@1decb654: 72 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 10 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@4158c7fa: 12 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@74bcc82f: 18 ms

I am running this script behind a proxy. Is that why I am getting this issue .I have confirmed access key and username are given correct but still not able to run successfully.

code:

import org.testng.annotations.Test;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.Assert;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class bro{

  public static final String USERNAME = "xxx";
  public static final String ACCESS_KEY = "xxx";
  public static final String URL = "http://" + USERNAME + ":" + ACCESS_KEY + "@xx.yy.com/wd/hub";

  private WebDriver driver;  

  @BeforeClass
  public void setUp() throws Exception {
 DesiredCapabilities caps = new DesiredCapabilities();
 caps.setCapability("browser", "Firefox");
 caps.setCapability("browser_version", "23.0");
 caps.setCapability("os", "Windows");
 caps.setCapability("os_version", "XP"); 
        caps.setCapability("browserstack.debug", "true"); //This enable Visual Logs
        driver = new RemoteWebDriver(new URL(URL), caps);
  }  

  @Test
  public void testSimple() throws Exception {
    driver.get("http://www.google.com");
    System.out.println("Page title is: " + driver.getTitle());
    Assert.assertEquals("Google", driver.getTitle());
    WebElement element = driver.findElement(By.name("q"));
    element.sendKeys("seleniumworks");
    element.submit();    
  }

  @AfterClass  
  public void tearDown() throws Exception {  
    driver.quit();  
  }  

}
Ahmed Ashour
  • 4,209
  • 10
  • 29
  • 46
Pramod
  • 2,241
  • 2
  • 17
  • 25
  • Can you post some more code of how you initialize the webdriver/webbrowser? – spcial Sep 21 '15 at 11:03
  • @spcial iI have added the code.pls check – Pramod Sep 21 '15 at 11:15
  • @spcial I want to runb the script in remote browser given by browserstack. so i think i cannot set the path as you said – Pramod Sep 21 '15 at 12:16
  • Yes you are totaly right, so I deleted my "answer". I actually haven't used browserstack myself. But I think you are right and this is a proxy setting failure because of the `HttpHostConnectException`.. I'm also sitting behind a proxy and can't ping hub.browserstack.com.. but doing a ping from my vserver which is not behind a proxy works fine. You can open the console and try "ping hub.browserstack.com".. if you don't get a ping back I think the chances are high that the proxy blocks it :) – spcial Sep 21 '15 at 12:26
  • @spcial I have ping from cmd and got request time out.So i think it is a proxy issue – Pramod Sep 21 '15 at 12:39
  • @spcial issue was solved it was do to proxy – Pramod Sep 22 '15 at 09:15
  • I don't get any error while doing ping to browserstack still getting issue of unreachable browser. P.S: I am using trial version of browserstack and I hope that won't create any such issue. – mashkurm Jul 12 '17 at 07:12

1 Answers1

0

The issue was due to running the script behind a proxy. I was getting this error since I was blocked to access to the URL hub.browserstack.com.

Ahmed Ashour
  • 4,209
  • 10
  • 29
  • 46
Pramod
  • 2,241
  • 2
  • 17
  • 25
  • How did you solve this please? When I try to access mentioned URL, I am getting _{"value":{"message":"Invalid Command"}}_ response – mashkurm Jul 12 '17 at 05:39