Appium測试安卓Launcher以滑动窗口获得目标应用
所谓Launcher,指的是安卓的桌面管理程序,全部的应用图标都放在launcher上面。事实上这是一个非常easy的样例,仅仅是为了验证几点想法而已。
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传送给appiumserver端。注意指定app,由于我们不须要又一次安装Launcher
- 找到代表整个屏幕的控件,然后通过获取它的location和size属性来计算出滑动開始和结束的坐标。
注意開始的坐标假设是屏幕的边界,须要调整下像素(样例中是减去5个像素)以防出错。
- 通过滑动遍历每一个页面直到找到目标控件为止。
作者 |
自主博客 |
微信 |
CSDN |
天地会珠海分舵 |
服务号:TechGoGoGo 扫描码: |
http://blog.csdn.net/zhubaitian |
Appium測试安卓Launcher以滑动窗口获得目标应用的更多相关文章
- 【转】Appium测试安卓Launcher以滑动窗体获得目标应用
原文地址:http://blog.csdn.net/zhubaitian/article/details/39755553 所谓Launcher,指的是安卓的桌面管理程序,所有的应用图标都放在laun ...
- Appium - WebView測试(Android)
Appium - WebView測试 作者: Max.Bai 时间: 2015/07 Appium - WebView測试(Android) 如今App都是混合型的.有原生的也包括WebView的,a ...
- (4.5.4)Android測试TestCase单元(Unit test)測试和instrumentationCase单元測试
Android单元和instrumentation单元測试 Developing Android unit and instrumentation tests Android的单元測试是基于JUnit ...
- [DeeplearningAI笔记]卷积神经网络3.1-3.5目标定位/特征点检测/目标检测/滑动窗口的卷积神经网络实现/YOLO算法
4.3目标检测 觉得有用的话,欢迎一起讨论相互学习~Follow Me 3.1目标定位 对象定位localization和目标检测detection 判断图像中的对象是不是汽车--Image clas ...
- MAC中在eclipse luna上搭建移动平台自己主动化測试框架(UIAutomator/Appium/Robotium/MonkeyRunner)关键点记录
这几天由于原来在用的hp laptop的电池坏掉了,机器一不小心就断电.所以仅仅能花时间在自己的mackbook pro上又一次搭建整套环境.大家都知道搭建好开发环境是个非常琐碎须要耐心的事情,特别是 ...
- Appium IOS 自己主动化測试初探
手机平台的自己主动化測试工具非常多,之前研究过了安卓和苹果的原生自己主动化測试框架.经一些同事介绍,貌似Appium是个不错的工具. 想记录一下研究的结果,也算是篇干货的文章 在网上也看了一些视频.个 ...
- iOS自己主动化測试的那些干货
前言 假设有測试大佬发现内容不正确.欢迎指正,我会及时改动. 大多数的iOS App(没有持续集成)迭代流程是这种 也就是说.測试是公布之前的最后一道关卡.假设bug不能在測试中发现,那么bug 就会 ...
- 【Android开发-6】了解内情,我们须要一些调试和測试手段
前言:人生不可能十全十美,总会有些遗憾存在,经历过遗憾,我们才懂的什么是生活. 程序也一样.追求完美,就必定会有经历bug存在的时候. 经历过不断的bug磨练.我们技术才会不断的成长.对于调试bug, ...
- Android单元測试之JUnit
随着近期几年測试方面的工作慢慢火热起来.常常看见有招聘測试project师的招聘信息.在Java中有单元測试这么一个JUnit 方式,Android眼下主要编写的语言是Java,所以在Android开 ...
随机推荐
- Java基础(四):Java Number & Math 类、Character 类、String 类、StringBuffer & StringBuilder 类
一.Java Number & Math 类: 1.Number类: 一般地,当需要使用数字的时候,我们通常使用内置数据类型,如:byte.int.long.double 等.然而,在实际开发 ...
- html 空白汉字占位符
可以看作一个空白的汉字 == 普通的英文半角空格 == == == no-break space (普通的英文半角空格但不换行) == 中文全角空格 (一个中文宽度) == ...
- 【Linux】Linux中 “there are stopped jobs”问题的解决方案
在用管理员执行一个命令后,我用Ctrl+Z把命令转移到了后台天.导致我无法退出root的. 输入命令:logout终端显示:There are stopped jobs. 解决方法:输入命令:jobs ...
- kettle利用参数遍历执行指定目录下的所有对象
使用kettle设计ETL设计完成后,我们就需要按照我们业务的需要对我们设计好的ETL程序,ktr或者kjb进行调度,以实现定时定点的数据抽取,或者说句转换工作,我们如何实现调度呢? 场景:在/wor ...
- Office WORD如何在图片上添加文字
如图所示,在图片格式中选择图片衬于文字下方即可,这样看起来感觉就像在图片上直接加字一样,没有生硬的感觉. 最终效果: Word如何在图片上添加文字Word如何在图片上添加文字Word如何在图片上添加文 ...
- mv命令(转)
原文:http://www.cnblogs.com/peida/archive/2012/10/27/2743022.html mv命令是move的缩写,可以用来移动文件或者将文件改名(move (r ...
- 用 Eclipse 插件提高代码质量
如果能在构建代码前发现代码中潜在的问题会怎么样呢?很有趣的是,Eclipse 插件中就有这样的工具,比如 JDepend 和 CheckStyle,它们能帮您在软件问题暴露前发现这些问题.在 让开发自 ...
- Android中onTouch与onClick事件的关系
这几天遇到点关于Android的触摸事件相关的,还跟onClick有关.暂且记下: LinearLayout分别设置了onTouchListener,onClickListener,onLongCli ...
- asp.net MVC在IIS7或7.5上的发布问题
按照网上的做法,开启了ISAPI和CGI限制C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll 应用程序池也设置好了,可是就是 ...
- linux too many open files报错
修改方法:vi /etc/security/limits.conf 增加一行,如下: * - nofile 65535 修改vi /etc/ssh/sshd ...