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 构 ...
随机推荐
- webservice之XFire的使用(java调用java)
注意:xfire不支持java.util.List等集合,所以调用webservice传递的参数要为基本类型. 转自:http://zp9245.blog.163.com/blog/static/10 ...
- hdu 1171
求能装入大小为sum/2的背包的最大价值 #include <cstdio> #include <cstdlib> #include <cmath> #includ ...
- 为 PHP 开发者准备的 12 个调试工具
PHP是在实践中发展迅速并被最多使用的脚本语言:包含了诸如详细的文档.庞大的社区.无数可使用的脚本及支持框架等许多特性.PHP提供的这些特性使得它比Python或Ruby等脚本语言更容易上手. 为构建 ...
- javascript (js)中的基本概念
1. 基本数据类型 1.1 number (数字)在js中没有整形和浮点型的区分,所有的数字都是浮点型标识, 采用64位的浮点格式来表示数字.如果数字类型用在字符串连接表达式中,则会自动转换成字符串, ...
- Python中编码问题?
一.键盘输入 raw_input('请输入:'.decode('utf-8').encode('gbk'))raw_input(unicode('请输入:','utf-8').encode('gbk' ...
- POJ 1989
#include <iostream> #define MAXN 10005 using namespace std; bool mark[MAXN]; int main() { //fr ...
- POJ 1552
#include<iostream> using namespace std; int main() { ]; int i,j; ; do{ sum=; ;num[i-]!=&&a ...
- E文阅读
Lesson 9 A cold welcome 冷遇 What does 'a cold welcome' refer to?On Wednesday evening, we went to the ...
- Maven的配置文件pom.xml
Maven的配置文件pom.xml 简介: 什么是POM? POM是项目对象模型(Project Object Model)的简称,它是Maven项目中的文件,使用XML表示,名称叫做pom.xml. ...
- VS2013试用期结束后如何激活
在激活框中输入密钥:BWG7X-J98B3-W34RT-33B3R-JVYW9