手机软件测试工具Robotium使用

合集下载

Robotium 实现滑动解锁

Robotium 实现滑动解锁

1. 测试滑动解锁功能,比较的简单,方法如下;2. 首先根据屏幕坐标,画出9个圆圈区域的中心位置;3. 1-9区域位置相对于"滑动解锁View"的区域位置是;位置1 : x = 1/6, y = 1/6位置2 : x = 3/6, y = 1/6位置3 : x = 5/6, y = 1/6位置4 : x = 1/6, y = 3/6位置5 : x = 3/6, y = 3/6位置6 : x = 5/6, y = 3/6位置7 : x = 1/6, y = 5/6位置8 : x = 3/6, y = 5/6位置9 : x = 5/6, y = 5/6上面讲了这么多了,来实现一个具体例子吧4. 要实现下图的滑动解锁,就让我们来写代码;5. 创建一个viewFetcher类,具体使用函数,touchLock(String viewID, int ... step )package com.example.abc.test;import java.util.ArrayList;import com.robotium.solo.*;import android.app.Activity;import android.app.Instrumentation; import android.os.SystemClock; import android.util.Log;import android.view.MotionEvent; import android.view.View;import android.view.ViewGroup; import android.widget.EditText; import android.widget.NumberPicker;public class ViewFetcher {Solo solo;private final Instrumentation inst;public ViewFetcher(Solo solo, Instrumentation inst) {this.solo = solo;this.inst = inst;}public View getChildView(View view, int id, String viewClass) { View view1 = null;ArrayList<View> viewList = new ArrayList<View>();if(view != null) {ViewGroup viewGroup = (ViewGroup) view;for(int i = 0; i< viewGroup.getChildCount(); i++) {final View child = viewGroup.getChildAt(i);String temp = child.getClass().getName().toString();temp = temp.substring(stIndexOf(".") +1, temp.length());if(temp.equals(viewClass)) {viewList.add(child);}}if(id>viewList.size()-1) {return view1;} else {view1 = viewList.get(id);}}return view1;}public View getViewById(String id) {View view = null;if( id == "") {return view;}try {Activity act = solo.getCurrentActivity();// 获取当前Activityint id1 = act.getResources().getIdentifier(id, "id",solo.getCurrentActivity().getPackageName());// 获取idview = solo.getView(id1);// 得到View} catch (Exception ex) {Log.e("Exception", ex.getMessage());}return view;}public boolean clickById(String id) {View view = getViewById(id);if( view == null) {return false;}solo.clickOnView(view);return true;}public View getChildViewByID(View view, String ID) {ArrayList<View> viewList = new ArrayList<View>();viewList = solo.getViews(view);for (int i = 0; i < viewList.size(); i++) {final View view1 = viewList.get(i);String temp = view1.toString();int index = stIndexOf("app:id/");if (index > 0) {String id = temp.substring(index + 7, temp.length() - 1);if (ID.equals(id)) {return view1;}}}return null;}public void enterTextById(String id, String text) { solo.enterText((EditText) getViewById(id), text); }public void typeTextById(String id, String text) { solo.typeText((EditText) getViewById(id), text);}public void clickViewByXY(View view) {int[] xyLocation = new int[2];view.getLocationOnScreen(xyLocation);final int viewWidth = view.getWidth();final int viewHeight = view.getHeight();final float x = xyLocation[0] + (viewWidth / 2.0f);float y = xyLocation[1] + (viewHeight / 2.0f);solo.clickOnScreen(x, y);}// area = 0 , 点击减少天数// area = 1 , 点击增加天数public void clickNumberPicker(View view, int area) {int[] xyLocation = new int[2];view.getLocationOnScreen(xyLocation);int viewWidth = view.getWidth();int viewHeight = view.getHeight();float x = xyLocation[0] + (viewWidth / 2.0f);float y ;if(area == 0) {y = xyLocation[1] + (viewHeight / 6.0f);} else if (area == 1) {y = xyLocation[1] + (viewHeight / 6.0f * 5.0f);} else {return;}solo.clickOnScreen(x, y);}public void touchLock(String viewID, int ... step ) { View v = getViewById(viewID);touchLock(v, step);}//滑动解锁中对应的点位//****1****2****3****//****4****5****6****//****7****8****9****public void touchLock(View view, int ... step) { //判断一下,滑动步数,至少要2步if(step.length <2) {return;}for(int i=0; i<step.length; i++) {//如果滑动步骤里出现不是对应9宫格的点位,直接退出if(step[i] < 1 || step[i] > 9) {return;}//把每个移动点位-1,对应X Y的数组;step[i] = step[i] -1;}int[] xyLocation = new int[2];view.getLocationOnScreen(xyLocation);int viewWidth = view.getWidth();int viewHeight = view.getHeight();float[] xPoint = new float[9];float[] yPoint = new float[9];//计算滑动解锁页面中,9个圈的中心位置。

Robotium自动化测试框架实用教程(图)

Robotium自动化测试框架实用教程(图)

Robotium⾃动化测试框架实⽤教程(图)⼀、简介Robotium是⼀款国外的Android⾃动化测试框架,主要针对Android平台的应⽤进⾏⿊盒⾃动化测试,它提供了模拟各种⼿势操作(点击、长按、滑动等)、查找和断⾔机制的API,能够对各种控件进⾏操作。

Robotium结合Android官⽅提供的测试框架达到对应⽤程序进⾏⾃动化的测试。

另外,Robotium 4.0版本已经⽀持对WebView的操作。

Robotium 对Activity,Dialog,Toast,Menu 都是⽀持的。

⼆、相关下载源码获取:/p/robotium/源API⽂档:/svn/doc/index.htmlrobotium5.1下载和最新API⽂档:/s/1bnlO8MF官⽅例⼦记事本:/s/1qWLVL72重签名⼯具:/s/1i3H0tKD三、常⽤语法1.等待timeout毫秒⼀个名字为name的Activity启动: waitForActivity(String name, int timeout)实例:assertTrue("⽆法启动启动类", solo.waitForActivity ("MainActivity", 30000));2.Robotium将睡眠设置的毫秒数:sleep(int time)实例:solo.sleep(5000)3.清空EditText的内容:clearEditText(android.widget.EditText editText)实例:solo.clearEditText((EditText)solo.getView ("edtInsertName"))4.根据按钮上的⽂字点击按钮:clickOnButton(String text)实例:solo.clickOnButton("^绿⾊$");5.根据⽂字点击控件:clickOnText(String text)实例:solo.clickOnText("控件上显⽰⽂字");6.输⼊内容:enterText(android.widget.EditText editText, String text)solo.enterText((EditText)solo.getView("edtInsertName"), "说些什么好呢?");7.返回:goBack()8.截屏并保存为设置的名字:takeScreenshot(String name)默认保存在: /sdcard/Robotium-Screenshots/9.解锁屏幕:unlockScreen()四、实战-针对APK进⾏的测试被测试项⽬为,下⾯是实战的具体步骤1. 配置ANDROID_HOM E为android sdk的安卓⽬录,例如:D:\android-sdk2. 在path下添加这两个:%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;3. 需要把APK重新签名,因为robotium要求被测应⽤和测试代码要有⼀致的签名, 所以我们需要把下载到的apk,通过re-sign.jar来产⽣debug key的apk,这个重新⽣成的apk就会跟测试项⽬签名⼀致了4. 下载完后,需要配置ANDROID_HOME,就是安卓SDK的位置,然后把APK拉到图标上,就会⾃动⽣成⼀个debug key的apk,如果⽆法直接单击re-sign.jar运⾏,需要切换到放置该jar⽂件的⽬录,cmd执⾏java -jar re-sign.jar产⽣新apk的过程中会弹出⼀个信息框,记得截下图,因为⾥⾯有两个信息我们等会的代码中需要⽤到5. 安装产⽣的apk。

robot framework使用方法

robot framework使用方法

robot framework使用方法Robot Framework使用方法1. 简介Robot Framework是一个开源的自动化测试框架,使用关键字驱动的方法编写测试用例。

它具有简单易学、灵活可扩展和跨平台等特点,被广泛用于软件测试领域。

2. 安装要开始使用Robot Framework,首先需要进行安装。

以下是安装的步骤:1.安装Python:Robot Framework是基于Python开发的,所以需要先安装Python解释器。

2.安装Robot Framework:可以通过pip命令安装RobotFramework,命令为pip install robotframework。

3. 编写测试用例在Robot Framework中,测试用例是通过关键字驱动的方式编写的。

以下是编写测试用例的基本步骤:1.创建测试套件:使用*** Test Cases ***关键字定义一个测试套件,可以包含多个测试用例。

2.添加测试用例:在测试套件中,使用*** Test Case ***关键字定义一个测试用例,然后在下一行写下测试用例的名称。

3.编写关键字:在测试用例中,使用关键字执行不同的操作或断言。

可以使用内置的关键字,也可以自定义关键字。

4.设置变量:使用*** Variables ***关键字定义变量,可以在测试用例中使用这些变量。

4. 运行测试编写完测试用例后,可以通过以下步骤来运行测试:1.在终端中切换到测试套件所在的目录。

2.运行测试套件:使用robot命令,后面跟上测试套件的文件名。

例如,robot。

3.查看测试结果:测试运行完成后,会在终端中显示测试结果摘要,包括测试通过的用例数、失败的用例数等信息。

5. 关键字库关键字库是Robot Framework的一个重要概念,它包含了一组关键字的实现。

可以通过以下方法来使用关键字库:1.导入关键字库:使用Library关键字导入关键字库。

例如,Library ExampleLibrary。

发那科机器人仿真软件ROBOGUIDE 详细操作说明手册

发那科机器人仿真软件ROBOGUIDE 详细操作说明手册

目录第一章概述3 1ROBOGUIDE简介3 2软件安装32.1ROBOGUIDE V8L安装说明32.2新建Work cell 7第二章界面介绍和基本操作15 1界面介绍15 2常用工具条功能介绍16第三章添加设备21 1周边设备的添加211.1Parts 211.2Fixtures 231.3Obstacles 251.4Workers 251.5Machines 262机器人相关设备的添加272.1机器人的添加和更改272.2机器人末端工具的添加282.3机器人DRESSOUT的添加30第四章仿真调试及视频录制32 1Roboguide中的示教盒(TP)32 2Roboguide中示教机器人35 3Roboguide仿真软件中特有的模拟程序(Simulation Program)36 4仿真视频的录制384.1功能按钮394.2Simulation Rate 394.3Display 394.4Control 404.5Collection 404.6AVI Settings 错误!未定义书签。

第一章 概述1ROBOGUIDE简介ROBOGUIDE是发那科机器人公司提供的一款仿真软件,它是围绕一个离线的三维世界进行模拟,在这个三维世界中模拟现实中的机器人和周边设备的布局,通过其中的TP(示教器)进行示教、编程,进一步来模拟它的运动轨迹。

通过这样的模拟可以验证方案的可行性同时获得准确的机器人动作节拍(运动周期时间)。

ROBOGUIDE包括搬运、弧焊、喷涂和点焊等其他子模块。

ROBOGUIDE的仿真环境界面是传统的WINDOWS界面,由菜单栏,工具栏,状态栏等组成。

使用本手册需要对机器人本体及机器人调试有一定基础。

2软件安装2.1ROBOGUIDE 安装说明打开···\Roboguide,双击文件夹下的setup.exe。

首先会弹出如下图的对话框:在安装ROBOGUIDE 前,需要先安装图中所列的组件,点击Install以安装。

robotium工作原理

robotium工作原理

robotium工作原理Robotium是一种用于Android应用测试的自动化测试框架,它的工作原理是通过模拟用户在应用界面上的操作来进行自动化测试。

本文将从Robotium的基本原理、工作流程和实现方式等方面介绍其工作原理。

Robotium基于JUnit框架,通过继承TestCase类来进行测试用例的编写。

它提供了一系列的API方法,可以模拟用户在应用界面上的各种操作,如点击按钮、输入文本、滑动屏幕等。

这些操作是通过调用Android系统提供的UI自动化框架Instrumentation来实现的。

在测试开始之前,需要先安装应用程序,并启动测试Activity。

接着,测试框架会根据编写的测试用例代码,模拟用户的操作来执行测试。

测试用例可以通过查找界面上的控件,如按钮、文本框等,然后调用相应的操作方法来进行操作。

例如,可以通过调用clickOnButton()方法来模拟点击按钮的操作。

在执行测试用例时,Robotium会自动等待应用界面加载完毕后再进行操作,以保证测试的准确性。

同时,它还提供了一些断言方法,用于判断测试结果是否符合预期。

例如,可以使用assertEqual()方法来判断两个字符串是否相等。

除了模拟用户操作外,Robotium还可以获取应用界面上的信息,如控件的文本、大小、位置等。

这些信息可以用于验证测试结果或者辅助测试用例的编写。

例如,可以通过getText()方法获取文本框中的文本内容,然后进行判断或者进一步操作。

在整个测试过程中,Robotium会记录用户的操作和应用界面的状态,并生成相应的日志和报告。

这些日志和报告可以帮助开发人员定位问题,并提供测试结果的可视化展示。

此外,Robotium还支持批量执行测试用例,可以节省测试时间并提高测试效率。

总结来说,Robotium的工作原理是通过模拟用户在应用界面上的操作来进行自动化测试。

它基于JUnit框架,通过继承TestCase类来编写测试用例,使用Android系统提供的UI自动化框架Instrumentation来实现操作的模拟。

Appium简介和使用说明书

Appium简介和使用说明书

1) Explain what is Appium?Appium is a freely distributed open source mobile application UI Testing framework.2) List out the Appium abilities?Appium abilities are•Test Web•Provides cross-platform for Native and Hybrid mobile automation•Support JSON wire protocol•It does not require recompilation of App•Support automation test on physical device as well as similar or emulator both•It has no dependency on mobile device3) List out the pre-requisite to use APPIUM?Pre-requisite to use APPIUM is•ANDROID SDK•JDK•TestNG•Eclipse•Selenium Server JAR•Webdriver Language Binding Library•APPIUM for Windows•APK App Info On Google Play•js4) List out the limitations of using Appium?•Appium does not support testing of Android Version lower than 4.2•Limited support for hybrid app testing. E.g., not possible to test the switching action of application from the web app to native and vice-versa•No support to run Appium Inspector on Microsoft Windows5) Explain how to find DOM element or xPath in a mobile application?To find the DOM element use "UIAutomateviewer" to find DOM element for Android application.6) Explain the design concept of Appium?•Appium is an "HTTP Server" written using Node.js platform and drives iOS and Android session using Webdriver JSON wire protocol. Hence, before initializing the Appium Server, Node.js must be pre-installed on the system•When Appium is downloaded and installed, then a server is setup on our machine that exposes a REST API•It receives connection and command request from the client and execute that command on mobile devices (Android / iOS)•It responds back with HTTP responses. Again, to execute this request, it uses the mobile test automation frameworks to drive the user interface of the apps. Framework like o Apple Instruments for iOS (Instruments are available only in Xcode 3.0 or later with OS X v10.5 and later)o Google UIAutomator for Android API level 16 or highero Selendroid for Android API level 15 or less7) What language does Appium support?Appium support any language that support HTTP request like Java, JavaScript with Node.js, Python, Ruby, PHP, Perl, etc.8) Explain the pros and cons of Appium?Pros:•For programmer irrespective of the platform, he is automating ( Android or iOS) all the complexities will remain under single Appium server•It opens the door to cross-platform mobile testing which means the same test would work on multiple platforms•Appium does not require extra components in your App to make it automation friendly •It can automate Hybrid, Web and Native mobile applicationsCons:•Running scripts on multiple iOS simulators at the same time is possible with Appium•It uses UIAutomator for Android Automation which supports only Android SDK platform, API 16 or higher and to support the older API's they have used another open source library called Selendroid9) Explain what is APPIUM INSPECTOR?Similar to Selenium IDE record and Playback tool, Appium has an "Inspector" to record and playback. It records and plays native application behavior by inspecting DOM and generates the test scripts in any desired language. However, Appium Inspector does not support Windows and use UIAutomator viewer in its option.10) Mention what are the basic requirement for writing Appium tests?For writing Appium tests you require,•Driver Client: Appium drives mobile applications as though it were a user. Using a client library you write your Appium tests which wrap your test steps and sends to the Appiumserver over HTTP.•Appium Session: You have to first initialize a session, as such Appium test takes place in the session. Once the Automation is done for one session, it can be ended and wait for another session•Desired Capabilities: To initialize an Appium session you need to define certain parameters known as "desired capabilities" like PlatformName, PlatformVersion, Device Name and so on. It specifies the kind of automation one requires from the Appium server.•Driver Commands: You can write your test steps using a large and expressive vocabulary of commands.11) Mention what are the possible errors one might encounter using Appium?The possible errors one might face in Appium includes•Error 1: The following desired capabilities are needed but not provided: Device Name, platformName•Error 2: Could not find adb. Please set the ANDROID_HOME environment variable with the Android SDK root directory path•Error 3: openqa.selenium.SessionNotCreatedException: A new session could not be created •Error 4: How to find DOM element or XPath in a mobile application?12) Do you need a server machine to run tests on Appium?No, you don't need server machine to run tests on Appium. Appium facilitates a 2-tier architecture where a test machine connects to a test server running Appium and automating the whole thing. You can have Appium running on the same machine where your test runs.13) Is it possible to interact with my apps using Javascript while I am testing with Appium?Yes, it is possible to interact with App while using Javascript. When the commands run on Appium, the server will send the script to your app wrapped into an anonymous function to be executed.14) Mention what are the most difficult scenarios to test with Appium?The most difficult scenario to test with Appium is data exchange.15) While using Appium can I run my tests in a multithreaded environment?Yes, you can run the test in a multithreaded environment but you have to ensure that no more than one test runs at the same time against the same Appium server.16) In Android, do you need an app's .apk to automate using Appium or you also need app in my workspace?In Android, you only need .apk file to automate using Appium.17) Explain what is Appium package master? How to create package?Appium package master is a set of tools manage and create appium packages. For example to create package you can use the code# using es7/babe1Gulp create-package –n <package-name>#regular es5Gulp create-package ---nobabe1 –n <package-name>The package will be generated in the out/<package-name>18) Explain how test frameworks are supported by Appium?Appium does not support test framework as such there is no need to support them. Appium can be used with any frameworks you want.Guru99 Provides FREE ONLINE TUTORIAL on Various courses like。

