2017年10月7日星期六

使用Appium向右旋转,向上和向下

这对于那些正在学习Appium的人来说是非常有用的教程,因为刷新和滚动通常用于几乎所有移动应用程序。因此,学习使用Appium自动化它会在编写测试代码中帮助您.Below是我已经写出不同功能的代码,其中从顶部到底,从左右从左到右从左到右,从右到左使用Appium 。我们可以在我们的测试用例中进行所有这些方法来执行所需的操作。此外,我创建了一个具有详细说明的视频教程。



/**
  /* Method to swipe screen from Bottom to Top (Vertical) Get the size of
  * screen. Find swipe start and end point from screen's width and height.
  * Find starty point which is at bottom side of screen. Find endy point
  * which is at top side of screen. Find horizontal point where you wants to
  * swipe. It is in middle of screen width.
  * Time duration should be in milliseconds
  */

 public void bottomTopswipe(int timeduration) {

  
  size = driver.manage().window().getSize();
  System.out.println(size);
  starty = (int) (size.height * 0.50);
  endy = (int) (size.height * 0.20);
  startx = size.width / 2;
  System.out.println("Start swipe operation");
  driver.swipe(startx, starty, startx, endy, timeduration);

 }

 /**
  * 
  * Method to swipe screen from Top to Bottom (Vertical) Get the size of
  * screen. Find swipe start and end point from screen's width and height.
  * Find starty point which is at bottom side of screen. Find endy point
  * which is at top side of screen. Find horizontal point where you wants to
  * swipe. It is in middle of screen width. 
         * Time duration should be in milliseconds
   */

 public void topBottomswipe(int timeduration) {

  
  size = driver.manage().window().getSize();
  System.out.println(size);
  starty = (int) (size.height * 0.50);
  endy = (int) (size.height * 0.20);
  startx = size.width / 2;
  System.out.println("Start swipe operation");
  driver.swipe(startx, endy, startx, starty, timeduration);

 }

 /**
  * 
  * Method to swipe screen from right to left (Horizontal) duration should be
  * in milliseconds Get the size of screen. Find swipe start and end point
  * from screen's width and height. Find startx point which is at right side
  * of screen. Find endx point which is at left side of screen. Find vertical
  * point where you wants to swipe. It is in middle of screen height. 
         * Time duration should be in milliseconds
   */

 public void 正确的LeftSwipe(int timeduration) {

  size = driver.manage().window().getSize();
  System.out.println(size);
  startx = (int) (size.width * 0.70);
  endx = (int) (size.width * 0.30);
  starty = size.height / 2;
  System.out.println("Start swipe operation");
  driver.swipe(startx, starty, endx, starty, timeduration);

 }

 /**
  * 
  * Method to swipe screen from left to right (Horizontal) duration should be
  * in milliseconds Get the size of screen. Find swipe start and end point
  * from screen's width and height. Find startx point which is at right side
  * of screen. Find endx point which is at left side of screen. Find vertical
  * point where you wants to swipe. It is in middle of screen height. 
         * Time duration should be in milliseconds
      */

 public void leftRightSwipe(int timeduration) {
  // duration should be in milliseconds
  size = driver.manage().window().getSize();
  System.out.println(size);
  startx = (int) (size.width * 0.70);
  endx = (int) (size.width * 0.30);
  starty = size.height / 2;
  System.out.println("Start swipe operation");
  driver.swipe(endx, starty, startx, starty, timeduration);

 }

25评论:

  1. 答案
    1. IEEE最后一年项目中心使最佳深度学习的最后一年的学生造成最终学生的想法 CSE的最后一年项目 培训并培养他们的深度学习体验和才能。

      IEEE最后一年的项目 项目中心在印度 始终追捧。最后一年的学生项目拍摄他们以改善他们的娱乐,而专家喜欢干扰创新。

      Chennai的企业培训 Chennai的企业培训

      公司培训公司在印度 公司培训公司在印度

      Chennai的企业培训公司 Chennai的企业培训公司

      我读过你的博客非常有吸引力和令人印象深刻。我喜欢你的博客。 金奈数字营销公司

      删除

  2. 本文非常有用,我希望这将是所需的有用信息。继续更新这些类型的信息......
    发短信API.
    SMS API.
    短信营销

    回复删除
  3. 谢谢你的精彩教程。
    需要帮助。我尝试了上面的代码,但它显示了strid.swipe()的错误

    "yource androiddriver的方法滑动(int,int,int,int,int)是未定义的"

    你能告诉我决议吗?

    回复删除
  4. 如何将Swipe方法水平刷新。我能够垂直向下滑动,但水平我面临着一些问题。

    回复删除
    答案
    1. 是的,这些代码需要按照最新版本进行更新。等待相同。

      删除
  5. 嗨,我使用以下代码滑动/滚动,它是完美的。
    刷新的代码
    public boolean swipefromuptobottom()
    {
    try {
    JavaScriptExecutor JS =(JavaScriptExecutor)驱动程序;
    hashmap scrollobject = new hashmap();
    scrollObject.put("direction", "up");
    js.executeScript("mobile: scroll", scrollObject);
    System.out.println("滑动成功完成。");
    }
    catch (Exception e)
    {
    System.out.println("滑动不是成功的");
    }
    return false;
    }
    代码向下滑动
    公共布尔swipefrombottomtoup()
    {
    try {
    JavaScriptExecutor JS =(JavaScriptExecutor)驱动程序;
    hashmap scrollobject = new hashmap();
    scrollObject.put("direction", "down");
    js.executeScript("mobile: scroll", scrollObject);
    System.out.println("刷下来成功完成");
    }
    catch (Exception e)
    {
    System.out.println("滑下来没有成功");
    }
    return false;
    }
    旋转木马图像的代码滑动

    公共布尔SwipeImages()
    {
    try {
    WebElement PageIndicator = Driver.FindElement(Page_Indicator);
    字符串PageString = PageIndicator.getAttribute("value");
    int length = pageString.Length();
    String count_string = pageString.substring(长度2,长度).trim();
    int count = integer.parseint(count_string);
    System.out.println("可用于滑动的图像数量:"+count);
    for (int i=0; i<=count; i++){
    JavaScriptExecutor JS =(JavaScriptExecutor)驱动程序;
    hashmap scrollobject = new hashmap();
    scrollObject.put("direction", "right");
    js.executeScript("mobile: scroll", scrollObject);
    }
    System.out.println("Swipe Successfully");
    }
    catch (Exception e)
    {
    System.out.println("图像滑动不是成功的");
    }
    return false;
    }

    回复删除
  6. 此评论已被作者删除。

    回复删除
  7. 谢谢你的手册。一世'完成并成功
    地铁冲浪者

    回复删除
  8. 错误: - 为Androiddriver类型滑动(int,int,int,int,int)的方法是未定义的

    回复删除
  9. 优秀的帖子!!!您在这项技术上发布的策略帮助我进入了下一级别,并有很多信息。
    班加罗尔的Java培训

    回复删除
  10. 感谢您分享此信息博客
    //www.digitalakash.in/web-design-development-training-in-bangalore/

    回复删除
  11. 谢谢你这么伟大的文章。我正在寻找相当长的时间,最后我'在你的博客上找到了它。对我来说肯定有趣,现在阅读他们的市场情况。
    钦奈的甲骨文培训

    在塔巴姆的甲骨文培训

    钦奈的Oracle DBA培训

    在塔巴姆的Oracle DBA培训

    CCNA培训在钦奈

    在塔巴姆培训

    钦奈的SEO培训

    SEO培训在塔巴姆

    回复删除