Appium swipe 不能用

李海燕 · 2016年12月15日 · 最后由 李海燕 回复于 2016年12月21日 · 2395 次阅读

代码
WebElement start = driver1.findElementById("xxxxx");
Point beginLoc = start.getLocation();
driver.swipe(beginLoc.getX(), beginLoc.getY(),beginLoc.getX()-700, beginLoc.getY(), 8000);
错误信息
org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'DESKTOP-5QUNUQR', ip: '192.168.6.178', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
Session ID: d933e532c79d286e896878df759b7b9c
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{platform=ANDROID, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=30.0.0.0, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true}]
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:647)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
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:336)
at io.appium.java_client.TouchAction.perform(TouchAction.java:323)
at io.appium.java_client.AppiumDriver.doSwipe(AppiumDriver.java:383)
at io.appium.java_client.android.AndroidDriver.swipe(AndroidDriver.java:186)
at estore.TestAppium.addContact(TestAppium.java:47)
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:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

共收到 19 条回复 时间 点赞

大侠们,帮帮忙

解决了吗,我的 swipe 也是用不了,启动页广告页滑动不了,后面的用例没法写了

大侠们都很忙,呵呵

排下版吧,这样日志和代码混在一起太难看了。

另外,把你的脚本完整贴上来,就这三句话定位不了问题。根据日志只能告诉你是你的脚本本身的问题。要不是 driver 用错了,要不是 appium-client 版本有问题。

@chenhengjie123
你好:我用的 appium-client 版本是 1.6.3

日志报错
Exception in thread "main" org.openqa.selenium.WebDriverException: Method has not yet been implemented (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 33 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'DESKTOP-5QUNUQR', ip: '192.168.6.193', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_79'
Session ID: 5c8fa93a-a973-4b3a-9e72-7d7b649b1330
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{platform=LINUX, javascriptEnabled=true, browserName=browser, networkConnectionEnabled=true, desired={newCommandTimeout=200000, platformVersion=5.0.2, platformName=Android, deviceName=emulator-5554, browserName=browser, unicodeKeyboard=true, resetKeyboard=true}, locationContextEnabled=false, deviceUDID=emulator-5554, newCommandTimeout=200000, platformVersion=5.0.2, databaseEnabled=false, platformName=Android, deviceName=emulator-5554, webStorageEnabled=false, unicodeKeyboard=true, resetKeyboard=true, warnings={}, takesScreenshot=true}]
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:647)
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 io.appium.java_client.AppiumDriver.swipe(AppiumDriver.java:365)
at estore.Test.main(Test.java:47)

appim 报错

