我在尝试使用 appium 的时候编写了一个简单的脚本,但是出现问题是:
appium 每次执行就只打开我手机上的 app,然后就结束了,没有执行我在脚本内编写的用例代码,我查看运行日志,日志中只是提醒没有接收到新的会话,等待新会话实践超多 60s,结束会话,杀掉 app 进程
在 eclipse 中通过查看发现这样的情况:
1.脚本无错误
2.测试结果从一开始便是由红色 x 标记
不明白为什么,请大神们指点一下迷津,谢谢!下面附上一些我写的脚本,还有 eclipse 中的结果截图,和 appium 运行日志中的一些结果提醒。
脚本如下
public void myteststart() throws MalformedURLException {
File classpathRoot= new File(System.getProperty("user.dir"));
File appDir= new File(classpathRoot, "res/app");
File app = new File(appDir, "lzvtc.apk");
DesiredCapabilities capabilities= new DesiredCapabilities();
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("deviceName","M5 Note");
capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("app", "C:/Users/Administrator/workspace/appiumdemo/res/app/lzvtc.apk");
capabilities.setCapability("appPackage", "com.lantu.MobileCampus.lzvtc");
capabilities.setCapability("appActivity", "com.lantu.MobileCampus.lzvtc.MainActivity");
driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@AfterClass

public void afterClass()
{

driver.quit();
}
public void my_test2() throws InterruptedException {

((WebElement) driver.findElementsByAccessibilityId("立即体验")).click();

((WebElement) driver.findElementsByAccessibilityId("请输入登录账号")).sendKeys("xy");

((WebElement) driver.findElementsByAccessibilityId("登陆")).click();

driver.findElement(By.xpath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.android.webkit.WebView/android.widget.android.view.View/android.widget.android.view.View[3]")).sendKeys("xy");

((WebElement) driver.findElementsByAccessibilityId("基础服务")).click();

((WebElement) driver.findElementsByAccessibilityId("新闻公告")).click();

}
截图如下

运行部分日志如下
* info: [debug] Didn't get a new command in 60 secs, shutting down...*

info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: E:\android_sdk\platform-tools\adb.exe -s 621QECQ83QJ4Q shell "input keyevent 3"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
info: [debug] [UIAUTOMATOR STDOUT] close [socket][/127.0.0.1:4724]
info: [debug] [BOOTSTRAP] [debug] Closed client connection
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [debug] [UIAUTOMATOR STDOUT] Time: 63.091
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] We shut down because no new commands came in


↙↙↙阅读原文可查看相关链接,并与作者交流