2016-05-12 71 views
3

我是新來的appium,並嘗試在我的android應用程序中編寫一些Java測試腳本。在這個視圖中,我有一個滾動查看其中的元素。我無法在scrollview或TouchAction上使用javascript命令「scrollTo」。我正在使用appium和android 5.0.1的1.4.13版本。下面是我的代碼片段。ScrollTo無法在Appium上工作Android

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

+0

stacktrace不包括失敗聲明(UnsupportedCommandException) – nullpointer

+0

增加了@nullpointer – DrPatience

+0

什麼依賴關係(庫)與版本是你用於appium?另外你爲什麼使用Selendroid API 21來測試(只是好奇)? – nullpointer

回答

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(); 
+0

謝謝,我曾經使用過,但它沒有工作 – DrPatience

+0

@DrPatience:好吧,你可以添加完整stacktrace爲'UnsupportedCommandException'問題 – nullpointer

+0

嗨,我已經更新了堆棧跟蹤的問題,謝謝 – DrPatience

0

它可能會像This example相同的邏輯,刷卡。

+0

謝謝你的建議。在使用TouchActions – DrPatience

+0

感謝您的迴應時,我得到了下面的錯誤,我仍然有一個錯誤。您可以在此鏈接http://pastebin.com/NvEYeLW4上查看錯誤 – DrPatience