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开 ...
随机推荐
- Minimum Window Substring leetcode java
题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...
- Substring with Concatenation of All Words leetcode java
题目: You are given a string, S, and a list of words, L, that are all of the same length. Find all sta ...
- vue当前路由跳转初步研究
一样闲话少说,直接上问题,如图: 也是消息面板,没想到一个小小的消息面板,碰到这么多坑,惆怅. 就是如果当前路由和跳转路由不一样时,正常跳转没有任何问题.但是如果一样时,就不会跳转了,用了很多方法,比 ...
- BZOJ 3732 Network Link-Cut-Tree (我是认真的!!
题目大意:给定一个n个点m条边的无向连通图.k次询问两点之间全部路径中最长边的最小值 LCT的裸题! 首先维护一个动态的最小生成树,然后每次增加边时删除两点间路径上权值最大的边.最后询问时直接求x到y ...
- THINKPHP URL模块大小写导致404问题
最近我使用THINKPHP开发了一个项目在本地的集成开发环境wampserver做开发时并没有出现问题 上传到linux系统也没有出现问题,但当上传到windows平台上就出现了问题"文件4 ...
- Kettle资源库采用SQLserver数据库需要注意的点
Kettle开源ETL工具有着自己的元数据存储方式,可以分为两种 1:File 2:DB 文件存储我这里就不多说了,下面说一下在用SQLserver2008 R2作为资源库在创建的过程中遇到的问题 K ...
- [jQuery] Custom event trigger
$(document).ready(function(){ // Get Weather $('button').on('show.weather', function() { var results ...
- 劣质代码评析——《写给大家看的C语言书(第2版)》附录B之21点程序(八)
[重构](续) 牌的表示: 一副牌有52张,可用一整数数组描述.但是由于在游戏过程中牌数在不断减少,所以用一表示剩余张数的整数和一整数数组共同描述.C99支持一种变量长度数组,但用在这里并没有什么特别 ...
- Discuz常见大问题-如何使用云采集插件
在百度中搜discuz 云采集插件(直接在Discuz官方的插件库中搜可能搜不到) 启用这个插件 随后在任意版块发帖的时候,顶部都会有一个文本框,可以直接放别人博客的帖子,点击获取将生成到你发的帖子中 ...
- 如何自定义CollectionView中每个元素的大小和间距
问题: 让每个元素大小变为104 x 104 Step 1: 在你的视图控制器头文件中实现UICollectionViewFlowLayout协议 eg: @interface XXViewContr ...