Android uiautomator gradle build system
This will guide you through the steps to write your first uiautomator test using gradle as it build system.
What is gradle?
“Gradle combines the power and flexibility of Ant with the dependency management and conventions of Maven into a more effective way to build.”
For more visit gradle page.
What is uiautomator?
“The uiautomator testing framework lets you test your user interface (UI) efficiently by creating automated functional UI testcases that can be run against your app on one or more devices.”
For more visit uiautomator page.
Java source code
Create a directory named bluetooth:
$ mkdir bluetooth
Create a java project layout:
$ cd bluetooth
$ mkdir -p src/main/java/com/github/wiliamsouza/bluetooth
Create a java file BluetoothTest.java with the following content:
package com.github.wiliamsouza.bluetooth;
import java.io.IOException;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class BluetoothTest extends UiAutomatorTestCase {
public void setUp() throws UiObjectNotFoundException, IOException {
getUiDevice().pressHome();
String packageName = "com.android.settings";
String component = packageName + "/.Settings";
String action = "am start -a android.intent.action.MAIN -n ";
// start settings application
Runtime.getRuntime().exec(action + component);
UiObject settingsUi = new UiObject(new UiSelector().packageName(packageName));
assertTrue("Application settings not started", settingsUi.waitForExists(5000));
}
public void testBluetooth() throws UiObjectNotFoundException {
UiScrollable scroll = new UiScrollable(new UiSelector().scrollable(true));
UiObject layout = scroll.getChildByText(new UiSelector().className(android.widget.LinearLayout.class.getName()),"Bluetooth", true);
UiObject switchBluetooth = layout.getChild(new UiSelector().className(android.widget.Switch.class.getName()));
assertTrue("Unable to find bluetooth switch object", switchBluetooth.exists());
switchTo(switchBluetooth, "Bluetooth");
}
private void switchTo(UiObject switchObject, String name) throws UiObjectNotFoundException {
// Before start test ensure switch is off
if (switchObject.isChecked()) {
switchObject.click();
sleep(3000);
}
switchObject.click();
sleep(3000);
assertTrue("Unable to turn " + name + " on", switchObject.isChecked());
switchObject.click();
sleep(3000);
assertFalse("Unable to turn " + name + " off", switchObject.isChecked());
}
}
Gradle
Create a build.gradle with the following content:
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.5
targetCompatibility = 1.5
version = '0.1'
project.ext {
dexDir = new File('build/dex')
distDir = new File('./dist')
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: androidSdkHome + '/platforms/' + androidSdkTarget, include: '*.jar')
compile group: 'junit', name: 'junit', version: '4.11'
}
jar {
doLast {
tasks.dex.execute()
}
}
task dex(dependsOn: jar, type:Exec) {
println 'Building dex...'
project.dexDir.mkdirs()
workingDir '.'
commandLine androidSdkHome + '/' + androidSdkBuildToolsDir + '/' + 'dx', '--dex', '--no-strict', '--output=' + buildDir +'/dex/' + project.name + '.jar', jar.archivePath
doLast {
tasks.dist.execute()
}
}
task dist(dependsOn:dex, type:Copy) {
project.distDir.mkdirs()
from(project.dexDir)
into(project.distDir)
include('*.jar')
}
Configure
Now lets configure the build system, Create a file gradle.properties containing:
androidSdkHome=/home/wiliam/bin/android-sdk-linux
androidSdkTarget=android-18
androidSdkBuildToolsDir=build-tools/18.1.1
- androidSdkHome – Point to the root directory of android SDK.
- androidSdkTarget – Is the target, points to a directory inside platforms.
- androidSdkBuildToolsDir – Location of dx program.
Build
$ gradle build
Install
$ adb push dist/bluetooth.jar /data/local/tmp/
Run
$ adb shell uiautomator runtest bluetooth.jar -c com.github.wiliamsouza.bluetooth.BluetoothTest
Android uiautomator gradle build system的更多相关文章
- 解决Android Studio Gradle Build Running慢的问题
Android Studio方便好用,但是Android Studio Gradle Build Running很慢 解决方法: C:\Users\你的用户名\.gradle 目录下新建一个文件名为 ...
- 解决Android Studio Gradle Build特别慢的问题
解决Android Studio Gradle Build 特别慢的问题 C:\Users\你的用户名\.gradle目录下新建一个文件名为gradle.properties的文件.内容为:org.g ...
- Android Studio Gradle Build Running 特别慢的问题探讨
本文的本本win7 64bit 6G android studio2.1 在运行程序的时候Gradle Build Running 特别慢,一个helloworld都快2min了 1.开启gradle ...
- Android Studio --> Gradle Build设置自动
ps:http://www.cnblogs.com/kangyi/p/4448398.html 应用场景 通常情况下我们的apps发布后也就是release模式下log是不显示的,debug模式下是显 ...
- Android Studio Gradle build 报错:Received status code 400 from server: Bad Request
错误提示如下 Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/ ...
- Android Studio Gradle Build Running 加速
加速效果
- android studio Gradle Build速度加快方法
设置离线编译就可以解决这个问题了.如下图所示:
- Gradle: The New Android Build System
Gradle: The New Android Build System Google selected Gradle as the foundation of the Android SDK bui ...
- Android Gradle 构建工具(Android Gradle Build Tools)是什么?
转载地址:http://mrfu.me/android/2015/07/17/New_Android_Gradle_Build_Tools/ 译者地址:[翻]一览新的 Android Gradle 构 ...
随机推荐
- Swift-6-函数
// Playground - noun: a place where people can play import UIKit // 定义和调用函数 func sayHello(personName ...
- PHP第一课:开发环境配置
最近在学php,大概了解了一下php的语法结构,以及一些php及基础的知识.由此想到了要亲手试一试:以为以前是学java的用的 ide是myeclipse,所以对eclipse软件布局有特别的钟爱. ...
- Sqli-labs less 58
Less-58 执行sql语句后,并没有返回数据库当中的数据,所以我们这里不能使用union联合注入,这里使用报错注入. Payload:http://127.0.0.1/sqli-labs/Less ...
- Ambient Occlusion
一般在光照模型中,ambient light的计算方法为:A = l * m,其中l表示表面接收到的来自光源的ambient light的总量,而m表示表面接收到ambient light后,反射和吸 ...
- POJ 1634 Who's the boss?
题意: 一个员工A的直接上司是那些薪水大于A,并且身高>=A的人中薪水最少的一个. 主席CEO的薪水最高,且身高也是最高的. 有多组数据. 每组数据给出m个员工,和q个询问. 每个员工有id.薪 ...
- swift-网络请求
跟着网上大神写了个,还有待提高啊:http://pan.baidu.com/s/1sjC5Pl7
- Codeforces Round #258 (Div. 2)(A,B,C,D)
题目链接 A. Game With Sticks time limit per test:1 secondmemory limit per test:256 megabytesinput:standa ...
- Visual Studio 自定义控件不显示在工具箱
工具=>选项=>Windows窗体设计器=>常规=>AutoToolBoxPopulate=>True
- eq相等 ,ne、neq不相等 EL表达式
eq相等,ne.neq不相等, gt大于, lt小于 gte.ge大于等于 lte.le 小于等于 not非 mod求模 is [not] div by是否能被某数整除 is [n ...
- 线段树(区间合并) POJ 3667 Hotel
题目传送门 /* 题意:输入 1 a:询问是不是有连续长度为a的空房间,有的话住进最左边 输入 2 a b:将[a,a+b-1]的房间清空 线段树(区间合并):lsum[]统计从左端点起最长连续空房间 ...