环境:appium1.1,windows 7,htc one

代码如下:


 private AppiumDriver driver;

        @Before
        public void setUp() throws Exception {
            // set up appium
//          File classpathRoot = new File(System.getProperty("user.dir"));
            //存放app目录:apps
//          File appDir = new File(classpathRoot, "apps");
//            File app = new File(appDir, "GHome--release-tag-v4.7.0-20140606-01.apk");
            //配置webdriver
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("platform", "WINDOWS");
            capabilities.setCapability("deviceName","HTC");
            capabilities.setCapability("platformVersion", "4.2");
//          capabilities.setCapability("app", app.getAbsolutePath());
            capabilities.setCapability("appPackage", "com.sdo.sdaccountkey");
            capabilities.setCapability("appActivity", ".ui.guide.TXZFirstActivity");
//          capabilities.setCapability("appActivity", ".ui.guide.TXZFreshManGuideActivity");
            //appium的独特地方,使用自己的AppiumDriver, 它本身是继承自WebDriver
            driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
            //设置超时
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }
        @Test
        public void guideFreshMan() throws InterruptedException{
        //向下滑动,appium0.18的用法
           JavascriptExecutor jse=(JavascriptExecutor)driver;
            HashMap<String, Double> scriptObject=new HashMap<String, Double>();
            scriptObject.put("startX", 400.0);
            scriptObject.put("startY", 2.0);
            scriptObject.put("endX", 1.0);
            scriptObject.put("endY", 2.0);
            scriptObject.put("duration", 0.1);
            jse.executeScript("mobile: swipe", scriptObject);
            //driver.swipe(157, 1029, 156, 1, 1);   
          //点击立即体验按钮
          WebElement expierence  = null;
        //searchHisotry = driver.findElementByXPath("//android.widget.ListView//android.widget.RelativeLayout[@index=1]");
          expierence = driver.findElementByXPath("//android.widget.RelativeLayout[last()]");
          expierence.click();   
         }
        @After
        public void tearDown() throws Exception {
            driver.quit();
        }

appium 输入日志如下:

> info: UiAutomator shut down normally
> ERROR: error: Failed to start an Appium session, err was: Error: com.sdo.sdaccountkey/.ui.guide.TXZFirstActivity never started. Current: com.sdo.sdaccountkey/.ui.guide.TXZFreshManGuideActivity
> info: Cleaning up android objects
> info: Cleaning up appium session
> info: Error: com.sdo.sdaccountkey/.ui.guide.TXZFirstActivity never started. Current: com.sdo.sdaccountkey/.ui.guide.TXZFreshManGuideActivity
>     at null.<anonymous> (D:\Appium-1.1.0\node_modules\appium\lib\devices\android\adb.js:1276:12)
>     at null.<anonymous> (D:\Appium-1.1.0\node_modules\appium\lib\devices\android\adb.js:1221:7)
>     at D:\Appium-1.1.0\node_modules\appium\lib\devices\android\adb.js:153:5
>     at ChildProcess.exithandler (child_process.js:635:7)
>     at ChildProcess.EventEmitter.emit (events.js:98:17)
>     at maybeClose (child_process.js:743:16)
>     at Process.ChildProcess._handle.onexit (child_process.js:810:5)
> info: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: com.sdo.sdaccountkey/.ui.guide.TXZFirstActivity never started. Current: com.sdo.sdaccountkey/.ui.guide.TXZFreshManGuideActivity)","origValue":"com.sdo.sdaccountkey/.ui.guide.TXZFirstActivity never started. Current: com.sdo.sdaccountkey/.ui.guide.TXZFreshManGuideActivity"},"sessionId":null}
> POST /wd/hub/session 500 26417ms - 404b

Eclipse 运行时的截图如下:

PS:同样的环境,我替换掉里面的变量,可以在手机淘宝上成功运行代码。。这尼玛算咋回事呢?有小伙伴能帮忙看下异常引起的原因吗? 万分感谢!


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