在运行Appium Server启动/停止脚本时获取ExceptionHttpHostConnectException。 我尝试更改端口号但仍然得到相同的异常 任何人都可以检查问题是什么? PFB代码,异常,jarfile版本
硒 - 机器人-driver.jar java-client-4.1.2(1).jar 硒 - 服务器 - 独立-3.0.1.jar
CODE
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
public class Serverhort {
static AndroidDriver driver;
private static Process process;
public static String APPIUM_NODE_FILEPATH = "C:/Program Files (x86)/Appium/node.exe";
public static String APPIUM_SERVERSCRIPT_FILEPATH = "C:/Program Files (x86)/Appium/node_modules/appium/bin/appium.js";
public static String APPIUMSERVERSTART = "\"" + APPIUM_NODE_FILEPATH + "\" \"" + APPIUM_SERVERSCRIPT_FILEPATH + "\" ";
public static void startServer() throws IOException, InterruptedException
{
Runtime runtime = Runtime.getRuntime();
process = runtime.exec(APPIUMSERVERSTART);
Thread.sleep(5000);
if (process != null)
{
System.out.println("Appium server started");
}
}
/**
* DOCUMENT ME!
*/
public static void stopServer()
{
if (process != null)
{
process.destroy();
}
System.out.println("Appium server stop");
}
public static void main(String args[]) throws IOException, InterruptedException {
stopServer();
startServer();
Thread.sleep(10000);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "ccdcb242");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "ANDROID");
capabilities.setCapability(CapabilityType.VERSION, "5.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.sears.android");
capabilities.setCapability("appActivity", "com.android.sears.activity.MenuDrawerActivity");
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4727/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
stopServer();
}
异常消息
Exception in thread "main" org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4727 [/127.0.0.1] failed: Connection refused: connect
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'SHI58495EU1003F', ip: '192.168.0.106', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_66'
Driver info: driver.version: AndroidDriver
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:84)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:36)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:114)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:132)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:92)
at Utility.Serverhort.main(Serverhort.java:60)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4727 [/127.0.0.1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
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)