我正在使用appium
自动化Android应用。使用url创建驱动程序。
在这里,我为移动网络浏览器提供了空字符串,因为我直接自动化应用程序。
这是appium代码,
public class Cal {
private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException{
File app = new File("C:\\Users\\Priya\\Desktop\\FitbaseApk\\Fitbase_01_21_2016_APK.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Lenovo- A7000-a");
capabilities.setCapability("platformVersion", "5.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.ionicframework.fitbase444706");
capabilities.setCapability("appActivity","com.ionicframework.fitbase444706.mainActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
}
}
以下是错误日志:
Exception in thread "main" 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.49.0', revision: '365eeb4', time: '2016-01-13 18:33:29'
System info: host: 'QA1-PC', ip: '192.168.0.82', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_71'
Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
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:249)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:37)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:161)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:170)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:82)
at FitbaseApp.Cal.main(Cal.java:37)
Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect
Build info: version: '2.49.0', revision: '365eeb4', time: '2016-01-13 18:33:29'
System info: host: 'QA1-PC', ip: '192.168.0.82', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_71'
Driver info: driver.version: AndroidDriver
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:79)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
... 11 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: 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:142)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:67)
... 12 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
... 25 more
答案 0 :(得分:1)
问题是在。
HttpHostConnectException:连接到127.0.0.1:4723 [/127.0.0.1] 失败:
答案 1 :(得分:1)
我得到了解决方案。出现问题是因为appium需要相对较长的时间才能启动。你可以在最后给出&#34; driver.manage()。timeouts()。implicitlyWait(80,TimeUnit.SECONDS);&#34;。在这里我减少了时间,现在它正常工作..
答案 2 :(得分:1)
使用上面的代码,你根本不应该使用固定的Thread.Sleep,因为你永远不知道appium要花多长时间才能开始。最好的方法是以编程方式启动appium,然后监视http://localhost:4723,这是appium始终运行的地方。您需要继续向此网址发送请求,并等待您收到此网址的响应,一旦您收到应该初始化驱动程序的响应,例如,如果您了解这一点,我将发布整个代码,httpClientWrap是我的图书馆。
public static boolean waitForAppiumServer()
{
boolean flag = false;
for(int i=0; i<=20; i++)
{
String status = httpClientWrap.sendGetRequest("http://localhost:4723/wd/status");
if(!status.isEmpty())
{
logger.info("appium service has been launched successfully. ");
flag = true;
break;
}
logger.info("appium service has not been launched, waiting to get started .... attempt: "+i);
try {Thread.sleep(3000);} catch (InterruptedException e) {}
}
return flag;
}