所谓Launcher,指的是安卓的桌面管理程序,全部的应用图标都放在launcher上面。事实上这是一个非常easy的样例,仅仅是为了验证几点想法而已。

1.实验目的

做这个试验的目的有二

  • 尝试下窗口滑动函数swipe的使用
  • 好奇到底能不能正常的对安卓的Launcher进行指定package和activity进行測试

2.实验背景

过程是打算使用appium来启动launcher,然后滑动窗体去获取在第三个桌面的sdk自带应用”Notes“。

例如以下图所看到的


3. 试验步骤

3.1 获得launcher的package和activity两个capabilities

能够通过HierarchyViewer直接查看获得

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

天地会珠海分舵

http://techgogogo.com

服务号:TechGoGoGo

扫描码:

http://blog.csdn.net/zhubaitian



Appium測试安卓Launcher以滑动窗口获得目标应用的更多相关文章

  1. 【转】Appium测试安卓Launcher以滑动窗体获得目标应用

    原文地址:http://blog.csdn.net/zhubaitian/article/details/39755553 所谓Launcher,指的是安卓的桌面管理程序,所有的应用图标都放在laun ...

  2. Appium - WebView測试(Android)

    Appium - WebView測试 作者: Max.Bai 时间: 2015/07 Appium - WebView測试(Android) 如今App都是混合型的.有原生的也包括WebView的,a ...

  3. (4.5.4)Android測试TestCase单元(Unit test)測试和instrumentationCase单元測试

    Android单元和instrumentation单元測试 Developing Android unit and instrumentation tests Android的单元測试是基于JUnit ...

  4. [DeeplearningAI笔记]卷积神经网络3.1-3.5目标定位/特征点检测/目标检测/滑动窗口的卷积神经网络实现/YOLO算法

    4.3目标检测 觉得有用的话,欢迎一起讨论相互学习~Follow Me 3.1目标定位 对象定位localization和目标检测detection 判断图像中的对象是不是汽车--Image clas ...

  5. MAC中在eclipse luna上搭建移动平台自己主动化測试框架(UIAutomator/Appium/Robotium/MonkeyRunner)关键点记录

    这几天由于原来在用的hp laptop的电池坏掉了,机器一不小心就断电.所以仅仅能花时间在自己的mackbook pro上又一次搭建整套环境.大家都知道搭建好开发环境是个非常琐碎须要耐心的事情,特别是 ...

  6. Appium IOS 自己主动化測试初探

    手机平台的自己主动化測试工具非常多,之前研究过了安卓和苹果的原生自己主动化測试框架.经一些同事介绍,貌似Appium是个不错的工具. 想记录一下研究的结果,也算是篇干货的文章 在网上也看了一些视频.个 ...

  7. iOS自己主动化測试的那些干货

    前言 假设有測试大佬发现内容不正确.欢迎指正,我会及时改动. 大多数的iOS App(没有持续集成)迭代流程是这种 也就是说.測试是公布之前的最后一道关卡.假设bug不能在測试中发现,那么bug 就会 ...

  8. 【Android开发-6】了解内情,我们须要一些调试和測试手段

    前言:人生不可能十全十美,总会有些遗憾存在,经历过遗憾,我们才懂的什么是生活. 程序也一样.追求完美,就必定会有经历bug存在的时候. 经历过不断的bug磨练.我们技术才会不断的成长.对于调试bug, ...

  9. Android单元測试之JUnit

    随着近期几年測试方面的工作慢慢火热起来.常常看见有招聘測试project师的招聘信息.在Java中有单元測试这么一个JUnit 方式,Android眼下主要编写的语言是Java,所以在Android开 ...

随机推荐

  1. DialogPlus

    项目地址:https://github.com/orhanobut/dialogplus  Demo地址:https://github.com/baiqiantao/DialogPlusTest co ...

  2. linux文件系统命令(1)---概述

    一.目的 本系列博文将介绍linux文件系统相关的命令. linux文件系统分为4个层面:用户空间程序.系统调用.内核虚拟文件系统以及实际文件系统.本系列文章仅仅涉及用户空间程序的操作及用法.旨在掌握 ...

  3. Leaf - 一个由 Go 语言编写的开发效率和执行效率并重的开源游戏服务器框架

    转自:https://toutiao.io/posts/0l7l7n/preview Leaf 游戏服务器框架简介 Leaf 是一个由 Go 语言(golang)编写的开发效率和执行效率并重的开源游戏 ...

  4. Declaration Merging with TypeScript

    原文:https://blog.oio.de/2014/03/21/declaration-merging-typescript/ Why might you need this? There can ...

  5. 主成分分析(PCA)

    相对与网上很多人分享的有关PCA的经历,我第一次接触PCA却不是从人脸表情识别开始的,但我所在的实验室方向之一是人脸的研究,最后也会回到这个方向上来吧. PCA(principal component ...

  6. 基于XMPP 协议的开发 android

    设计过一款基于开源的XMPP即时通信协议的软件.採用C/S协议,通过GPRS无线网络用TCP协议到server.以架设开源的Openfire server作为即时通讯平台 系统主要由下面部分组成:一是 ...

  7. C#.NET常见问题(FAQ)-程序不包含适合于入口点的静态“Main”方法怎么办

    如下图所示,一般程序上次运行还好好的,而且不管你复制粘贴再简单的程序也出现这种错误提示.   先点击右侧的显示所有文件,下面列举了所有CS文件,右击点击包括在项目中,则该文件呈现绿色,再运行即可.不过 ...

  8. Win10 专业版激活!

    从Win8.1(无论盗版正版),只要符合计算机处理器位数(32或64),就可以 利用: QJNXR-YD97Q-K7WH4-RYWQ8-6MT6Y 激活你的永久Win10,且激活后记录当前设备信息,版 ...

  9. rm 命令(转)

    原文:http://www.cnblogs.com/peida/archive/2012/10/26/2740521.html rm命令.rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件 ...

  10. Android Studio怎样加入工程(project)为library(针对非gradle)

    这篇文章还是针对非gradle build的project,gradle build有一些区别.在Eclipse要引用别的project为本project的library非常easy,可是在Andro ...