【发布时间】:2016-09-08 13:37:44
【问题描述】:
我是 appium 的新手,正在尝试用 Java 为我的 android 应用程序编写一些测试脚本。在这个视图上,我有一个滚动视图,里面有元素。我无法在滚动视图或 TouchAction 上使用 javascript 命令“scrollTo”。我正在使用 1.4.13 版的 appium 和 android 5.0.1。下面是我的代码的 sn-ps。
final WebElement scroller = (new WebDriverWait (driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("vehicleDetailScroll"))));
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap <String, String> scrollObject = new HashMap <String, String>();
scrollObject.put("direction", "down");
scrollObject.put("element", ((RemoteWebElement)
driver.findElement(By.id("vehicleDetailScroll"))).getId());
js.executeScript("mobile: scroll", scrollObject);
记录的错误:找不到请求的资源,或者使用映射资源不支持的 HTTP 方法接收到请求。
javaScript 执行器的堆栈跟踪
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/db708eaa-13cc-d47d-8a85-d465e21d9d2e/element","method":"POST","json":{"using":"id","value":"vehicleDetailScroll"}}
info: [debug] Proxied response received with status 200: {"sessionId":"db708eaa-13cc-d47d-8a85-d465e21d9d2e","status":0,"value":{"ELEMENT":"fb5d8d8b-8cd7-5487-9862-339c9d837a27"}}
info: <-- POST /wd/hub/session/db708eaa-13cc-d47d-8a85-d465e21d9d2e/element 200 42.071 ms - 122
info: --> POST /wd/hub/session/db708eaa-13cc-d47d-8a85-d465e21d9d2e/execute {"script":"mobile: scrollTo","args":[{"element":"fb5d8d8b-8cd7-5487-9862-339c9d837a27"}]}
info: [debug] Responding to client with error: {"status":9,"value":{"message":"The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource. (Original error: That device doesn't know how to respond to 'mobile: 'scrollTo--it's probably not using Appium's API)","origValue":"That device doesn't know how to respond to 'mobile: 'scrollTo--it's probably not using Appium's API"},"sessionId":"db708eaa-13cc-d47d-8a85-d465e21d9d2e"}
info: <-- POST /wd/hub/session/db708eaa-13cc-d47d-8a85-d465e21d9d2e/execute 500 1.854 ms - 453
info: --> DELETE /wd/hub/session/db708eaa-13cc-d47d-8a85-d465e21d9d2e {}
info: Shutting down appium session
info: [debug] Stopping selendroid server
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/db708eaa-13cc-d47d-8a85-d465e21d9d2e","method":"DELETE"}
info: [debug] e
还有 TouchAction
TouchAction scrollAction = new TouchAction((MobileDriver)driver);
int startx = driver.findElement(By.id("vehicleDetailScroll")).getLocation().getX();
int starty = driver.findElement(By.id("vehicleDetailScroll")).getSize().getHeight();
int endx = driver.findElement(By.id("map")).getLocation().getX();
int endy = driver.findElement(By.id("map")).getLocation().getY();
scrollAction.press(startx, starty).moveTo(endx, endy).release().perform();
Error:
FAILED: scenarioFour
org.openqa.selenium.UnsupportedCommandException: Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: '***', ip: '***', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.4', java.version: '1.7.0_80'
Session ID: 6b072ce3-d2fc-1768-6fac-98dd3c31848c
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{automationName=selendroid, platform=ANDROID, acceptSslCerts=true, javascriptEnabled=true, browserName=selendroid, networkConnectionEnabled=true, rotatable=true, desired={automationName=Selendroid, deviceName=GT-19505, platformName=Android}, version=0.16.0, platformVersion=21, platformName=android, deviceName=GT-19505, handlesAlerts=true, warnings={}, takesScreenshot=true}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
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:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:43)
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:316)
at io.appium.java_client.TouchAction.perform(TouchAction.java:318)
at SeleniumTest01.selenium.AndroidBBDTests.scenarioOne(AndroidBBDTests.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
TouchAction 的堆栈跟踪:
info: --> POST /wd/hub/session/5b3d9e53-fce3-28ce-66e8- 85a8a5812d50/touch/perform {"actions":[{"action":"press","options":{"x":0,"y":75}},{"action":"moveTo","options":{"x":0,"y":6439}},{"action":"release","options":{}}]}
info: [debug] Proxying command to localhost:8080
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/5b3d9e53-fce3-28ce-66e8-85a8a5812d50/touch/perform","method":"POST","json":{"actions":[{"action":"press","options":{"x":0,"y":75}},{"action":"moveTo","options":{"x":0,"y":6439}},{"action":"release","options":{}}]}}
info: [debug] Proxied response received with status 404: undefined
info: <-- POST /wd/hub/session/5b3d9e53-fce3-28ce-66e8-85a8a5812d50/touch/perform 404 7.924 ms - -
info: --> DELETE /wd/hub/session/5b3d9e53-fce3-28ce-66e8-85a8a5812d50 {}
info: Shutting down appium session
info: [debug] Stopping selendroid server
info: [debug] Making http request with opts: {"url":"http://localhost:8080/wd/hub/session/5b3d9e53-fce3-28ce-66e8-85a8a5812d50","method":"DELETE"}
我试过了 driver.scrollTo("英里远")
它可以工作,但不是很闲。我也在使用 Selendroid。
【问题讨论】:
-
stacktrace 不包括所述的失败 (UnsupportedCommandException)
-
添加了@nullpointer
-
您在 appium 中使用了哪些版本的依赖项(库)?另外,您为什么要使用 Selendroid for API 21 进行测试(只是好奇)?
-
java-client-3.4.1.jar、selenium-java-2.53.0-srcs.jar、selenium-java-2.53.0.jar 和 selenium-server-standalone-2.53.0。罐。没有使用 API 21 的特殊原因,我的 android 设备当前版本为 5.0.1 @nullpointer
-
android 16 及以上的 appium 是首选的自动化类型,所以我建议你使用它。 appium 的 java 客户端本身也包含所需的 selenium 客户端,除非您想使用特定于 selenium 的东西,否则您不需要它们