package Modules;
import Config.button;
import Config.module_config;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import uiautomatorrpc.UiDevice;
import uiautomatorrpc.UiObject;
import uiautomatorrpc.UiSelector;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Created by qiumin on 2015/8/14.
*/
public class module {
private HashMap<String, button> buttons;
private module_config config;
public Logger logger= LogManager.getLogger(this.getClass());
private final Marker MARKER = MarkerManager.getMarker("MODULE");
public UiDevice device=UiDevice.getInstance();
public Marker get_mark(){return MARKER;}
public void set_map(){
this.buttons=config.set_map();
}
public void set_cfg(module_config cfg) throws Exception{
this.config=cfg;
set_map();
}
public String get_pkg2_cfg(){return config.get_pkg2();}
public String get_pkg_cfg(){return config.get_pkg();}
public String get_apk_name(){return config.get_apk_name();}
public String get_attr(String name){
return this.config.get_attr(name);
}
public module_config.method_sel get_sel(String name){return this.config.get_sel(name);}
public button get_button(String name) throws Exception{
if(buttons.containsKey(name)) {
//logger.debug(MARKER,"'{}' is exist in config map.",name);
return buttons.get(name);
}else{
logger.error(MARKER,"The '{}' is not in config map.",name);
throw new Exception();
}
}
public void print_cfg(){
config.print_cfg();
}
public void open_apk() throws Exception{
boolean find=false;
logger.info(MARKER,"apk name is '{}'",config.name);
try {
find = scroll_find(config.name, false);
find = new UiObject(new UiSelector().text(config.name)).exist();
logger.info("find is {}",find);
if(!find){
for(int i=0;i<15;i++){
device.swipe(585, 360, 180, 360, 20);
find = new UiObject(new UiSelector().text(config.name)).exist();
if(find){
logger.info("finally find apk,click it");
click_button(new UiObject(new UiSelector().text(config.name)));
this.clicks("D1");
return;
}
logger.info("open-apk : {}",i);
}
}else {
logger.info("Click open apk");
click_button(new UiObject(new UiSelector().text(config.name)));
}
}catch (Exception e){
logger.error(MARKER," can't find '{}' .",config.name);
throw e;
} catch (Throwable e) {
e.printStackTrace();
logger.error(MARKER," ~ can't find '{}' .",config.name);
}
}
public void check_if_terminated() throws Exception{
clicks("D5");
String real_pkg=get_current_pkg();
if(real_pkg.contains(config.pkg)){
logger.info(MARKER, "The package name is correct. this apk is running correctly.");
}else {
logger.error(MARKER,"The package name is not correct (real({}) vs expect({})), this apk is not running correctly.",real_pkg,config.pkg);
throw new Exception();
}
}
public void clicks(String btns_in) throws Exception{
String [] btns=btns_in.split("\\|");
logger.debug(Arrays.toString(btns));
for(String btn : btns){
if(btn.contains("D")){
String a=btn.replace("D","");
int n=Integer.parseInt(a);
Thread.sleep(1000*n);
logger.info(MARKER,"Wait for "+n+" seconds.");
}
else if(btn.equals("HOME")){
press_home();
}
else if(btn.equals("BACK")){
press_back();
}
else if(btn.equals("CALL")){
press_call();
}
else if(btn.equals("CAMERA")){
press_camera();
}
else if(btn.equals("NOTIFY")){
open_notification();
}
else if(btn.equals("WAKE")){
wakup();
}
else{
click_button(btn);
}
}
}
public void click_button(String name) throws Exception{
button btn=get_button(name);
UiObject click_obj=button_to_uiobject(btn);
boolean b=button_exist(click_obj);
if(b) {
try {
click_obj.click();
logger.info(MARKER, "Try to click the button '{}' ", name);
// if (!a) {
// throw new Exception();
// }
} catch (Throwable throwable) {
logger.error(MARKER, "Click button '{}'failed.", name);
throw new Exception(throwable);
}
}else{
logger.error(MARKER,"'{}' is configed,but not exist..",name);
throw new Exception();
}
}
public void click_button(button btn) throws Exception{
UiObject click_obj=button_to_uiobject(btn);
boolean b=button_exist(click_obj);
if(b) {
try {
click_obj.click();
logger.info(MARKER, "Try to click the button '{}' ", btn.attribute);
// if (!a) {
// throw new Exception();
// }
} catch (Throwable throwable) {
logger.error(MARKER, "Click button '{}'failed.", btn.attribute);
throw new Exception(throwable);
}
}else{
logger.error(MARKER,"'{}' is configed,but not exist..",btn.attribute);
throw new Exception();
}
}
public void click_button(UiObject obj) throws Exception{
boolean b=button_exist(obj);
if(b) {
try {
obj.click();
logger.info(MARKER, "Try to click a UiObject.");
// if (!a) {
// throw new Exception();
// }
} catch (Throwable throwable) {
logger.error(MARKER, "Click a UiObject Failed.");
throw new Exception(throwable);
}
}else{
logger.error(MARKER,"This uiobject is not exist.");
throw new Exception();
}
}
public void write_button(String name,String text) throws Exception{
button btn=get_button(name);
UiObject write_obj=button_to_uiobject(btn);
boolean b=button_exist(write_obj);
if(b) {
try {
boolean a = write_obj.setText(text);
logger.info(MARKER, "Try to write '" + text + "' in button :" + name);
if (!a) {
throw new Exception();
}
} catch (Throwable throwable) {
logger.error(MARKER, "Write in button '" + name + "'failed.");
throw new Exception(throwable);
}
}else{
logger.error(MARKER,"'{}' is configed,but not exist..",name);
throw new Exception();
}
}
public void write_button(button btn,String text) throws Exception{
UiObject write_obj=button_to_uiobject(btn);
boolean b=button_exist(write_obj);
if(b) {
try {
boolean a = write_obj.setText(text);
logger.info(MARKER, "Try to write '{}' in button : '{}'", text, btn.attribute);
if (!a) {
throw new Exception();
}
} catch (Throwable throwable) {
logger.error(MARKER, "Write in button '{}'failed.", btn.attribute);
throw new Exception(throwable);
}
}else{
logger.error(MA
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Android 项目是使用 Android 操作系统和相关开发工具开发的一款移动应用程序。Android 平台提供了丰富的功能和接口,开发人员可以使用 Java 或 Kotlin 等编程语言编写 Android 应用程序。Android 项目也可以是针对特定设备或特定需求进行自定义开发的软件解决方案。 以下是 Android 项目的一些主要特点和资料介绍: 1. 开放源代码:Android 是基于 Linux 内核的开源操作系统,开发人员可以自由获取、使用和修改源代码。 2. 多样化的硬件设备支持:Android 支持多种硬件设备和屏幕尺寸,可以运行于手机、平板电脑、电视、手表等多种设备上。 3. 灵活的用户界面:Android 提供了丰富的用户界面控件和布局方式,可以实现漂亮、个性化的用户界面。 4. 响应式设计:Android 应用程序可以根据设备类型、屏幕尺寸等因素调整布局和显示方式,以适应不同的设备和用户需求。 5. 多媒体支持:Android 支持常见的音频、视频、图像等多媒体格式,可以实现各种多媒体应用。 6. 数据存储:Android 提供了多种数据存储方式,包括 SQLite 数据库、文件存储、SharedPreferences 等。 7. 网络通信:Android 支持多种网络通信方式,包括 HTTP、TCP、UDP 等。 8. 社交媒体集成:Android 提供了集成社交媒体的功能,可以实现与 Facebook、Twitter、Google+ 等社交媒体的交互。 # 注意 1. 本资源仅用于开源学习和技术交流。 2. 部分字体以及插图等来自网络,若是侵权请联系删除。 3. 不可商用,一切后果由使用者承担。
资源推荐
资源详情
资源评论
收起资源包目录
基于Uiautomator的Android系统测试工具.zip (365个子文件)
${sys 0B
module.class 37KB
base_phone.class 35KB
module.class 35KB
UiSelector.class 12KB
UiSelector.class 12KB
test1.class 11KB
test.class 10KB
base_testcase.class 9KB
UiDevice.class 9KB
base_testcase.class 8KB
UiDevice.class 8KB
Configs.class 8KB
Calculator.class 7KB
base_phone.class 7KB
Configs.class 7KB
Calculate.class 6KB
UiObject.class 6KB
UiObject.class 6KB
Phone_cfg.class 5KB
Phone_cfg.class 5KB
Phone_L676.class 4KB
Call.class 4KB
Messaging_cfg.class 4KB
Messaging_cfg.class 4KB
Call.class 4KB
JsonRpcService.class 4KB
JsonRpcService.class 4KB
module_config.class 4KB
Email_cfg.class 4KB
Email_cfg.class 4KB
module_config.class 3KB
Calculator_cfg.class 3KB
Calculator_cfg.class 3KB
Example.class 3KB
Example.class 3KB
Calendar_cfg.class 3KB
Calendar_cfg.class 3KB
Music_cfg.class 3KB
Music_cfg.class 3KB
Recorder_cfg.class 2KB
Recorder_cfg.class 2KB
Files_cfg.class 2KB
Files_cfg.class 2KB
Contacts_cfg.class 2KB
Contacts_cfg.class 2KB
Call_cfg.class 2KB
Call_cfg.class 2KB
Browser_cfg.class 2KB
Browser_cfg.class 2KB
AdbOperation.class 2KB
Clock_cfg.class 2KB
Clock_cfg.class 2KB
AdbOperation.class 2KB
button.class 2KB
Downloads_cfg.class 2KB
Downloads_cfg.class 2KB
button.class 2KB
Gallery_cfg.class 1KB
Gallery_cfg.class 1KB
JsonRpcServerThread.class 1KB
case06_creditcardbanner.class 1KB
JsonRpcServerThread.class 1KB
case07_creditcardtop5.class 1KB
case02_company_report.class 1KB
case03_person_report.class 1KB
MTBF_case01_contact.class 1KB
case01_download.class 1KB
case04_dishonest.class 1KB
case05_enforce.class 1KB
case08_login.class 1KB
MTBF_case32_camera10.class 1KB
MTBF_case23_camera1.class 1KB
MTBF_case26_camera4.class 1KB
MTBF_case29_camera7.class 1KB
MTBF_case27_camera5.class 1KB
MTBF_case25_camera3.class 1KB
MTBF_case28_camera6.class 1KB
MTBF_case31_camera9.class 1KB
MTBF_case30_camera8.class 1KB
MTBF_case20_recorder.class 1KB
MTBF_case24_camera2.class 1KB
MTBF_case09_email3.class 1KB
MTBF_case33_calculator.class 1KB
MTBF_case10_email4.class 1KB
MTBF_case08_email2.class 1KB
MTBF_case14_browser4.class 1KB
MTBF_case16_browser6.class 1KB
MTBF_case17_browser7.class 1KB
MTBF_case15_browser5.class 1KB
MTBF_case13_browser3.class 1KB
MTBF_case12_browser2.class 1KB
MTBF_case07_email1.class 1KB
MTBF_case18_calendar.class 1KB
MTBF_case22_files.class 1KB
MTBF_case11_browser1.class 1KB
MTBF_case19_clock.class 1KB
MTBF_case21_music.class 1KB
MTBF_case04_sms2.class 1KB
MTBF_case06_mms2.class 1KB
共 365 条
- 1
- 2
- 3
- 4
资源评论
阿齐Archie
- 粉丝: 3w+
- 资源: 2465
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功