手机兼容性测试方案

手机兼容性测试方案

手机兼容性测试方案一、引言手机兼容性测试是为了保证移动应用程序能够在不同的手机设备上正常运行而进行的一项重要测试。

由于不同的手机设备具有不同的操作系统、硬件配置和软件环境,移动应用程序在不同的设备上可能会出现兼容性问题。

因此,进行兼容性测试可以发现并解决这些问题,确保移动应用程序可以在各种手机设备上良好运行。

本文将介绍手机兼容性测试的方案,包括测试目标、测试环境、测试工具、测试用例设计等内容,以帮助测试人员更好地进行手机兼容性测试。

二、测试目标1.确保移动应用程序在主流手机品牌和型号上正常运行;2.发现并解决在特定手机设备上出现的兼容性问题;3.确保移动应用程序在不同的操作系统版本上正常运行;4.验证移动应用程序与手机设备的各种硬件功能的兼容性,如摄像头、GPS、加速度计等;5.确保移动应用程序在各种网络环境下能够正常运行。

三、测试环境1.硬件环境:测试人员需要准备一台或多台具有不同品牌和型号的手机设备,以覆盖主流手机品牌和型号。

同时,还需要准备一台或多台电脑作为测试环境的控制终端,用于远程控制手机设备。

2.软件环境:测试人员需要在测试手机上安装测试工具和测试应用程序,并配置相应的测试环境。

