title: org.apache.http.conn.HttpHostConnectException: Connect to localhost:19538 [localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)
body: <p>I have a linux box on which jenkins server runs and pulls the scripts from git and start executing</p>
  
  <p>I have a windows pc from which i open the jenkins url say xyz:8080 and try to execute the scripts from my windows box but it gives below error.</p>
  
  <p>same happens when is run using phantomjs.</p>
  
  <p>I am trying to run this in firefox as of now</p>
  
  <pre><code>  -------------------------------------------------------
   T E S T S
  -------------------------------------------------------
  Running TestSuite
  1516800459520   geckodriver INFO    geckodriver 0.19.1
  1516800459526   geckodriver INFO    Listening on 127.0.0.1:15327
  log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
  log4j:WARN Please initialize the log4j system properly.
  log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  
  Results :
  
  Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
  
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 32.526 s
  [INFO] Finished at: 2018-01-24T08:28:00-05:00
  [INFO] Final Memory: 28M/241M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project com.perfect.wp: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process
  [ERROR] org.testng.TestNGException:
  [ERROR] 
  [ERROR] An error occurred while instantiating class buyer.testcases.solicitation.CreateSolicitation: null
  [ERROR] at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:422)
  [ERROR] at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:323)
  [ERROR] at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:126)
  [ERROR] at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:191)
  [ERROR] at org.testng.TestClass.getInstances(TestClass.java:99)
  [ERROR] at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:85)
  [ERROR] at org.testng.TestClass.init(TestClass.java:77)
  [ERROR] at org.testng.TestClass.&lt;init&gt;(TestClass.java:42)
  [ERROR] at org.testng.TestRunner.initMethods(TestRunner.java:423)
  [ERROR] at org.testng.TestRunner.init(TestRunner.java:250)
  [ERROR] at org.testng.TestRunner.init(TestRunner.java:220)
  [ERROR] at org.testng.TestRunner.&lt;init&gt;(TestRunner.java:161)
  [ERROR] at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:578)
  [ERROR] at org.testng.SuiteRunner.init(SuiteRunner.java:185)
  [ERROR] at org.testng.SuiteRunner.&lt;init&gt;(SuiteRunner.java:131)
  [ERROR] at org.testng.TestNG.createSuiteRunner(TestNG.java:1383)
  [ERROR] at org.testng.TestNG.createSuiteRunners(TestNG.java:1363)
  [ERROR] at org.testng.TestNG.runSuitesLocally(TestNG.java:1217)
  [ERROR] at org.testng.TestNG.runSuites(TestNG.java:1144)
  [ERROR] at org.testng.TestNG.run(TestNG.java:1115)
  [ERROR] at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:281)
  [ERROR] at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
  [ERROR] at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:121)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
  [ERROR] Caused by: java.lang.ExceptionInInitializerError
  [ERROR] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  [ERROR] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  [ERROR] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  [ERROR] at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  [ERROR] at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:23)
  [ERROR] at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:410)
  [ERROR] ... 25 more
  [ERROR] Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:15327 [localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)
  [ERROR] Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T18:33:54.468Z'
  [ERROR] System info: host: 'phfqwptestauto', ip: '10.5.1.175', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-504.30.3.el6.x86_64', java.version: '1.8.0_152'
  [ERROR] Driver info: driver.version: PCDriver
  [ERROR] at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
  [ERROR] at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
  [ERROR] at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
  [ERROR] at org.openqa.selenium.remote.RemoteWebDriver.&lt;init&gt;(RemoteWebDriver.java:142)
  [ERROR] at org.openqa.selenium.firefox.FirefoxDriver.&lt;init&gt;(FirefoxDriver.java:120)
  [ERROR] at commonutils.pageobjects.utils.PCDriver.invokeBrowser(PCDriver.java:71)
  [ERROR] at commonutils.pageobjects.utils.PCDriver.&lt;clinit&gt;(PCDriver.java:52)
  [ERROR] ... 31 more
  [ERROR] Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:15327 [localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)
  [ERROR] at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
  [ERROR] at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
  [ERROR] at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
  [ERROR] at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
  [ERROR] at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
  [ERROR] at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
  [ERROR] at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
  [ERROR] at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
  [ERROR] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
  [ERROR] at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
  [ERROR] at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:138)
  [ERROR] at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:86)
  [ERROR] at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:101)
  [ERROR] at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
  [ERROR] at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
  [ERROR] at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
  [ERROR] ... 37 more
  [ERROR] Caused by: java.net.ConnectException: Connection refused (Connection refused)
  [ERROR] at java.net.PlainSocketImpl.socketConnect(Native Method)
  [ERROR] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
  [ERROR] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
  [ERROR] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
  [ERROR] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
  [ERROR] at java.net.Socket.connect(Socket.java:589)
  [ERROR] at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
  [ERROR] at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
  [ERROR] ... 52 more
  [ERROR] -&gt; [Help 1]
  [ERROR] 
  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR] 
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
  Build step 'Execute shell' marked build as failure
  Sending e-mails to: wp.qa@perfect.com
  Finished: FAILURE
  </code></pre>
  
  <p>PCDriver Class :</p>
  
  <pre><code>public class PCDriver implements WebDriver {
  
      public static WebDriver driver;
      // static log4jClass log = new log4jClass();
  
      static {
          PCDriver.invokeBrowser(ReadConfig.getInstance().getBrowser());
  
      }
  
      public static synchronized WebDriver invokeBrowser(String browser) {
  
          switch (browser) {
  
          case "firefox":
              File pathBinary = new File("//home//chiefs//firefox//firefox");
              FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);   
              //DesiredCapabilities desired = DesiredCapabilities.firefox();
              DesiredCapabilities cap = new DesiredCapabilities();
  
              FirefoxOptions options = new FirefoxOptions();
              cap.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
              cap.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
              System.setProperty("webdriver.gecko.driver",
                      ReadConfig.getInstance().getDriverPath().toString() + "geckodriver");
              driver = new FirefoxDriver(options);
              driver.get(ReadConfig.getInstance().getApplicationUrl());
              // log.info("Browser Invoked");
              break;
  
          case "htmlunit":
              DesiredCapabilities capHtml = DesiredCapabilities.htmlUnit();
              capHtml.acceptInsecureCerts();
              capHtml.setJavascriptEnabled(true);
              /*
               * System.setProperty("webdriver.gecko.driver",
               * ReadConfig.getInstance().getDriverPath().toString() + "geckodriver.exe");
               */
              driver = new HtmlUnitDriver(capHtml);
              driver.get(ReadConfig.getInstance().getApplicationUrl());
              // log.info("Browser Invoked");
              break;
  
          case "chrome":
              DesiredCapabilities capChrome = DesiredCapabilities.chrome();
              ChromeOptions chromeOptions = new ChromeOptions();
              chromeOptions.addArguments("headless");
              capChrome.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
              capChrome.setJavascriptEnabled(true);
              capChrome.acceptInsecureCerts();
              System.setProperty("webdriver.chrome.driver",
                      ReadConfig.getInstance().getDriverPath().toString() + "chromedriver.exe");
              driver = new ChromeDriver(capChrome);
              driver.get(ReadConfig.getInstance().getApplicationUrl());
              driver.manage().window().setSize(new Dimension(1440, 900));
              break;
  
          case "ie":
              DesiredCapabilities capIE = new DesiredCapabilities();
              capIE.setPlatform(Platform.WINDOWS);
              capIE.acceptInsecureCerts();
              capIE.setJavascriptEnabled(true);
              capIE.setCapability("ignoreZoomSetting", true);
              capIE.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
  
              capIE.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, false);
              System.setProperty("webdriver.ie.driver",
                      ReadConfig.getInstance().getDriverPath().toString() + "IEDriverServer.exe");
              driver = new InternetExplorerDriver(capIE);
              driver.get(ReadConfig.getInstance().getApplicationUrl());
  
              /*
               * case "edge": DesiredCapabilities capEdge = DesiredCapabilities.edge();
               * capEdge.setPlatform(Platform.WIN10); capEdge.acceptInsecureCerts();
               * capEdge.setJavascriptEnabled(true); EdgeOptions options = new EdgeOptions();
               * options.setPageLoadStrategy("eager");
               * System.setProperty("webdriver.edge.driver",
               * ReadConfig.getInstance().getDriverPath().toString() +
               * "MicrosoftWebDriver.exe"); driver = new EdgeDriver(options);
               */
  
  
                case "phantomjs": 
                   DesiredCapabilities capPhantom =new DesiredCapabilities(); 
                   ArrayList&lt;String&gt; cliArgsCap = new ArrayList&lt;String&gt;(); 
                   cliArgsCap.add("--web-security=false");
                   cliArgsCap.add("--proxy=10.5.1.175:1024");
  
                cliArgsCap.add("--ssl-protocol=any");
                cliArgsCap.add("--ignore-ssl-errors=true");
                cliArgsCap.add("--webdriver-loglevel=NONE");
                cliArgsCap.add("--load-images=true"); //
                capPhantom.setBrowserName("PhantomJs");
                capPhantom.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
               // capPhantom.setCapability("trustAllSSLCertificates", true);
                            capPhantom.setCapability("screen-resolution", "1280x1024");
  
                capPhantom.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,cliArgsCap);
                  capPhantom.setPlatform(Platform.LINUX);
                capPhantom.setCapability("proxy", "10.5.1.175:1024");
  
                capPhantom.setJavascriptEnabled(true);
                capPhantom.setCapability("takesScreenshot", true);
                capPhantom.setCapability("phantomjs.binary.path",ReadConfig.getInstance().getDriverPath().toString() + "phantomjs");
                driver = new PhantomJSDriver(capPhantom);
    driver.manage().timeouts()
                  .pageLoadTimeout(60, TimeUnit.SECONDS)
                  .implicitlyWait(60, TimeUnit.SECONDS);
                  driver.manage().window().maximize();
                driver.get(ReadConfig.getInstance().getApplicationUrl());
  
          }
  
          return driver;
      }
  
      public void close() {
          driver.close();
  
      }
  
      public static WebDriver getDriver() {
          return driver;
      }
  
      public static void acceptAlert() {
          WebDriverWait wait = new WebDriverWait(driver, 20);
          wait.until(ExpectedConditions.alertIsPresent());
          driver.switchTo().alert().accept();
      }
  
      public static void dismissAlert() {
          WebDriverWait wait = new WebDriverWait(driver, 20);
          wait.until(ExpectedConditions.alertIsPresent());
          driver.switchTo().alert().dismiss();
      }
  
      public static void waitForPageLoad() {
          ExpectedCondition&lt;Boolean&gt; pageLoadCondition = new ExpectedCondition&lt;Boolean&gt;() {
              public Boolean apply(WebDriver driver) {
                  return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
              }
          };
          WebDriverWait wait = new WebDriverWait(driver, 30);
          wait.until(pageLoadCondition);
      }
  </code></pre>
  
  <p>Pom.xml</p>
  
  <pre><code>project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.perfect&lt;/groupId&gt;
      &lt;artifactId&gt;com.perfect.wp&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;build&gt;
          &lt;sourceDirectory&gt;webprocure&lt;/sourceDirectory&gt;
          &lt;pluginManagement&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                      &lt;version&gt;3.7.0&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;source&gt;1.7&lt;/source&gt;
                          &lt;target&gt;1.7&lt;/target&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
  
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.19.1&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;useSystemClassLoader&gt;false&lt;/useSystemClassLoader&gt;
  
                          &lt;suiteXmlFiles&gt;
                              &lt;suiteXmlFile&gt;testng.xml&lt;/suiteXmlFile&gt;
                          &lt;/suiteXmlFiles&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
  
              &lt;/plugins&gt;
          &lt;/pluginManagement&gt;
  
      &lt;/build&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;com.perfect.wp&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
              &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
              &lt;version&gt;3.8.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
              &lt;artifactId&gt;selenium-htmlunit-driver&lt;/artifactId&gt;
              &lt;version&gt;2.52.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.relevantcodes&lt;/groupId&gt;
              &lt;artifactId&gt;extentreports&lt;/artifactId&gt;
              &lt;version&gt;2.41.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.testng&lt;/groupId&gt;
              &lt;artifactId&gt;testng&lt;/artifactId&gt;
              &lt;version&gt;6.11&lt;/version&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
              &lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
              &lt;version&gt;3.17&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.17&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.codeborne&lt;/groupId&gt;
              &lt;artifactId&gt;phantomjsdriver&lt;/artifactId&gt;
              &lt;version&gt;1.4.4&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Jenkins Maven Configuration Screenshot links:</p>
  
  <p><a href="http://prntscr.com/i4wn8h" rel="nofollow noreferrer">http://prntscr.com/i4wn8h</a>
  <a href="http://prntscr.com/i4wnj4" rel="nofollow noreferrer">http://prntscr.com/i4wnj4</a></p>