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 构 ...
随机推荐
- string为什么可以写入共享内存
我今天在想这个vector,map为什么不能写入共享内存,原来是因为new的时候只是new了这个对象在共享内存上,而真正的堆上的内存并没有在共享内存里面的,如果要想vector 可以共享就要重写分配器 ...
- jquery 插件开发及extend
以下信息是在看了IBM上的一篇文章(使用 jQuery(中级),第 2 部分: 创建自己的插件)http://www.ibm.com/developerworks/cn/web/wa-aj-jquer ...
- Sqli-labs less 28
Less-28 本关考察内容与27关没有太大的差距,我们直接给出一个payload: http://127.0.0.1/sqllib/Less-28/?id=100')union%a0select(1 ...
- URAL 1517 Freedom of Choice(后缀数组,最长公共字串)
题目 输出最长公共字串 #define maxn 200010 int wa[maxn],wb[maxn],wv[maxn],ws[maxn]; int cmp(int *r,int a,int b, ...
- Pots of gold game:看谁拿的钱多
问题描述: Pots of gold game: Two players A & B. There are pots of gold arranged in a line, each cont ...
- Install WindowBuilder for Eclipse
WindowBuilder官方下载安装说明地址:http://www.eclipse.org/windowbuilder/download.php 先祝各位能顺利安装上!以下是基于Eclipse in ...
- 修改DevExpress中英文提示,将英文改为中文
1 : 修改DX 提示框中的英文字符 /// <summary> /// 重写DX弹出框 英文变为中文 /// </summary> public class CHS : De ...
- 几点基于Web日志的Webshell检测思路
http://www.open-open.com/lib/view/open1456751673359.html
- IOS笔记 #pragma mark的用法和作用(方便查找和导航代码)
简单的来说就是为了方便查找和导航代码用的. 下面举例如何快速的定位到我已经标识过的代码. #pragma mark 播放节拍器 - (void) Run:(NSNumber *)tick{ ...
- Linux静态库和动态库
Linux 工具 ❑ GCC: The GNU Compiler Collection, containing the GNU C compiler❑ G++: A C++ compiler, inc ...