测试工具可以是第三方兼容性测试工具,也可以是自行开发的测试工具。

四、测试工具2. Appium:是一款开源的自动化测试框架,用于测试移动应用程序的兼容性。

3. MonkeyRunner:是由Google官方提供的一款命令行工具,用于测试Android应用程序的兼容性。

4. Selendroid:是一款开源的自动化测试框架,用于测试Android 应用程序的兼容性。

5. Robotium:是一款开源的自动化测试框架,用于测试Android应用程序的兼容性。

以上是一些常用的手机兼容性测试工具,测试人员可以根据具体的测试需求选择合适的工具进行测试。

五、测试用例设计1.硬件功能测试:测试移动应用程序与手机设备的各种硬件功能的兼容性,如摄像头、GPS、加速度计等。

robotium自动化测试框架解析

robotium自动化测试框架解析

脚本录制
• • • • • • 窗口提示starting,开始手机端点击录制。 手机端操作后,在窗口中显示脚本 按照自动化测试用例进行动作录制 录制完成后点击SAVE,保存录制的脚本 填写该case名称,英文 下次如果是工程中新加case ,工程名称一 致,新增工程则同上步骤
脚本加强
• 部分控件recorder无法识别只能手动添加, 如:连接设置 按钮 • 部分动作recorder无法识别只能手动添加, 如:下滑动作 • 部分代码冗余,需要优化 • 具体API见robotium API整理文档
脚本回放
• • • • 运行 选择运行方式 选择运行设备 脚本运行
• 部分脚本跑不过去,需要调试,或者更换 控件的识别方法,具体情况具体分析
测试结果收集
• • • • 只能脚本运行时查看效果 脚本回放失败只能查看 计划编写个公共类,记录日志 计划做个循环失败后仍能跳过继续执行
Robotium的优点
Robotium简介
• Robotium是一款国外的Android自动化测试 框架,主要针对Android平台的应用进行黑 盒自动化测试,它提供了模拟各种手势操 作(点击、长按、滑动等)、查找和断言 机制的API,能够对各种控件进行操作。 Robotium结合Android官方提供的测试框架 达到对应用程序进行自动化的测试。另外 ,Robotium 对Activity,Dialog,Toast, Menu 都是支持的。
Robotium自动化测试框架
用友网络股份有限公司 U8移动及UAP开发部 王兆君 2015年1月4日
yonyouup information technology Co• • • • • •
Robotium简介 Robotium环境搭建 脚本录制 脚本加强 脚本回放 测试结果收集 工具优缺点介绍
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
安装JDK,安装并设置环境变量JAVA_HOME 、CLASSPATH和path 下载解压Eclipse for java工具
下载 Android SDK 解压,运行SDK Manager.exe文件,安装软件包
下载 ADT ,在Eclipse安装ADT插件 在Eclipse设置Android SDK 路径 创建一个新的 Android 虚拟设备AVD (Android模拟器的配置) 在/p/robotium/downloads/list下载相应 版本的robotium jar文件
• • • • 1.使用需要一定的权限如root,USB调试已经启用 2.鼠标右键可以旋转屏幕方向 3.反映数度有一定的延迟 4.下载androidscreencast.jnl
•对应的key值KeyMapping
/p/androidscreencast/wiki/KeyMapping
Eclipse for building Test project
ADT (Android Development Tools) Android SDK (Software Development Kit) Robotium-solo-*.*.*.jar
第5页
Robotium环境搭建
•可以扩充它的API(Java部分),并用python脚本调用这些API, 从而实 现丰富的测试功能。用于API部分可以访问到Android全部API。python又 能灵活部署测试,所以 ASE 的扩展性非常好。 •参考《Android Scripting Environment.pdf》
第16页
第19页
Android测试的辅助工具
DDMS( Dalvik Debug Monitor Service )
•Dalvik调试监视器服务提供例如:为测试设备截屏,针对特定的进程查 看正在运行的线程以及堆信息、Logcat、广播状态信息、模拟电话呼叫 、接收 SMS、虚拟地理坐标等等。DDMS将搭建起IDE与测试终端 (Emulator 或者connected device)的链接,它们应用各自独立的端口监 听调试器的信息,DDMS可以实时监测到测试终端的连接情况。当有新的 测试终端连接后,DDMS将捕捉到终端的ID,并通过adb建立调试器,从而 实现发送指令到测试终端的目的。 •参考《Android DDMS如何使用.pdf》
第21页
Android测试的辅助工具
Androidscreencastcase
•一个适用于Windows/Linux/MacOS平台控制任何android设备,通过USB 连接就可实现鼠标键盘控制你的android. •网址:/p/androidscreencast/ •几点说明:
Android测试的其他手段
Monkey
•Monkey是一个命令行工具, Monkey是运行在模拟器或设备上的一个程 序,用来伪随机地模拟点击和触摸等用户事件,就如其它许多系统事件 一样。Monkey可以用于对我们开发的应用程序进行随机和重复的压力测 试。 •示例:Program Files\Android\android-sdkwindows\docs\guide\developing\tools\monkey.html •参考《Android自动化测试手段之Monkey.pdf》
•使用ADB之前
• 把tools目录下的adb.exe和AdbWinApi.dll两个文件放到系统盘的 windows/system32文件夹里 • 用数据线连接手机或者启动模拟器,然后在命令中使用adb命令
第18页
Android测试的辅助工具
Hierarchy Viewer (层级观察器)
•Hierarchy Viewer是随AndroidSDK发布的工具,位置在tools文件夹下 ,名为hierarchyviewer.bat,是Android自带的非常有用而且使用简单 的工具,可以帮助我们更好地检视和设计用户界面(UI),调试和优化你 的用户界面,是UI检视的利器。 •它可以找到我当前窗口所有的view,并可以查看每个view的属性,查看 每个控件的id,方便编写case。 •参考《UI检视利器:Hierarchy Viewer.pdf》
选择File->New->Project->Android Test Project输入测试工程的名称 ,如:AndroidCalculatorTest。选 择An existing Android Project, 点击Browse按钮,选择之前创建的 被测工程AndroidCalculator,点击 OK按钮。一个测试工程就创建好了 ,如图:
第15页
Android测试的其他手段
CTS
•用来确保某设备符合Android兼容性规范 •参考《Android CTS测试研究.pdf》
ASE(oid Scripting Environment)
•可以通过脚本(如Python)调用Android的功能,从而定制一些测试。
如打电话,发短信,浏览网页等。
第13页
Robotium进行测试的方法和步骤
运行测试程序
选择测试工程AndroidCalculatorTest右击,选择Run As->Android JUnit Test运行测试程序。可以在Run configuration中设置模拟器或设备区运行 测试程序。 运行完后的测试结果界面(Pass)
在使用该工具的时候有一点必须:当编辑完测试脚本后, 会生成一个apk文件,将该apk安装到手机端,并通过abd 输入一系列命令后直接运行测试脚本。但该apk的签名必 须要与测试程序的apk签名保持一致。
第4页
Robotium环境搭建
Robotium使用所需的环境:
JDK (Java Development Kit)
第9页
Robotium进行测试的方法和步骤
导入robotium.jar
选择测试工程AndroidCalculatorTest右击,选择Build Path->Configure Build Path…,在libraries页面中点击Add External JARs按钮。因为之 前创建的工程的SDK是2.2的,所以选择robotium-solo-1.8.0.jar。点击OK 按钮。
第6页
Robotium进行测试的方法和步骤
以一个简单的计算乘法的程序AndroidCalculator作为被测程序 如图所示
第7页
Robotium进行测试的方法和步骤
启动Eclipse执行 File--> Import --> Select root directory,选 择AndroidCalculator项目将被测程序导入进来。 创建一个测试项目AndroidCalculatorTest
第17页
Android测试的辅助工具
ADB (Android Debug Bridge,Android调试桥)
•ADB是androidSdk里的一个通用调试工具, 这个工具可以直接操作管理 android模拟器或者真实设备的状态。还可以进行以下的操作:
• • • • • 在模拟器或设备上安装应用程序的.apk文件 快速更新设备或手机模拟器中的代码,如应用或Android系统升级; 在设备上运行shell命令,访问模拟器或设备; 管理设备或手机模拟器上的预定端口; 在设备或手机模拟器上复制或粘贴文件;
第10页
Robotium进行测试的方法和步骤
为测试用例编写代码
对AndroidCalculator程序进行测试,要实现的一个测试用例如下: 1)访问的第一和第二个编辑域(EditFields) 2)输入选择的测试数据 3)访问和点击multiply按钮 4)验证计算的结果是否符合预期 打开TestMain.java进行编辑并保存,见下图
第11页
第12页
Robotium进行测试的方法和步骤
测试代码的结构
public TestMain() {//构造函数,通知系统要测的app是什么 super("com.calculator", Main.class); } //每一个test case都会调用setup来进行初始化 protected void setUp() throws Exception { super.setUp(); …… } //可以通过tearDown()方法来结束case,可以指定清空或结束此case曾经调用过 的一些资源,如果不写tearDown()方法,系统会调用默认的方法 protected void tearDown() throws Exception{ …… super.tearDown(); } //具体实现测试用例的方法 public void testDisplayBlackBox() { …… } }
第20页
Android测试的辅助工具
MonkeyRunner
•monkeyrunner工具提供了一个API,使用此API写出的程序可以在 Android代码之外控制Android设备和模拟器。通过monkeyrunner,您可 以写出一个Python程序去安装一个Android应用程序或测试包,运行它, 向它发送模拟击键,截取它的用户界面图片,并将截图存储于工作站上 。monkeyrunner工具的主要设计目的是用于测试功能/框架水平上的应用 程序和设备,或用于运行单元测试套件,也可以将其用于其它目的。 •E:\Program Files\Android\android-sdkwindows\docs\guide\developing\tools\monkeyrunner_concepts.html
运行完后的测试结果界面(Fail)
第14页
Robotium进行测试的方法和步骤
在模拟器或者手机上测试
前面的例子在eclipse中进行测试的,也可以在模拟器或者手机上测试。 如果需要直接在模拟器或者手机上测试,需要将测试包和被测试包改成相 同的签名。 关于测试方法可以参考《Test Android APK File With Robotium.pdf》 关于apk包的签名和重签名请参考《重新签名APK文件.pdf》
相关文档
最新文档