File classpathRoot=new File(System.getProperty("user.dir"));
File appDir=new File(classpathRoot,"apps/ContactManager");
File app=new File(appDir,"公司的产品就不写了");
//判断 APK 是否存在
if(! app.exists()){
System.out.println("本次需要安装的 APK 不存在");
}
//设置启动参数
DesiredCapabilities capabilities = new DesiredCapabilities();
//设置浏览器类型,如果为空,建议取用 appium 中设定的浏览器
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Firefox");
//设置键盘,支持中文输入
capabilities.setCapability("unicodeKeyboard", "True");
capabilities.setCapability("resetKeyboard", "True");

//设置测试平台
capabilities.setCapability("platformName","Android");
//设置设备名称
capabilities.setCapability("deviceName","Android Emulator");
//设置 Android 版本
capabilities.setCapability("platformVersion", "4.4.2");
//capabilities.setCapability("udid","192.168.56.101:5555");
//获取绝对路径
capabilities.setCapability("app",app.getAbsolutePath());
//设置启动包名
capabilities.setCapability("appPackage", "公司的产品,就不写了");
//设置启动主 activity
capabilities.setCapability("appActivity", ".LoadingActivity");
//设置代理服务器
//AppiumDriver driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub,capabilities"));

//driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
//设置等待超时时间
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
Thread.sleep(10000);
int width=driver.manage().window().getSize().width;
int height=driver.manage().window().getSize().height;
System.out.println("width="+width);
System.out.println("height="+height);
System.out.println("width * 3 / 4="+width * 3 / 4);
System.out.println("height / 2="+height / 2);
System.out.println("width / 8="+width / 8);
//driver.swipe(width * 3 / 4, height / 2, width / 8, height / 2, 2000);//用这个方法不行
new TouchAction(driver).press(width * 3 / 4,height / 2).moveTo(width / 8,height / 2).release().perform();//用这个方法也不行

报错如下:
Exception in thread "main" org.openqa.selenium.interactions.InvalidCoordinatesException: The coordinates provided to an interactions operation are invalid. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 802 milliseconds
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'YC-039-PC', ip: '10.0.0.6', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_25'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=E:\workspace_app\test1\apps\ContactManager*****_1.1.7.apk, appPackage=com., networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=emulator-5554, platform=LINUX, appActivity=.LoadingActivity, desired={app=E:\workspace_app\test1\apps\ContactManager*****_1.1.7.apk, appPackage=com., appActivity=.LoadingActivity, platformVersion=4.4.2, browserName=Firefox, unicodeKeyboard=true, platformName=Android, deviceName=Android Emulator, resetKeyboard=true}, platformVersion=4.4.4, webStorageEnabled=false, locationContextEnabled=false, browserName=Firefox, takesScreenshot=true, javascriptEnabled=true, unicodeKeyboard=true, platformName=Android, resetKeyboard=true}]
Session ID: f6ff3835-9271-418a-839c-4ecc1f0a26e1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:162)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:27)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at io.appium.java_client.AppiumDriver.performTouchAction(AppiumDriver.java:380)
at io.appium.java_client.TouchAction.perform(TouchAction.java:302)
at com.pack.test1.main(test1.java:69)

appuim 中报错入下:
Responding to client with error: {"status":29,"value":{"message":"The coordinates provided to an interactions operation are invalid.","origValue":"Coordinate [x=420.0, y=800.0] is outside of element rect: [0,0][480,800]"},"sessionId":"f6ff3835-9271-418a-839c-4ecc1f0a26e1"}

info: <-- POST /wd/hub/session/f6ff3835-9271-418a-839c-4ecc1f0a26e1/touch/perform 500 791.029 ms - 240
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"Coordinate [x=420.0, y=800.0] is outside of element rect: [0,0][480,800]","status":29}
info: [debug] Didn't get a new command in 60 secs, shutting down...
info: Shutting down appium session

麻烦看下怎么解决,谢谢


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