[HTTP] --> POST /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/url {"url":"*************"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/url] to [POST http://127.0.0.1:8000/wd/hub/session/19fc6b414b91e5520209ef9ace6f1bdb/url] with body: {"url":"
*****************"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"19fc6b414b91e5520209ef9ace6f1bdb","status":0,"value":null}
[JSONWP Proxy] Replacing sessionId 19fc6b414b91e5520209ef9ace6f1bdb with 5c8fa93a-a973-4b3a-9e72-7d7b649b1330
[HTTP] <-- POST /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/url 200 129133 ms - 76
[HTTP] --> POST /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/element {"using":"id","value":"classes-and-campaigns"}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/element] to [POST http://127.0.0.1:8000/wd/hub/session/19fc6b414b91e5520209ef9ace6f1bdb/element] with body: {"using":"id","value":"classes-and-campaigns"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"19fc6b414b91e5520209ef9ace6f1bdb","status":0,"value":{"ELEMENT":"0.6417469698935747-1"}}
[JSONWP Proxy] Replacing sessionId 19fc6b414b91e5520209ef9ace6f1bdb with 5c8fa93a-a973-4b3a-9e72-7d7b649b1330
[HTTP] <-- POST /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/element 200 100 ms - 106
[HTTP] --> GET /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/element/0.6417469698935747-1/location {}
[MJSONWP] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Proxying [GET /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/element/0.6417469698935747-1/location] to [GET http://127.0.0.1:8000/wd/hub/session/19fc6b414b91e5520209ef9ace6f1bdb/element/0.6417469698935747-1/location] with body: {}
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"19fc6b414b91e5520209ef9ace6f1bdb\",\"status\":0,\"value\":{\"ceil\":{},\"clone\":{},\"floor\":{},\"round\":{},\"scale\":{},\"toString\":{},\"translate\":{},\"x\":0,\"y\":60}}"
[JSONWP Proxy] Replacing sessionId 19fc6b414b91e5520209ef9ace6f1bdb with 5c8fa93a-a973-4b3a-9e72-7d7b649b1330
[HTTP] <-- GET /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/element/0.6417469698935747-1/location 200 37 ms - 169
[HTTP] --> POST /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/touch/perform {"actions":[{"action":"press","options":{"x":0,"y":60}},{"action":"wait","options":{"ms":8000}},{"action":"moveTo","options":{"x":-700,"y":60}},{"action":"release","options":{}}]}
[debug] [MJSONWP] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":0,"y":60}},{"action":"wait","options":{"ms":8000}},{"action":"moveTo","options":{"x":-700,"y":60}},{"action":"release","options":{}}],"5c8fa93a-a973-4b3a-9e72-7d7b649b1330"]
[HTTP] <-- POST /wd/hub/session/5c8fa93a-a973-4b3a-9e72-7d7b649b1330/touch/perform 501 27 ms - 122

java 代码


    DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "emulator-5554");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "5.0.2");
        capabilities.setCapability("unicodeKeyboard", true); 
        capabilities.setCapability("resetKeyboard", true);
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "browser");
        capabilities.setCapability("unicodeKeyboard",true);
        capabilities.setCapability("resetKeyboard",true);
        capabilities.setCapability("newCommandTimeout", 200000);



        AndroidDriver driver1 = null;
        try {
            driver1 = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        driver1.manage().timeouts().pageLoadTimeout(7000, TimeUnit.SECONDS);
//      driver1.get("http://www.baidu.com");
        driver1.get("***************************/");

        WebElement start = driver1.findElement(By.id("classes-and-campaigns"));
        Point beginLoc = start.getLocation();
        driver1.swipe(beginLoc.getX(), beginLoc.getY(), beginLoc.getX()-700, beginLoc.getY(), 8000);
end

#6 楼 @lihaiye 先调整下排版,太乱了。。。

参考下回帖框右下角的 “排版说明”

@gui3836337

你能用了吗?咋样用的
我用了 tap 的时候报出同样的错误

@chenhengjie123
你再帮帮看看是什么问题

你设置了 browserName ,appium 有可能自动切换成了 webview context ,所以手势无效。
你 swipe 前切换成 native context 试试?

@chenhengjie123
不行呀,报的同样的错误。
你看一下是不是我的写的代码不对

driver1.manage().timeouts().pageLoadTimeout(7000, TimeUnit.SECONDS);
driver1.get("https://estore-int01.mercedes-benz.com.cn/");
Set<String> contextNames = driver1.getContextHandles();
WebElement start = driver1.findElement(By.id("classes-and-campaigns"));
Point beginLoc = start.getLocation();
driver1.swipe(beginLoc.getX(), beginLoc.getY(), beginLoc.getX()-700, beginLoc.getY(), 8000);

#11 楼 @lihaiye 你代码里哪里切换了 native context ?我只看到你获取了 contextNames ,但没做切换啊。

建议先去看下 appium 官方 sample 里面切换 context 相关的代码。你现在的用法是 selenium 的用法,和 appium 的有一些出入。

@chenhengjie123

Set<String> contextNames = driver1.getContextHandles();
for (String contextName : contextNames){ 
    System.out.println(contextName); 
    if(contextName.contains("WEBVIEW")||contextName.contains("webview"))
    { driver1.context(contextName); }
    else{ System.out.println("no WEBVIEW"); }
}

得到的结果是
NATIVE_APP
no WEBVIEW
CHROMIUM
no WEBVIEW

@chenhengjie123
但是用 uiautomatorviewer 才看页面的时候是 WEBVIEW

#14 楼 @lihaiye
你要确认下你执行 swipe 前处于什么 context 。chromium 是浏览器,走的也是 selenium。swipe 这些只有处于 native app 这个 context 才能用

@chenhengjie123
我的代码是这样的

Set<String> contextNames = driver1.getContextHandles();
for (String contextName : contextNames){ 
    System.out.println(contextName); 
    if(contextName.contains("WEBVIEW")||contextName.contains("webview"))
    { driver1.context(contextName); }
    else{ System.out.println("no WEBVIEW"); }
}
driver1.findElementByClassName("item-container");
driver1.swipe(60, 0, -700, 60, 500);

for 循环的到的结果是 NATIVE_APP no WEBVIEW CHROMIUM no WEBVIEW
这是不是能够说明我是在 native app 这个 context

#17 楼 @lihaiye 你找下获取当前 context 的函数。。。这个顺序是固定 NATIVE_APP 排在第一位的,和你当前在什么 context 没啥关系。

@chenhengjie123
你好:
在代码中使用了 driver1.context(“NATIVE_APP”)以后用 swipe 就不会出现错误了
谢谢,你的帮忙。

李海燕 关闭了讨论 12月21日 15:53
李海燕 重新开启了讨论 12月21日 15:53
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册