【转】Appium测试安卓Launcher以滑动窗体获得目标应用
原文地址:http://blog.csdn.net/zhubaitian/article/details/39755553
所谓Launcher,指的是安卓的桌面管理程序,所有的应用图标都放在launcher上面。其实这是一个很简单的例子,只是为了验证几点想法而已。
1.实验目的
做这个试验的目的有二
- 尝试下窗体滑动函数swipe的使用
- 好奇究竟能不能正常的对安卓的Launcher进行指定package和activity进行测试
2.实验背景
3. 试验步骤
3.1 获得launcher的package和activity两个capabilities
3.2 编码实现
- package majcit.com.AppiumDemo;
- import io.appium.java_client.android.AndroidDriver;
- import java.net.URL;
- import org.junit.Test;
- import org.junit.After;
- import org.junit.Before;
- import org.openqa.selenium.Dimension;
- import org.openqa.selenium.NoSuchElementException;
- import org.openqa.selenium.Point;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.remote.DesiredCapabilities;
- import static org.hamcrest.Matchers.*;
- import static org.hamcrest.MatcherAssert.assertThat;
- /**
- * Unit test for simple App.
- */
- public class LauncherTest {
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- private AndroidDriver driver;
- @Before
- public void setUp() throws Exception {
- // set up appium
- //File classpathRoot = new File(System.getProperty("user.dir"));
- //File appDir = new File(classpathRoot, "apps");
- //File app = new File(appDir, "NotePad.apk");
- DesiredCapabilities capabilities = new DesiredCapabilities();
- capabilities.setCapability("deviceName","Android");
- //capabilities.setCapability("platformVersion", "4.2");
- //capabilities.setCapability("platformName", "Android");
- //capabilities.setCapability("app", app.getAbsolutePath());
- capabilities.setCapability("appPackage", "com.miui.home");
- capabilities.setCapability("appActivity", "com.miui.home.launcher.Launcher");
- //capabilities.setCapability("appActivity", ".NotesList");
- //capabilities.setCapability("autoLaunch", "false");
- //capabilities.setCapability("noReset", true);
- driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
- }
- @After
- public void tearDown() throws Exception {
- driver.quit();
- }
- @Test
- public void launchNotePad() throws InterruptedException{
- WebElement el = null;
- WebElement screen = null;
- Point point = null;
- Dimension size = null;
- boolean found = false;
- int pageCount = 3; //Assume that there are totally 3 screens to be swiped.
- int xStart = -1;
- int yStart = -1;
- int xEnd = -1;
- int yEnd = -1;
- //Get the start and end coordinates for swipe
- Thread.sleep(3000);
- screen = driver.findElementById("com.miui.home:id/cell_layout");
- point = screen.getLocation();
- size = screen.getSize();
- xEnd = point.getX();
- yEnd = point.getY() + size.getHeight()/2;
- xStart = point.getX() + size.getWidth() - 5;
- yStart = yEnd;
- System.out.println("starX:" + xStart +"\nstartY:" + yStart + "\nendX:" + xEnd + "\nendY:" + yEnd);
- //本来想通过判断屏幕上的几个小圆点来判断究竟有多少个屏幕的,但发觉xPath根本不起效,父目录感觉根本起不了定位作用,只有最后的//android.widget.ImageView起效,所以一下找出75个元素。
- /*
- List<WebElement> pageImages = driver.findElementsByXPath("//android.view.View/android.widget.LinearLayout/android.widget.ImageView");
- assertThat(pageImages.size(),is(3));
- for (WebElement e: pageImages) {
- e.click();
- }
- */
- //Swipe all screens till get the expected control
- int currentPage = 0;
- while (found == false && currentPage < pageCount) {
- found = true;
- currentPage += 1;
- try {
- el = driver.findElementByName("Notes");
- }catch (NoSuchElementException e) {
- found = false;
- System.out.println(e);
- }
- if (found == true)
- break;
- driver.swipe(xStart, yStart, xEnd, yEnd, 100);
- Thread.sleep(1000);
- }
- assertThat(found,is(true));
- assertThat(el,notNullValue());
- el.click();
- }
- }
步骤说明大概如下:
- 准备好必须的capabilities传送给appium服务器端,注意指定app,因为我们不需要重新安装Launcher
- 找到代表整个屏幕的控件,然后通过获取它的location和size属性来计算出滑动开始和结束的坐标。注意开始的坐标如果是屏幕的边界,需要调整下像素(例子中是减去5个像素)以防出错。
- 通过滑动遍历每个页面直到找到目标控件为止。
【转】Appium测试安卓Launcher以滑动窗体获得目标应用的更多相关文章
- Appium測试安卓Launcher以滑动窗口获得目标应用
所谓Launcher,指的是安卓的桌面管理程序,全部的应用图标都放在launcher上面.事实上这是一个非常easy的样例,仅仅是为了验证几点想法而已. 1.实验目的 做这个试验的目的有二 尝试下窗口 ...
- Appium测试安卓apk遇到的问题及解决方法
1.Showing error - “Returned value cannot be converted to WebElement: {ELEMENT=1} 解决方法:https://sqa.s ...
- 使用appium框架测试安卓app时,获取toast弹框文字时,前一步千万不要加time.sleep等等待时间。
使用appium框架测试安卓app时,如果需要获取toast弹框的文案内容,那么再点击弹框按钮之前,一定记得千万不要加time.sleep()等待时间,否则有延迟,一直获取不到: 获取弹框的代码: m ...
- 一文带你趟过mac搭建appium测试环境的遇到的坑
做UI自动化,最难的一步就是在环境搭建上,怎么去搭建一个UI自动化测试的环境,会难住很多人,在Mac上搭建appium如何搭建呢,本文带着大家去领略如何在mac上搭建appium测试环境.下面就是详细 ...
- Qt使用QGraphicsView实现滑动窗体效果
QGraphicsView用来显示一个滚动视图区的QGraphicsScene内容.QGraphicsScene提供了QGraphicsItem的容器功能.通常与QGraphicsView一起使用来描 ...
- 【亲测】Appium测试Android混合应用时,第二次切换到WebView失败
要解决的问题:Appium测试Android混合应用时,第二次切换到WebView时失败 原因分析:在用Appium测试Android混合应用时,当程序第一次切换到WebView时,可以正常进行自动化 ...
- leetcode ---双指针+滑动窗体
一:Minimum Size Subarray Sum(最小长度子数组的和O(N)) 题目: Given an array of n positive integers and a positive ...
- Appium使用Python运行appium测试的实例
Appium使用Python运行appium测试的实例 一. Appium之介绍 https://testerhome.com/topics/8038 详情参考--https://testerhom ...
- 滑动窗体的最大值(STL的应用+剑指offer)
滑动窗体的最大值 參与人数:767时间限制:1秒空间限制:32768K 通过比例:21.61% 最佳记录:0 ms|8552K(来自 ) 题目描写叙述 给定一个数组和滑动窗体的大小.找出全部滑动窗体里 ...
随机推荐
- 开源Math.NET基础数学类库使用(10)C#进行基本数据统计
原文:[原创]开源Math.NET基础数学类库使用(10)C#进行基本数据统计 本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p ...
- JDBC调用存储过程
一. JDBC调用存储过程 (1)使用存储过程SQL编写的程序代码,等一段语句和控制流语句.在创建时被编译成机器代码和存储在数据库中的client转让. 存储过程具有以下优势: 1.所生成的机器代码被 ...
- ECharts SSH+JQueryAjax+Json+JSP在数据库中的数据来填充ECharts在
1导入包.设定SSH框架. 进口JQuery的JS包.<script src="JS/jquery-1.7.1.js"></script> 导入EChart ...
- Oracle listener lsnrctl
lsnrctl(Listener Control)是一家SQL*Net具,用于控制数据库listener,此工具提供了控制命令listener开端.停止,查看listener状态,更改listener ...
- android 反编译,反,注射LOG
反编译smali注射显示LOG该代码.以后使用: .class public Lnet/iaround/connector/DebugClass; .super Ljava/lang/Object; ...
- quick-cocos2d-x游戏开发【3】——display.newSprite创建向导
游戏嘛.没有图片没有图片可以称为你的游戏,所以,我们看一下使用quick如何创建精灵的方式. quick的api精灵族的创造仍然是非常具体的解释.因此,建立非常easy. display.newSpr ...
- state-of-the-art implementations related to visual recognition and search
http://rogerioferis.com/VisualRecognitionAndSearch2014/Resources.html Source Code Non-exhaustive lis ...
- 不一样的是不一样的,我的独家滚动条------Day35
在您开始建立自己的,感觉应该先录一个概念:内核的浏览器. 兼容性问题之前多次提及,而在平时经常会遇到兼容性问题.原因,就在于它:浏览器内核.这是比較通俗的说法,事实上应该把它描写叙述的专业点:Rend ...
- 在win7在结构cocos2d-x v3.2rc0开发环境(For Android)
cocos2d-x 这是现在比较流行的游戏引擎., 因此.本文的目的在于教导新手怎样在win7下建立cocos2dx开发环境, 截止本文,cocos2dx的最新版本号为 v3.2rc0版,我将如果您的 ...
- LInq 与lambda表达式
LInq 与lambda表达式 LinQ是我们常用的技术之一.因为我们绕不开的要对数据进行一系列的调整,如 排序. 条件筛选.求和.分组.多表联接 等等. lambda则是我们常用的语法糖,配合lin ...