ScrollTo无法在Appium for Android上运行

时间:2016-05-12 15:42:12

标签: java android appium

我是appium的新手,并试图用我的Android应用程序用Java编写一些测试脚本。在这个视图中,我有一个包含元素的scrollview。我还没有能够使用javascript命令" scrollTo"在scrollview或TouchAction上。我使用的是appium和Android 5.0.1的1.4.13版本。以下是我的代码片段。

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 Executor的堆栈跟踪

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(&#34;里程数&#34;)

它有效,但并非空闲。我也使用 Selendroid

2 个答案:

答案 0 :(得分:0)

使用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();

TouchAction scrollAction = new TouchAction(driver);
int startx = driver.findElement(By.id("vehicleDetailScroll")).getLocation().getX();
int starty = driver.findElement(By.id("vehicleDetailScroll")).getLocation().getY();
int endx = driver.findElement(By.id("map")).getLocation().getX();
int endy = driver.findElement(By.id("map")).getLocation().getY();

答案 1 :(得分:0)

可能类似This example与滑动相同的逻辑。