对于那些学习Appium的人来说,这是非常有用的教程,因为几乎所有移动应用程序都经常使用滑动和滚动。因此,学习使用Appium来实现自动化将帮助您编写测试代码。以下是我编写了不同功能的代码,这些代码用于使用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 对 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 对 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 对 (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 对 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); }
好贴。
回复删除班加罗尔最佳Oracle培训
IEEE最终项目中心为最终学生提供了令人惊叹的深度学习最终项目思想 CSE的最后一年项目 训练和发展他们的深度学习经验和才能。
删除IEEE最终年项目 印度的项目中心 一直受到追捧。四年级学生项目向他们射击以提高他们的才智,而专家则喜欢干扰创新的乐趣。
钦奈企业培训 钦奈企业培训
印度公司培训公司 印度公司培训公司
金奈公司培训公司 金奈公司培训公司
我已经读过您的博客,它非常吸引人。我喜欢你的博客。 钦奈数字营销公司
回复删除本文非常有帮助,我希望这对需要的人来说是有用的信息。继续更新这些有用的信息...
短信API
短信API
短信营销
谢谢您的精彩教程。
回复删除需要您的帮助。我尝试了上面的代码,但在driver.swipe()中显示错误
"对于类型AndroidDriver,未定义方法swipe(int,int,int,int,int)"
你能告诉我分辨率吗
取消了滑动方式后如何水平滑动。我能够垂直或水平滑动我遇到了一些问题。
回复删除是的,这些代码需要根据最新版本进行更新。等待一样。
删除嗨,我已经使用下面的代码来滑动/滚动,并且它运行良好。
回复删除向上滑动的代码
公共布尔swipeFromUpToBottom()
{
尝试{
JavascriptExecutor js =(JavascriptExecutor)驱动程序;
HashMap scrollObject = new HashMap();
scrollObject.put("direction", "up");
js.executeScript("mobile: scroll", scrollObject);
System.out.println("向上滑动已成功完成。");
}
捕获(异常e)
{
System.out.println("向上滑动不成功");
}
返回false;
}
代码向下滑动
公共布尔swipeFromBottomToUp()
{
尝试{
JavascriptExecutor js =(JavascriptExecutor)驱动程序;
HashMap scrollObject = new HashMap();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);
System.out.println("向下滑动已成功完成");
}
捕获(异常e)
{
System.out.println("向下滑动不成功");
}
返回false;
}
轮播图片滑动代码
公共布尔swipeImages()
{
尝试{
WebElement pageIndicator = driver.findElement(page_indicator);
字符串pageString = pageIndicator.getAttribute("value");
int length = pageString.length();
字符串count_string = pageString.substring(length-2,length).trim();
int count = Integer.parseInt(count_string);
System.out.println("可滑动的图片数量:"+count);
为(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");
}
捕获(异常e)
{
System.out.println("图像滑动失败");
}
返回false;
}
感谢Vinita
删除此评论已被作者删除。
回复删除谢谢您的手册。一世'做得成功
回复删除地铁冲浪者
错误:-未为类型AndroidDriver定义方法Swipe(int,int,int,int,int)
回复删除在我现在仍然阅读的所有博客中,该博客仍然是最好的。伟大的写作风格和内容交付方式。请分享更多更新。
回复删除安娜·纳加尔的雅思辅导
阿迪亚尔雅思考试
波兰语雅思考试
钦奈的雅思考试
钦奈英语口语课
钦奈最佳英语口语课
钦奈英语口语课
很棒的博客!!!是一个有趣且概念清晰的博客。并且肯定会帮助许多人进行更新。
回复删除钦奈的ReactJS培训
ReactJS培训
金奈GST课程
钦奈的UX设计课程
ReactJS课程
钦奈网页设计课程
钦奈的道德黑客课程
钦奈的理货课程
优秀的帖子!您在该技术上发布的策略帮助我进入了一个新的水平,并获得了很多信息。
回复删除班加罗尔的Java培训
帖子不错,谢谢 网络安全培训
回复删除感谢您分享这个内容丰富的博客
回复删除//www.digitalakash.in/web-design-development-training-in-bangalore/
感谢您在这里的精彩文章。我一直在寻找类似的东西很长时间,最后我'在您的博客上找到了它。对于我来说,了解他们如今的市场状况绝对是一件很有趣的事情。
回复删除在钦奈的oracle培训
坦巴兰的oracle培训
甲骨文在dna的dba培训
坦巴拉姆的oracle dba培训
钦奈ccna培训
坦巴拉姆的ccna培训
钦奈的seo培训
坦巴拉姆的seo培训
在我现在仍然阅读的所有博客中,该博客仍然是最好的。伟大的写作风格和内容交付方式。请分享更多更新。
回复删除钦奈网页设计培训
网页设计培训
钦奈的数字营销培训
全方位数字营销培训
钦奈的rpa培训
RPA OMR培训
在钦奈进行理货培训
omr理货培训
非常丰富的博客和出色的工作,
回复删除多谢与我们分享,
钦奈的数据科学培训
porur的数据科学培训
钦奈android培训
porur中的android培训
在钦奈的devops培训
训练在porur
钦奈的人工智能培训
porur的人工智能培训
很好的分享,非常感谢。写得很好,我感谢您的工作。
回复删除在钦奈的oracle培训
在annanagar的oracle培训
甲骨文在dna的dba培训
在annanagar进行oracle dba培训
钦奈ccna培训
annanagar ccna培训
钦奈的seo培训
安娜纳加尔的seo培训
这是一直在寻找的信息。真知灼见&您已经很好地解释了。谢谢&期待更多此类有价值的更新。
回复删除在钦奈的oracle培训
甲骨文培训
甲骨文在dna的dba培训
甲骨文dba培训
钦奈ccna培训
CCNA velachery培训
钦奈的seo培训
velachery的seo培训
很棒的博客!!!是一个有趣且概念清晰的博客。
回复删除演员评论
Acte velachery评论
女演员坦布拉姆评论
女演员安娜·纳加尔评论
acte porur评论
演员评论
钦奈女演员评论
女演员学生评论
回复删除感谢您分享最有价值的信息,这些信息真的很棒。
工作日工作室培训
Workday Studio在线培训
工作日课程
印度Workday Studio在线培训
Workday Studio在线培训海得拉巴
印度工作日工作室培训
Aivivu-瑟里韦梅湾(Thamkhảo)
回复删除vémáybayđiMỹbaonhiêutiền
vémỹvềviệtnam
洛杉矶湾日报
ềănkýbaytừcanadavềViệtNam