gpt4 book ai didi

maven - org.apache.http.conn.HttpHostConnectException : Connect to localhost:19538 [localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)

转载 作者:行者123 更新时间:2023-12-05 07:37:41 25 4
gpt4 key购买 nike

我有一个 linux box,jenkins 服务器在上面运行并从 git 中拉取脚本并开始执行

我有一台 Windows 电脑,我从它打开 jenkins url 说 xyz:8080 并尝试从我的 Windows 框中执行脚本,但它给出了以下错误。

使用 phantomjs 运行时也会发生同样的情况。

我现在正尝试在 firefox 中运行它

  -------------------------------------------------------
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.<init>(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.<init>(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.<init>(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.<init>(RemoteWebDriver.java:142)
[ERROR] at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
[ERROR] at commonutils.pageobjects.utils.PCDriver.invokeBrowser(PCDriver.java:71)
[ERROR] at commonutils.pageobjects.utils.PCDriver.<clinit>(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] -> [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

PC驱动类:

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<String> cliArgsCap = new ArrayList<String>();
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<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
}
};
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(pageLoadCondition);
}

Pom.xml

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">
<modelVersion>4.0.0</modelVersion>

<groupId>com.perfect</groupId>
<artifactId>com.perfect.wp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>webprocure</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>

<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

</plugins>
</pluginManagement>

</build>
<packaging>jar</packaging>

<name>com.perfect.wp</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
</dependency>

<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.4.4</version>
</dependency>
</dependencies>
</project>

Jenkins Maven 配置截图链接:

http://prntscr.com/i4wn8h http://prntscr.com/i4wnj4

最佳答案

根据错误跟踪日志 Maven 未能执行如下目标:

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 实例未被检测到,如下所示:

[ERROR] Driver info: driver.version: PCDriver

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

解决方案:

一旦您使用switch (browser) 并定义case "firefox" 等您需要如下设置系统属性:

  • 案例“firefox”:

    System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
    //configuration starts here
  • 案例“chrome”:

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

    System.setProperty("webdriver.ie.driver", "C:\\Utility\\BrowserDrivers\\IEDriverServer.exe");
    //configuration starts here
  • 案例“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 包含以下条目:

    127.0.0.1               localhost.localdomain localhost

关于maven - org.apache.http.conn.HttpHostConnectException : Connect to localhost:19538 [localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48419801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com