【问题标题】:Getting error while executing program to swipe down the screen using Appium执行程序以使用 Appium 向下滑动屏幕时出错
【发布时间】:2016-01-06 03:04:26
【问题描述】:

我在执行程序以使用 Appium 向下滑动屏幕时遇到错误。

虽然代码适用于向右或向左滑动,但在向下滑动屏幕时出现错误。
这几天我几乎要撞到头了。请帮忙。我已附上代码和错误消息供您查看。

提前致谢。

代码:-

public class SwipeScreen {
    AndroidDriver dr;
    @Test
    public void testApp() throws MalformedURLException, InterruptedException{
    DesiredCapabilities capabilities = new DesiredCapabilities("appWaitActivity", null, null);
    File app =new File(System.getProperty("user.dir")+"\\app\\net.one97.paytm (1).apk");
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "android"); 
     capabilities.setCapability("deviceName","samsung-gt_i9060-42035bec4397 c000");
      capabilities.setCapability("PlatformVersion","4.2.2");
      capabilities.setCapability("PlatformName","Android");
      capabilities.setCapability("app",app.getAbsolutePath());
     // capabilities.setCapability("appPackage","com.android.settings");
     // capabilities.setCapability("appActivity","com.android.settings.SettingsTabActivity");
      dr = new AndroidDriver(new URL("http://192.168.10.165:4723/wd/hub"),capabilities);
      dr.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
    Thread.sleep(50000);
    System.out.println(dr.manage().window().getSize().getWidth());
    System.out.println(dr.manage().window().getSize().getHeight());
    int screenWidth = dr.manage().window().getSize().getWidth();
    int screenHeight = dr.manage().window().getSize().getHeight();
    //Swipe Right
    int startx = screenWidth*8/9;
    int endx = screenWidth/9;
    int starty = screenHeight/2;
    int endy = screenHeight/2;
    dr.swipe(startx, starty, endx, endy, 5000);
    Thread.sleep(50000);
     //Swipe Left
    startx = screenWidth/9;
    endx = screenWidth*8/9;
    starty = screenHeight/2;
    endy = screenHeight/2;
    dr.swipe(startx, starty, endx, endy, 5000);
    Thread.sleep(50000);
    //swipe down
    startx = screenWidth/2;
    endx = screenWidth/2;
    starty = screenHeight*6/7;
    endy = screenHeight/5;
    dr.swipe(startx, starty, endx, endy, 10000);
    Thread.sleep(50000);
    //swipe up
    startx = screenWidth/2;
    endx = screenWidth/2;
    starty = screenHeight/6;
    endy = screenHeight*5/6;
    dr.swipe(startx, starty, endx, endy, 5000);

    }

}

错误:-

org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session.  
Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:58'
System info: host: 'Halcyon2-PC', ip: '192.168.140.172', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_67'
Driver info: driver.version: AndroidDriver

【问题讨论】:

  • 你能确保你的appium服务器正在运行吗?错误说它无法访问 appium 服务器
  • > info: [debug] [BOOTSTRAP] [debug] 从 [x=240.0, y=685.0] 滑动到 [x=240.0, y=160.0] 步骤:280 > info: [debug ] [BOOTSTRAP] [debug] 返回结果:{"value":"刷卡没有成功完成","status":13} > info: [debug] 响应客户端错误:{"status":13," value":{"message":"处理命令时发生未知的服务器端错误。","origValue":"滑动未成功完成"},"sessionId":"8074bc5f-24b3-47b1-b6f8- e2343f941817"}

标签: android selenium-webdriver appium


【解决方案1】:

由于您的问题在网上已经被提及过几次,没有严格的解决方案:link1link2link3

我将在此处发布您可以尝试实现的代码行。它为我完成了这项工作。

action.press(startX1,startY1).waitAction(2000).moveTo(endX1,endY1).release().perform();

【讨论】:

  • 感谢您的回复,但仍然遇到同样的问题。它正在完成任务并抛出异常。
  • 看来问题可能不完全与刷卡功能有关,而与服务器浏览器本身有关。也许尝试将服务器的 IP 更改为 localhost(当然,如果可以的话),设置不同的端口号,并确保在每次午餐后停止并重新启动 appium 框架。您也可以在尝试之前清除报告文件夹。
  • 代码在左滑和右滑时工作正常,但我在仅向下滑动时遇到问题。我正在使用安卓版本为 4.2.2 的三星手机。我的 Appium 版本是 1.4.0.0,java 客户端版本是 3.1.0。可能是我的版本有问题??
  • 这里有同样的问题。向下滑动在除三星 (OS - 5.1.1) 之外的所有设备上都可以正常工作。此错误是特定于设备的
  • 在这种情况下,您可以定义 startX1、startY1、endX1、endY1 并尝试以我在上面发布的 action.press 的方式滑动。它为我完成了向所有方向滑动的工作 - 由开始,结束变量定义。
猜你喜欢
  • 2017-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-20
  • 2020-11-04
  • 2015-08-08
  • 2018-11-11
  • 2019-03-31
相关资源
最近更新 更多