Appium WebDriverException: An unknown server-side error occurred while processing the TouchAction command

gundamsing · 2017年11月22日 · 最后由 gundamsing 回复于 2017年12月12日 · 1861 次阅读

The problem

执行 TouchAction 的时候出现 WebDriverException. 只出现在安卓机器上,苹果上一切正常。

Environment

  • Appium version (or git revision) that exhibits the issue: 1.7.0
  • Desktop OS/version used to run Appium: MacOS 10.12
  • Node.js version (unless using Appium.app|exe):
  • Mobile platform/version under test:Android 5.x, 6.x
  • Real device or emulator/simulator: Real device

Appium logs

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: 0 milliseconds
Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:42:44.417Z'
System info: host: 'sprylabs.local', ip: '2001:1438:4010:2812:0:0:0:ff86', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_91'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.sprylab.appiumtestapp, deviceScreenSize=2560x1600, networkConnectionEnabled=true, noReset=true, warnings={}, databaseEnabled=false, deviceName=CB5A28GNDH, fullReset=false, platform=LINUX, deviceUDID=CB5A28GNDH, appActivity=com.sprylab.purple.android.app.purple.splash.SplashActivity, desired={appPackage=com.sprylab.appiumtestapp, appActivity=com.sprylab.purple.android.app.purple.splash.SplashActivity, noReset=true, newCommandTimeout=300, udid=CB5A28GNDH, platformName=Android, deviceName=SGP712, fullReset=false}, newCommandTimeout=300, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, javascriptEnabled=true, deviceModel=SGP712, udid=CB5A28GNDH, deviceManufacturer=Sony, platformName=LINUX}]
Session ID: 94ad6514-8ace-4918-9016-8e062d594f53

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:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
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 io.appium.java_client.PerformsTouchActions.performTouchAction(PerformsTouchActions.java:41)
at io.appium.java_client.TouchAction.perform(TouchAction.java:325)
at com.sprylab.purple.pages.KioskPage.scrollUpUntilElementDisplayed(KioskPage.java:357)
at com.sprylab.purple.tests.KioskTest.MultiIssueDownloadInSameTime(KioskTest.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
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 com.sprylab.tools.appium.internal.DeviceRunner$AppiumDriverStatement.evaluate(DeviceRunner.java:269)
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 com.sprylab.tools.appium.internal.DeviceRunner$AppUninstallChildrenInvokerStatement.evaluate(DeviceRunner.java:224)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at com.sprylab.tools.appium.AppiumMultiDeviceTestRunner.runChild(AppiumMultiDeviceTestRunner.java:151)
at com.sprylab.tools.appium.AppiumMultiDeviceTestRunner.runChild(AppiumMultiDeviceTestRunner.java:46)
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 com.sprylab.tools.appium.AppiumMultiDeviceTestRunner$1.evaluate(AppiumMultiDeviceTestRunner.java:140)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Code To Reproduce Issue

public void scrollUpUntilElementDisplayed(WebElement element) throws NoSuchElementException {
        int windowHeight = driver.manage().window().getSize().height;
        int windowWidth = driver.manage().window().getSize().width;
        do {
            new TouchAction(driver)
                .press(windowWidth / 2, windowHeight / 2)
                .waitAction(Duration.ofMillis(300))
                .moveTo(0, -200)
                .release()
                .perform();
        } while (!element.isDisplayed());
    }

共收到 7 条回复 时间 点赞

又试了很多次,发现只有在我使用 .press(x,y) 的时候才会这样,用 .press(element) 代替坐标就不会出现 exception,在安卓手机和平板上试过都是这样,真是十分奇怪。

我以前遇到过

是官方文档的解释有错误

在 moveTo 中使用相对于屏幕左上角的坐标
不要使用相对于起点的坐标,我上个星期刚刚处理完这个

dy20082250 回复

卧槽,还真是。我记得我最早一开始用的是相对屏幕的位置,后来不知道啥时候出错了。然后改成了相对于起点的位置。这是又改回去了么??? 不管怎样非常感谢!🙏

gundamsing 回复

我就被这个文档的解释忽悠了一把,然后上网查,还都是人云亦云者,花了我大半个下午才意识到问题所在,简直坑爹!!

dy20082250 回复

原来这个 moveTo 用在安卓和苹果的效果不一样。。。尴尬了。。。还得写个 if😂

gundamsing 回复

真的吗?

我还没有写苹果端的代码,如果真是这样,那真就坑爹了

dy20082250 回复

苹果是相对于起点。。。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册