android自动化测试工具【UiAutomator】——打开settings实例
2014-04-16 20:04
465 查看
以下为使用UiAutomation打开settings的一个标本实例,来简单说明使用该工具的测试步骤
package com.uia.example.my;
//导入需要的内容
import android.os.RemoteException;
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 LaunchSettings extends UiAutomatorTestCase {
public void testDemo() throws UiObjectNotFoundException, RemoteException {
System.out.println("My first time to use it") ;
// Simulate a short press on the HOME button. 模拟点击home键
getUiDevice().pressHome();
System.out.println("Step 1: Open home screen. ") ;
// We’re now in the home screen. Next, we want to simulate
// a user bringing up the All Apps screen.
// If you use the uiautomatorviewer tool to capture a snapshot
// of the Home screen, notice that the All Apps button’s
// content-description property has the value “Apps”. We can
// use this property to create a UiSelector to find the button. 根据属性来获取一个对象
UiObject allAppsButton = new UiObject(new UiSelector()
.description("Apps"));
getUiDevice().sleep() ;
// Simulate a click to bring up the All Apps screen. //模拟点击来搭载所有程序界面
allAppsButton.clickAndWaitForNewWindow();
System.out.println("Step 2: Bring up the all apps screen. ") ;
// In the All Apps screen, the Settings app is located in
// the Apps tab. To simulate the user bringing up the Apps tab,
// we create a UiSelector to find a tab with the text
// label “Apps”.
UiObject appsTab = new UiObject(new UiSelector()
.text("Apps"));
// Simulate a click to enter the Apps tab. 模拟点击进入所有程序列表
appsTab.click();
System.out.println("Step 3: Enter the apps tab. ") ;
// Next, in the apps tabs, we can simulate a user swiping until
// they come to the Settings app icon. Since the container view
// is scrollable, we can use a UiScrollable object. 使用UiScrollable 设置手机界面显示方向,方便查找需要的程序
UiScrollable appViews = new UiScrollable(new UiSelector()
.scrollable(true));
// Set the swiping mode to horizontal (the default is vertical) 设置界面为水平
appViews.setAsHorizontalList();
System.out.println("Step 4: Set the swiping mode to horizontal. ") ;
// Create a UiSelector to find the Settings app and simulate
// a user click to launch the app. 根据属性className为Settings来获取一个对象
UiObject settingsApp = appViews.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()),
"Settings");
settingsApp.clickAndWaitForNewWindow(); //点击该对象
System.out.println("Step 5: Tap app with name settings. ") ;
// Validate that the package name is the expected one 根据对象的属性来进行验证,比如packageName,text
UiObject settingsValidation = new UiObject(new UiSelector()
.packageName("com.android.settings"));
assertTrue("Unable to detect Settings", //此处根据断言来判断对象是否存在,如果不存在则给出错误提示
settingsValidation.exists());
System.out.println("Step 5555: Test text is: " + settingsValidation.exists()) ;
//verify text
//String sr = new UiSelector.test("Settings") ;
//UiObject settingsValidation = new UiObject(new UiSelector()
// .text("Settings"));
//assertTrue("Unable to detect Settings",
// settingsValidation.exists());
System.out.println("Step 6: Verify this app with text Settings. ") ;
System.out.println("Step 7: Test text is: " + settingsValidation.exists()) ;
}
}
转载来源:http://blog.csdn.net/shandong_chu/article/details/8890224
package com.uia.example.my;
//导入需要的内容
import android.os.RemoteException;
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 LaunchSettings extends UiAutomatorTestCase {
public void testDemo() throws UiObjectNotFoundException, RemoteException {
System.out.println("My first time to use it") ;
// Simulate a short press on the HOME button. 模拟点击home键
getUiDevice().pressHome();
System.out.println("Step 1: Open home screen. ") ;
// We’re now in the home screen. Next, we want to simulate
// a user bringing up the All Apps screen.
// If you use the uiautomatorviewer tool to capture a snapshot
// of the Home screen, notice that the All Apps button’s
// content-description property has the value “Apps”. We can
// use this property to create a UiSelector to find the button. 根据属性来获取一个对象
UiObject allAppsButton = new UiObject(new UiSelector()
.description("Apps"));
getUiDevice().sleep() ;
// Simulate a click to bring up the All Apps screen. //模拟点击来搭载所有程序界面
allAppsButton.clickAndWaitForNewWindow();
System.out.println("Step 2: Bring up the all apps screen. ") ;
// In the All Apps screen, the Settings app is located in
// the Apps tab. To simulate the user bringing up the Apps tab,
// we create a UiSelector to find a tab with the text
// label “Apps”.
UiObject appsTab = new UiObject(new UiSelector()
.text("Apps"));
// Simulate a click to enter the Apps tab. 模拟点击进入所有程序列表
appsTab.click();
System.out.println("Step 3: Enter the apps tab. ") ;
// Next, in the apps tabs, we can simulate a user swiping until
// they come to the Settings app icon. Since the container view
// is scrollable, we can use a UiScrollable object. 使用UiScrollable 设置手机界面显示方向,方便查找需要的程序
UiScrollable appViews = new UiScrollable(new UiSelector()
.scrollable(true));
// Set the swiping mode to horizontal (the default is vertical) 设置界面为水平
appViews.setAsHorizontalList();
System.out.println("Step 4: Set the swiping mode to horizontal. ") ;
// Create a UiSelector to find the Settings app and simulate
// a user click to launch the app. 根据属性className为Settings来获取一个对象
UiObject settingsApp = appViews.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()),
"Settings");
settingsApp.clickAndWaitForNewWindow(); //点击该对象
System.out.println("Step 5: Tap app with name settings. ") ;
// Validate that the package name is the expected one 根据对象的属性来进行验证,比如packageName,text
UiObject settingsValidation = new UiObject(new UiSelector()
.packageName("com.android.settings"));
assertTrue("Unable to detect Settings", //此处根据断言来判断对象是否存在,如果不存在则给出错误提示
settingsValidation.exists());
System.out.println("Step 5555: Test text is: " + settingsValidation.exists()) ;
//verify text
//String sr = new UiSelector.test("Settings") ;
//UiObject settingsValidation = new UiObject(new UiSelector()
// .text("Settings"));
//assertTrue("Unable to detect Settings",
// settingsValidation.exists());
System.out.println("Step 6: Verify this app with text Settings. ") ;
System.out.println("Step 7: Test text is: " + settingsValidation.exists()) ;
}
}
转载来源:http://blog.csdn.net/shandong_chu/article/details/8890224
相关文章推荐
- android自动化测试工具【UiAutomator】——打开settings实例
- android自动化测试工具【UiAutomator】——UiWatcher(一)
- android自动化测试工具【UiAutomator】——使用Indec来定位控件
- Android自动化测试工具 UiAutomator使用详解
- 在Macbook上配置使用Android自动化测试工具uiautomator
- UiAutomator——Android自动化测试工具简要介绍
- android自动化测试工具【UiAutomator】——截图功能
- Android自动化测试工具uiautomator
- android自动化测试工具【UiAutomator】——UiScrollable
- android自动化测试工具【UiAutomator】——UiObject
- Android自动化测试工具汇总
- Android自动化测试中uiautomator修改uiautomatorviewer获取不到动态界面的缺陷
- 关于Android自动化测试工具AnTest的构思
- Android自动化压力测试图解教程——Monkey工具
- Android自动化测试工具——Monkey
- 推荐五款Android 应用的自动化测试工具
- Android自动化测试工具实现简述
- android 自动化测试常用测试框架/工具
- android自动化测试工具简介
- android 4.1 UI 工具测试的新利器, uiautomator