Ⅰ appium脚本如何让点击一个按钮无限次数
//代码如源下 //开始按钮_点击操作 功能 开始_点击() while(1)//表示无限循环 keyboard.keypress(69,1)//按键码,69表示E help.sleep(800)//延时1000=1秒 endwhile 功能结束
Ⅱ Appium进行自动化测试的时候,始终无反应,也没有日志输出,请问什么原因
1. 启http服务器:127.0.0.1:4723 2. 根据测试代码setUp()进行初始化http服务器建立session象; 3. 始调用adb找连接设备设置设备id 猜测:我连接模拟器设备呢第二篇文章命令行启使用-U参数指定某设备我现图形界面启没指定设备 4. 等待设备准备响应命令 相关命令: c1: adb.exe -s emulator-5554 wait-for-device c2: adb.exe -s emulator-5554 shell "echo 'ready'" 5.启logcat志监控 java -jar appium\node_moles\appium\lib\devices\android\helpers\strings_from_apk.jar aimsi.apk c:\windows\temp\com.example.aimsi 条命令读取apk文件些apk基本信息json描述我例: { "app_name" : "Aimsi", "menu_settings" : "Settings", "title_activity_main" : "MainActivity", "RbtnImsi" : "汉字", "RtxtImsi" : "IMSI_IMEI" } apk属性信息文件strings.json存设备目录: c3:adb.exe -s emulator-5554 push "c:\\windows\\temp\\com.example.aimsi\\strings.json" /data/local/tmp 6.读取apk安装情况 c4:adb.exe -s emulator-5554 shell "pm list packages -3 com.example.aimsi" 读结我前已经安装apk 7.端口映射发给appium httpserver内容经httpserver直接发给设备 c5:adb.exe -s emulator-5554 forward tcp:4724 tcp:4724 8. 弄appiumjar包设备 c6:adb.exe -s emulator-5554 appium\node_moles\appium\build\android_bootstrap\appiumbootstrap.jar /data/local/tmp 网络bootstrap:Bootstrap 快速发Web应用程序前端工具包CSSHTML集合,使用新浏览器技术,给Web发提供尚版式 9.哇k安装unlock_apk-debug.apk c7:adb.exe -s emulator-5554 install appium\node_moles\appium\build\unlock_apk\unlock_apk-debug.apk apk用解锁屏幕解锁apk使其调试我猜者吧运行测试程序候看看手机没apk知道 10.kill掉所uiautomator进程 c8:adb.exe -s emulator-5554 shell "ps|grep 'uiautomator'" 我模拟器没启进程 11.执行bootstrap c9:adb.exe -s emulator-5554 uiautomator runtest appiumbootstrap.jar -c io.appium.android.bootstrap.bootstrap 帝原谅我没管写面紧跟着uiautomator输 12.bootstrap始工作 socket打4724端口appiumsocket服务器准备绪 加载json,唤醒客户端 等我想想设备apk--设备bootstrap--pcappium http server--测试程序先姑且猜着吧 13. 所设备运行窗口都输志文件判断设备已经解锁继续 c10:adb.exe -s emulator-5554 shell "mpsys window" 志文件写pc:appium\node_moles\appium\.mpsys.log 14.启测试程序 c11:adb.exe -s emulator-5554 shell "am start -S -n com.example.aimsi/.MainActivity" 15.等待测程序获焦点处超60s模拟器太慢居读两窗口才启功 16.创建session记初候根据setup提交给appium httpserver东东吧sessionid维持工作队列bootstrap队列面取命令执行像知道队列pc设备我觉像pc; 面些内容没啥看非步步调用 说啥研究些东西仔细做技术尤其测试技术原则用少搞明白底细遇问题候处理起快 吧
Ⅲ 哪位大神知道怎么用appium实现引导页的滑动,并且成功跳转到主界面
通过获取屏幕的尺寸大小,然后通过swipe进行滑动,具体代码如下:
fromappiumimportwebdriver
fromtimeimportsleep
capabilites={
"platformName":"Android",
"platformVersion":"5.1.1",
"deviceName":"aa19503",
"app":"F:\mukewang.apk",
}
driver=webdriver.Remote('
#获取屏幕宽和高
defget_size():
size=driver.get_window_size()
width=size['width']
height=size['height']
returnwidth,height
#向左滑动
defswipe_left():
x1=get_size()[0]/10*9
y1=get_size()[1]/2
x=get_size()[0]/10
sleep(3)
driver.swipe(x1,y1,x,y1)
swipe_left()
Ⅳ appium+java处理alertDialog失败
知识点:
1、利用反射,阻止AlertDialog每次的dismiss事件;
在使用AlertDialog的时候,我们设置positive,negative和neutral的button,在点击之后,即使不手动调用dismiss方法,系统都会自动的帮我们dismiss掉了。
但是我这里可能点击了之后,还有一些时间比较长的工作处理之后,才能够dismiss掉此AlertDialog;那么这就是一个问题了。我们先直接看怎么来阻止这个系统的dismiss事件。
话不多述,我们直接先上代码,看看如何操作的,然后在稍微看看源码,一探究竟:
首先是来一个button,设置点击事件,弹出dialog
[java]view plain
@Override
publicvoidonClick(Viewv){
switch(v.getId()){
caseR.id.btn_rDialog:
showDialog();
break;
}
}
然后在activity里头,创建showDialog方法,如下:
[java]view plain
/**
*利用反射,阻止dialog点击确定或者取消按钮,总是会使得dialog消失的结果
*/
voidshowDialog(){
AlertDialogalertDialog=newAlertDialog.Builder(this)
.setTitle("title")
.setMessage("content")
.setIcon(R.drawable.__leak_canary_icon)
.setPositiveButton(R.string.ok,
newDialogInterface.OnClickListener(){
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
//就算阻止了dialog的dismiss事件,这里调用dismiss也还是可以dismiss掉dialog的
//dialog.dismiss();
}
})
.setNegativeButton(R.string.cancel,newDialogInterface.OnClickListener(){
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
dialog.dismiss();
}
}).create();
alertDialog.setCanceledOnTouchOutside(false);
setDialogCancelable(alertDialog);
//setDialogIsCanceled(alertDialog,false);
/*显示对话框*/
alertDialog.show();
}
/**
*通过重新设置一个button处理类,达到点击确定按钮不dismiss掉dialog的效果
*
*@paramalertDialogalertDialog
*/
voidsetDialogCancelable(AlertDialogalertDialog){
try{
Fieldfield=alertDialog.getClass().getDeclaredField("mAlert");
field.setAccessible(true);
/*获得mAlert变量的值*/
Objectobj=field.get(alertDialog);
field=obj.getClass().getDeclaredField("mHandler");
field.setAccessible(true);
/*修改mHandler变量的值,使用新的ButtonHandler类*/
field.set(obj,newIButtonHandler(alertDialog));
}catch(Exceptione){
e.printStackTrace();
}
}
/**
*通过获取mShowing字段,修改它的值,达到点击确定按钮不dismiss掉dialog的效果
*但是好像是没有用的,不起效果
*
*@paramalertDialogalertDialog
*@=此dialog已经关闭了,反之则是为关闭
*/
voidsetDialogIsCanceled(AlertDialogalertDialog,booleanisCanceled){
try{
/*这里有一个层级关系需要记住,看字段是属于父类,还是属于父类的父类*/
Fieldfield=alertDialog.getClass()
.getSuperclass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
/*将mShowing变量设为false,表示对话框已关闭*/
field.set(alertDialog,isCanceled);
alertDialog.dismiss();
}catch(Exceptione){
e.printStackTrace();
}
}
还有涉及到一个IButtonHandler的类
[java]view plain
packagecom.yaojt.ui.reflect;
importandroid.content.DialogInterface;
importandroid.os.Handler;
importandroid.os.Message;
importjava.lang.ref.WeakReference;
/**
*desc:自定义的dialog点击按钮事件处理机制
*<p>
*author:kuyu.yaojt(tanksu)
*<p>
*email:[email protected]
*<p>
*date:17/3/7
*/
{
/*使用弱引用,避免内存泄漏*/
privateWeakReference<DialogInterface>mDialog;
/**
*构造方法
*
*@paramdialogdialog
*/
publicIButtonHandler(DialogInterfacedialog){
mDialog=newWeakReference<>(dialog);
}
@Override
publicvoidhandleMessage(Messagemsg){
switch(msg.what){
caseDialogInterface.BUTTON_POSITIVE:
caseDialogInterface.BUTTON_NEGATIVE:
caseDialogInterface.BUTTON_NEUTRAL:
((DialogInterface.OnClickListener)msg.obj).onClick(mDialog.get(),msg.what);
break;
/**
*AlertController,最终都会调用以下代码,并且传入MSG_DISMISS_DIALOG标志
*//
mHandler.obtainMessage(IButtonHandler.MSG_DISMISS_DIALOG,mDialog)
.sendToTarget();
然后到下面代码
//以下是原始的ButtonHandler类可以看到最后的最后,都会走到这一个入口里去了
导致所有的dialog方法都会被dismiss掉,只要拦截这个就可以了。做法就是重新定义一个ButtonHandler
设置取代原来的ButtonHandler实例即可。有一点不好那就是会影响到所有的dialog。
但是我们在确定监听里头是调用dismiss,是可以dismiss掉dialog的
其实就是不要dismiss的这个方法入口
{
//ButtonclickshaveMessage.whatastheBUTTON{1,2,3}constant
privatestaticfinalintMSG_DISMISS_DIALOG=1;
privateWeakReference<DialogInterface>mDialog;
publicIButtonHandler(DialogInterfacedialog){
mDialog=newWeakReference<>(dialog);
}
@(Messagemsg){
switch(msg.what){
caseDialogInterface.BUTTON_POSITIVE:
caseDialogInterface.BUTTON_NEGATIVE:
caseDialogInterface.BUTTON_NEUTRAL:
((DialogInterface.OnClickListener)msg.obj).onClick(mDialog.get(),msg.what);
break;
caseMSG_DISMISS_DIALOG:
((DialogInterface)msg.obj).dismiss();
}
}
}
*/
}
}
}
代码就是以上这些,都有注释的了。
反射确实挺好用的,可以在运行时动态地加载一个类,然后调用执行类里面的方法,在高级开发中,这个是必须的技能,要好好学习。
另外,这个也是有风险的做法,其他人也可以使用这个来获取到你的类的相关信息,然后做一些坏事什么的。
阅读全文