且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

org.apache.http.conn.HttpHostConnectException:连接到localhost:19538 [localhost/0:0:0:0:0:0:0:0:1]失败:连接被拒绝(连接被拒绝)

更新时间:2021-10-06 21:46:27

根据错误跟踪日志Maven无法执行目标,如下所示:

As per the error trace logs Maven failed to execute the goal as follows :

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

org.testng.TestNGException的结果如下:

[ERROR] org.testng.TestNGException:
[ERROR] 
[ERROR] An error occurred while instantiating class buyer.testcases.solicitation.CreateSolicitation: null

org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException的结果如下:

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)

这是driver.version:的结果,即您的WebDriver实例未被检测到,如下所示:

Which is the result of driver.version: i.e. your WebDriver instance is not getting detected as follows :

[ERROR] Driver info: driver.version: PCDriver

唯一的原因是根据您的开关(浏览器),您没有通过 System.setProperty()

The only reason for that is as per your switch (browser) you havn't set the System Property through System.setProperty()

一旦您使用 switch (browser) 并定义了 case "firefox" 等等,则需要按以下方式设置System Property:

  • case "firefox":

  • case "firefox":

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
//configuration starts here

  • case "chrome":

  • case "chrome":

    System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
    //configuration starts here
    

  • case "ie":

  • case "ie":

    System.setProperty("webdriver.ie.driver", "C:\\Utility\\BrowserDrivers\\IEDriverServer.exe");
    //configuration starts here
    

  • case "phantomjs":

  • case "phantomjs":

    File path=new File("C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
    System.setProperty("phantomjs.binary.path",path.getAbsolutePath());
    //configuration starts here
    

  • 确保 Linux Box 上的 /etc/hosts 包含以下条目:

  • Ensure that /etc/hosts on your Linux Box contains the following entry :

    127.0.0.1               localhost.localdomain localhost