背景
目前所测的应用是公司的 app,启动 app 时会有 4 张引导图(需要向左滑动 4 次进入 app 的主界面才能进行下一步操作),其中在写的一段代码就是关于滑动的操作
MainActivityTest.java 中的代码
public void swipeToLeft( int during)
{
int width = driver.manage().window().getSize().width;
int height = driver.manage().window().getSize().height;
try {
driver.swipe(width / 2, height / 2, width / 4, height / 2, during);
System.out.println("swipe done");
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("swipetoleft");
}
@Test
public void mainActivity() throws Exception
{
//等待引导图
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
swipeToLeft(200);
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
System.out.println("scroll done");
异常
运行代码时会抛出异常。日志与异常
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 16 milliseconds
Build info: version: '2.47.1', revision: 'unknown', time: '2015-07-30 11:02:44'
System info: host: 'FX-JSJ337', ip: '192.168.131.199', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{app=E:\phonesource\aphone\apps\aphone.apk, appPackage=com.test.video.mobile, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=Coolpad8675-0x02a108ba, platform=LINUX, appActivity=com.test.video.activity.StartActivity, desired={app=E:\phonesource\aphone\apps\aphone.apk, appPackage=com.test.video.mobile, appActivity=com.test.video.activity.StartActivity, newCommandTimeout=60, automationName=Appium, browserName=, platformName=Android, deviceName=Android}, newCommandTimeout=60, platformVersion=4.4.2, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, browserName=, takesScreenshot=true, javascriptEnabled=true, platformName=Android}]
Session ID: b3ba5f31-df33-4d03-8928-fb494be2c96c
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
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 io.appium.java_client.AppiumDriver.swipe(AppiumDriver.java:435)
at test.aphone.MainActivityTest.scrollLoadingPic(MainActivityTest.java:88)
at test.aphone.MainActivityTest.mainActivity(MainActivityTest.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
scroll done
appium 部分日志
info: [debug] Set Android implicit wait to 3000ms
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"a776984b-a93a-4fbb-99ae-e69b785ab71a"}
info: <-- POST /wd/hub/session/a776984b-a93a-4fbb-99ae-e69b785ab71a/timeouts/implicit_wait 200 1.707 ms - 76 {"status":0,"value":null,"sessionId":"a776984b-a93a-4fbb-99ae-e69b785ab71a"}
info: --> GET /wd/hub/session/a776984b-a93a-4fbb-99ae-e69b785ab71a/window/current/size {}
info: [debug] Pushing command to appium work queue: ["getDeviceSize"]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDeviceSize","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getDeviceSize
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"width":720,"height":1280},"status":0}
info: [debug] Responding to client with success: {"status":0,"value":{"width":720,"height":1280},"sessionId":"a776984b-a93a-4fbb-99ae-e69b785ab71a"}
info: <-- GET /wd/hub/session/a776984b-a93a-4fbb-99ae-e69b785ab71a/window/current/size 200 15.769 ms - 99 {"status":0,"value":{"width":720,"height":1280},"sessionId":"a776984b-a93a-4fbb-99ae-e69b785ab71a"}
info: --> GET /wd/hub/session/a776984b-a93a-4fbb-99ae-e69b785ab71a/window/current/size {}
info: [debug] Pushing command to appium work queue: ["getDeviceSize"]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDeviceSize","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getDeviceSize
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"width":720,"height":1280},"status":0}
info: [debug] Responding to client with success: {"status":0,"value":{"width":720,"height":1280},"sessionId":"a776984b-a93a-4fbb-99ae-e69b785ab71a"}
info: <-- GET /wd/hub/session/a776984b-a93a-4fbb-99ae-e69b785ab71a/window/current/size 200 6.638 ms - 99 {"status":0,"value":{"width":720,"height":1280},"sessionId":"a776984b-a93a-4fbb-99ae-e69b785ab71a"}
info: --> POST /wd/hub/session/a776984b-a93a-4fbb-99ae-e69b785ab71a/touch/perform {"actions":[{"action":"press","options":{"x":180,"y":640}},{"action":"wait","options":{"ms":200}},{"action":"moveTo","options":{"x":360,"y":640}},{"action":"release","options":{}}]}
info: [debug] Pushing command to appium work queue: ["swipe",{"startX":180,"startY":640,"endX":360,"endY":640,"steps":6}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"swipe","params":{"startX":180,"startY":640,"endX":360,"endY":640,"steps":6}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: swipe
info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][720,1280]
info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][720,1280]
info: [debug] [BOOTSTRAP] [debug] Swiping from [x=180.0, y=640.0] to [x=360.0, y=640.0] with steps: 6
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"The swipe did not complete successfully","status":13}
info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"The swipe did not complete successfully"},"sessionId":"a776984b-a93a-4fbb-99ae-e69b785ab71a"}
info: <-- POST /wd/hub/session/a776984b-a93a-4fbb-99ae-e69b785ab71a/touch/perform 500 14.197 ms - 208
info: --> DELETE /wd/hub/session/a776984b-a93a-4fbb-99ae-e69b785ab71a {}
info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: D:\Software\eclipse\sdk\platform-tools\adb.exe -s Coolpad8675-0x02a108ba shell "input keyevent 3"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
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: {"value":"OK, shutting down","status":0}
info: [debug] [UIAUTOMATOR STDOUT] [CDS] close[4724]
info: [debug] [UIAUTOMATOR STDOUT] close [socket][/0.0.0.0: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: 5.544
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"a776984b-a93a-4fbb-99ae-e69b785ab71a"}
info: <-- DELETE /wd/hub/session/a776984b-a93a-4fbb-99ae-e69b785ab71a 200 903.671 ms - 76 {"status":0,"value":null,"sessionId":"a776984b-a93a-4fbb-99ae-e69b785ab71a"}