运行时出现错误missing before token';' before 'KEYCODE'

[总结] jQuery的datatable插件 使用 问题
$(window).load(function () {$('#managertable').dataTable({&bServerSide&: true,&bAutoWidth&: true,&bStateSave&: false, //保存状态到cookie ******很重要 , 当搜索的时候页面一刷新会导...
$(window).load(function () {
$('#managertable').dataTable({
"bServerSide": true,
"bAutoWidth": true,
"bStateSave": false, //保存状态到cookie ******很重要 , 当搜索的时候页面一刷新会导致搜索的消失。使用这个属性设置为true就可避免了
"bPaginate": true, // 是否使用分页
"bProcessing": true, //是否显示正在处理的提示
"bLengthChange": false, //是否启用设置每页显示记录数
"iDisplayLength": 20, //默认每页显示的记录数
"bFilter": true, //是否使用搜索
"bJQueryUI": true, //页面风格使用jQuery.
// "sScrollY": 200,//竖向滚动条 tbody区域的高度
"sScrollX": "100%", //横向滚动条
"sScrollXInner": "100%",
"bScrollCollapse": true,
"aoColumns": [{ "sTitle": "Id" },
{ "sTitle": "Name" },
{ "sTitle": "Permission" },
{ "sTitle": "Remarks"}],
"sPaginationType": "full_numbers", //分页样式
"bAutoWidth": true, //列的宽度会根据table的宽度自适应
"bSort": false, //是否使用排序
"aaSorting": [[0, "desc"]],
"sAjaxSource": "/action/admin/index.ashx?paraname=admingroupmanager&sub_detail_id=" + $.cookies.get('sub_detail_id')
下面是ajaxsource响应:
[{"Id":1,"Name":"管理员组","Permission":"100,110,120,130,200,210,220,300,310,320,330,400,410,420,430,500,510,520,600,610,620,630,631,632,633,634,640,700,710,720,730,740,800,810,820,830","Remarks":""}]
绑定不上:var aData = _fnGetObjectDataFn( oSettings.sAjaxDataProp )( json ); //这里的json是有响应的数据
for ( var i=0, iLen=aData. i&iL i++ )
这里aData获取到的是:undefined; 这里解决了,
现在出现这个问题:
Showing 1 to NaN of NaN entries (filtered from NaN total entries)
DataTables warning (table id = 'managertable'): Requested unknown parameter '0' from the data source for row 0
红黑联盟&版权所有
Copyright&& 2017
All rights reserved.他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)javascript event keycode (Reprinted) event.keyCode event.keyCode value 37,38,39,40 corresponding keys are pressed left, up, right, down &Javascript: if (event.keyCode &45 | | event.keyCode& 57) event.returnValue =&); if (event.keyco
/ / Enter event $ ('# Qcons_1 [name = Qcon]', _root). Keypress (function (event) ( alert (event.keyCode +&--&+ event.which); var code = event.keyCode | | event. if (code == 13) $ ('# Sal_qt_search', _root). Click (); )); var code = event.k
keyCode key code name implies, English explains: Integer that specifies or receives the Unicode key code, the keyboard keys will eventually be converted into a 0,1 code is communicated to the central processing unit, and then respond to print them ou
keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter keycode 16 = Shift_L keycode 17 = Control_L keycode 18 = Alt_L keycode 19 = Pause keycode 20 = Caps_Lock keycode 27 = Escape Escape keycode 32 = space space key
onkeypress is the user press and release occurs when any alphanumeric key. System buttons (for example, the arrow keys and function keys) can not be identified. onkeyup any prior release in the user key when pressing the keyboard. onkeydown is in the
Just write the AJAX login authentication Use the carriage return call event It is mainly used to write this function, and share it function LoginKeyDown(event) { if (event.keyCode == 13) { // validatorloginName() Here is the press ENTER after calls e
javaScript window.event.keyCode 集合,对于事件的代码获取可以用脚本监听来实现. IE only的监听代码 [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] Ascii 代码表 Ascii 0 {Nulo, Sem Som} Ascii 1 Ascii 2 Ascii 3 Ascii 4 Ascii 5 Ascii 6 Ascii 7 Ascii 8 {BackSpace} Ascii 9 {Tab} Ascii 10 Ascii 11 Ascii 12
event.keyCode值列表大全,对于需要根据键盘按键触发相应事件的朋友需要. 网上收集的KeyCode值方便大家查找: keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter keycode 16 = Shift_L keycode 17 = Control_L keycode 18 = Alt_L keycode 19 = Pause keycode 20 = Ca
js获取键盘按键的键码event.keyCode,下面则是键盘的键码分布,记录一下,以备不时之需 图片版:点击看大图 网上收集的KeyCode值方便大家查找: keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter keycode 16 = Shift_L keycode 17 = Control_L keycode 18 = Alt_L keycode 19 = Paus
press enter javascript to determine whether &Input name = &chatMsg& type = &text& size = &90& onkeypress = &enterHandler (event );&/& function enterHandler (event) ( / / Get the user clicks the keyboard's &quo
Javascript event.keyCode key code value in the table refer to: http://minghao-1130.spaces.live.com/Blog/cns!CD7E552AFCE2F5AF!1438.entry
JS can be used under IE event.keyCode. But is not work under FF. Use only event.which. So you can use this format to determine if (event.which == null keyCode = event.keyC / / IE else if (event.which& 0) keyCode = event. / / All others But
keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter keycode 16 = Shift_L keycode 17 = Control_L keycode 18 = Alt_L keycode 19 = Pause keycode 20 = Caps_Lock keycode 27 = Escape Escape keycode 32 = space space key
Netscape/Firefox/Opera Does not support the window.event.keyCode requires event.which Instead of Because IE is used event.keCode Method gets the current was pressing the keyboard key value, and NetScape/FireFox/Opera Use is event.which Fill in the te
我们之前发过不少关于event.keyCode相关的文章,大家都可以参考下. 主要就是为了监听键盘按下的是哪个键,并且转成ASCII码; &!DOCTYPE html PUBLIC &-//W3C//DTD XHTML 1.0 Strict//EN& &http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&& &html xmlns=&http://www.w3.org/1999/xhtml&
window.event.keyCode兼容IE和Firefox具体实现代码如下,感兴趣的朋友可以参考下哈 HTML代码 &input type=&text& onkeydown=&keyNumAll(event);& & Javascript 代码 复制代码 代码如下: function keyNumAll(evt){ //兼容IE和Firefox获得keyBoardEvent对象 evt = (evt) ? evt : ((window.event)
非常不错的应用,让文本框里只能输入money大家看下具体的实现代码,真是只有想到,原理很简单. &script language=&javascript& type=&text/javascript&& function onlyNum() { if(!(event.keyCode==46)&&!(event.keyCode==8)&&!(event.keyCode==37)&&!(event.keyCod
keycode 0 = keycode 1 = keycode 2 = keycode 3 = keycode 4 = keycode 5 = keycode 6 = keycode 7 = keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 10 = keycode 11 = keycode 12 = Clear keycode 13 = Enter keycode 14 = keycode 15 = keycode 16 =
&body onkeypress=alert(event.keyCode)& Press any key, you will be the key to the key! keycode 0 = keycode 1 = keycode 2 = keycode 3 = keycode 4 = keycode 5 = keycode 6 = keycode 7 = keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 10 = ke
Look at two examples 1, access to any key &html& &!-- Press any key, you will get the key of the key values !--& &body onkeypress=alert(event.keyCode )& &/body& &/html& 2, another example &html& &head& &script
前言: 1.上几次讨论右键禁止等问题的时候,有网友问那里有键值表,我今天写了一个javascript,以飨各位有需要者. 2.适用于ns浏览器和ie浏览器. 3.代码行. &html& &!--//this code by hongseheike--& &head& &script language=&javascript&& ns4 = (document.layers) ? true : ie4 = (document.
The first paragraph: js script /* alin */ /* Email: */ /* QQ: */ /* Creation date:
*/ var myC_x,myC_y; var myC_timeset=null,myC_timeset1= var divObj= var inputN function myCalendar() //Constructing an ob
/**//** * Select the Calendar control by the tiannet derived according to previous experience perfect. Most of the code from meizz calendar control. *tiannet Added timing functions, select ,object Tags hidden features, there are other small features.
/ / Check the existence of page function CheckURL (URL) ( var xmlhttp = new ActiveXObject ( &Microsoft.XMLHTTP&); xmlhttp.Open ( &GET&, URL, false); try ( xmlhttp.Send (); var result = xmlhttp. ) catch (e) (return (false);) if (
JS form input validation scripts * The following is a library function directory and use: * * Common * 1, Trim = remove the spaces before and after the string Usage: String.trim () * 2, ctrim = remove the spaces between the string to use: String.ctri
Pop-up a layer, and then covered with a layer of translucent background. Code is not finishing, but some of the code posted by for reference html, &style type=&text/css&& .show_talk_ajax *{margin:0;padding:0;} .show_talk_ajax{width:500h
New Year's first task at work, responsible copied from the word in the content filtering out format (that is, filter out HTML tag), the use of js to achieve, in the paste key is pressed when the event trigger filter. Details of the code is as follows
Event source object event.srcElement.tagName event.srcElement.type Capture Release event.srcElement.setCapture (); event.srcElement.releaseCapture (); Events button event.keyCode event.shiftKey event.altKey event.ctrlKey Event return values event.ret
&html& &script language=&javascript&& / / Add a double-click event for each Td function ReWritable () ( var tbmian = document.getElementById ( &tbmain&); / / Loop to add each column for each row double-click events, but the
document.all [ 'heading1']. style.fontSize = 'xx-small'; Event source object event.srcElement.tagName event.srcElement.type Capture Release event.srcElement.setCapture (); event.srcElement.releaseCapture (); Events button event.keyCode - Back to keyd
Sum up the regular expression &^\\d+$& // Non-negative integer ( Positive integer + 0) &^[0-9]*[1-9][0-9]*$& // Positive integer &^((-\\d+)|(0+))$& // Non-positive integer ( Negative integer + 0) &^-[0-9]*[1-9][0-9]*$&qu
&html& &script language=&javascript&& // As each TD Add double-click event function ReWritable() { var tbmian=document.getElementById(&tbmain&); // Loop, for each row, each column double-click event , However, the first row
Today, when customers enter that page, do not accidentally click the ESC key, the result of the results clear, and to shield In fact, it is possible, though the strange, JAVASCRIPT can be achieved: &script type=&text/javascript&& document.
Super practical js Code Complete (I) Event source object event.srcElement.tagName event.srcElement.type Capture Release event.srcElement.setCapture (); event.srcElement.releaseCapture (); Events button event.keyCode event.shiftKey event.altKey event.
Note: This article is copied someone else's code, I am not original. ************************************************** ************** Event source object event.srcElement.tagName event.srcElement.type Capture Release event.srcElement.setCapture ();
//1 Reference URL :http://sharejs.com/ 2 Common : 1JS Regular expression code &^\\d+$& // Non-negative integers ( Positive integer + 0) &^[0-9]*[1-9][0-9]*$& // Positive integer &^((-\\d+)|(0+))$& // Non-positive integer ( Ne
&script language=&javascript& type=&text/javascript&& document.onkeypress = function esckey () { if (event.keyCode == 27) / / click on &ESC& key { var message = window.confirm (&Do you want to close this form? clic
Wrote Event source object event.srcElement.tagName event.srcElement.type Capture Release event.srcElement.setCapture (); event.srcElement.releaseCapture (); Events button event.keyCode event.shiftKey event.altKey event.ctrlKey Event return values eve
click () object. click () so that the object is clicked. closed object. closed the window object is off true / false clearTimeout (object) remove the object has been set setTimeout clearInterval (object) to clear setInterval object has been set confi
Event source object event.srcElement.tagName event.srcElement.type Capture Release event.srcElement.setCapture(); event.srcElement.releaseCapture(); Events button event.keyCode event.shiftKey event.altKey event.ctrlKey Event return values event.retur
Want to be a period of time on Baidu and other search automatically prompt completion of the function. So get the point information from the Internet to achieve the first version, but the cursor event did not materialize. So get online and from the p
Results as shown: aaa.html &html& &head& &title& Commodity status data &/title& &script language=&JavaScript& src=&yeardate.js&&&/script& &/head& &body & Date of js control :&input typ
[Example Description Auto-complete input box is a more popular technique, using Ajax technology can not refresh the prompts. This example describes the principle of this technique. &html xmlns=&http://www.w3.org/1999/xhtml& & &head&
自动完成功能是指:类似百度搜索之类的输入一个词的一部分后就自动提示,然后用户可以选择,不需要再输入剩余部分. 废话不多说,直观的看一下: 实现这个功能需要服务端配合.客户端通过脚本来展示从服务端取得的数据. 先看客户端的HTML: &!DOCTYPE html PUBLIC &-//W3C//DTD XHTML 1.0 Strict//EN& &http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&& &lt
鉴于网上找到的几个日期选择程序有些问题,遂着手重写一个程序,添加了时间选择功能,截图及源码如下,有需要的朋友可以参考下 鉴于网上找到的几个日期选择程序有些问题,遂着手重写一个程序,大部分还是借鉴前人的代码,添加了时间选择功能,隐藏会遮挡控件的标签select,object. 开始本想使用window.createPopup()来弹出日历的选择,这样就可以跨过任何标签. 不过做到中途发现用createPopup窗口实现理论上是行不通的: 一是因为不在窗体里单击任何地方都会关闭窗口,而当用下拉框选择
此脚本的功能为将一个目录中的jpg,gif,png格式的图片生成Html相册,页面上的图像只是改变显示大小,并没有生成缩略图. 用到的技术:Scripting.FileSystemObject,Adodb.Stream.其中得到图片长宽用了秋水无恨的Adodb.Stream取得图像的高宽 '/////////////////////////////////////////////// 'VBS相册生成脚本,使用方法:将此文件放在sendto目录中(在运行中输入直接sendto,就可以打开),然后
都是一些非常不错的js 小技巧,学习js的朋友一定要看下,有很多不错的代码. //自定义的apply,call Function.prototype.apply = function (obj, argu) { if (obj) obj.constructor.prototype._caller = var argus = new Array(); for (var i=0;i&argu.i++) argus[i] = &argu[& + i + &qu
这次是更改后的代码实现以下功能:去掉了&确定&,&取消&按钮.变单击为双击事件,用户按ESC键,取消更改感兴趣的朋友可以了解下 客户需求至上. 这次是更改后的代码,去掉了&确定&,&取消&按钮.变单击为双击事件,用户按ESC键,取消更改. //为每个Td添加双击事件 function ReWritable() { var tbmian=document.getElementById(&tbmain&); /
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture(); 事件按键 event.keyCode event.shiftKey event.altKey event.ctrlKey 事件返回值 event.returnValue 鼠标位置 event.x event.y 窗体活动元素 document.acti
event.srcElement.setCapture(); event.srcElement.releaseCapture(); 事件按键 event.keyCode event.shiftKey event.altKey event.ctrlKey 事件返回值 event.returnValue 鼠标位置 event.x event.y 窗体活动元素 document.activeElement 绑定事件 document.captureEvents(Event.KEYDOWN); 访问窗体
Copyright (C) , All Rights Reserved.
版权所有 闽ICP备号
processed in 0.045 (s). 9 q(s)Android 测试工具Monkey & Monkeyrunner 使用方法
程序编写完成后进行测试一定是必不可少的,Android Sdk给我们提供了Monkey和Monkeyrunner这两个自动化测试工具。时光境迁,随着版本的不断更新迭代,Monkey和Monkeyrunner也在不断的改变,改变的速度甚至已经到...
程序编写完成后进行测试一定是必不可少的, Sdk给我们提供了Monkey和Monkeyrunner这两个自动化测试工具。时光境迁,随着版本的不断更新迭代,Monkey和Monkeyrunner也在不断的改变,改变的速度甚至已经到了官方文档有时都跟不上了,这无疑给我们的学习带来很多困扰。
今天我把我近期使用Monkey和Monkeyrunner的一些体会与大家分享,Sdk版本为Rev22.01,Api17(4.22).
Monkey是一个命令行工具,可以运行在模拟器里或实际设备中。它向发送伪随机的用户事件流,实现对正在开发的应用程序进行压力测试。Monkey包括许多选项,它们大致分为四大类:
· 基本配置选项,如设置尝试的事件数量。
· 运行约束选项,如设置只对单独的一个包进行测试。
· 事件类型和频率。
· 调试选项。
二、Monkey的基本用法
基本语法如下:
$ adb shell monkey [options] &event-count&
如果不指定options,Monkey将以无反馈模式启动,并把事件任意发送到安装在目标环境中的全部包。下面是一个更为典型的命令行示例,它启动指定的应用程序,并向其发送500个伪随机事件:
$ adb shell monkey -p your.package.name -v 500
一些常用的参数信息:
命令行的每一个-v将增加反馈信息的级别。Level 0(缺省值)除启动提示、测试完成和最终结果之外,提供较少信息。Level 1提供较为详细的测试信息,如逐个发送到Activity的事件。Level 2提供更加详细的设置信息,如测试中被选中的或未被选中的Activity。
伪随机数生成器的seed值。如果用相同的seed值再次运行Monkey,它将生成相同的事件序列。
--throttle &milliseconds&
在事件之间插入固定延迟。通过这个选项可以减缓Monkey的执行速度。如果不指定该选项,Monkey将不会被延迟,事件将尽可能快地被产成。
--pct-touch &percent&
调整触摸事件的百分比(触摸事件是一个down-up事件,它发生在屏幕上的某单一位置)。
--pct-motion &percent&
调整动作事件的百分比(动作事件由屏幕上某处的一个down事件、一系列的伪随机事件和一个up事件组成)。
--pct-trackball &percent&
调整轨迹事件的百分比(轨迹事件由一个或几个随机的移动组成,有时还伴随有点击)。
--pct-nav &percent&
调整“基本”导航事件的百分比(导航事件由来自方向输入设备的up/down/left/right组成)。
--pct-majornav &percent&
调整“主要”导航事件的百分比(这些导航事件通常引发图形界面中的动作,如:5-way键盘的中间按键、回退按键、菜单按键)
--pct-syskeys &percent&
调整“系统”按键事件的百分比(这些按键通常被保留,由系统使用,如Home、Back、Start Call、End Call及音量控制键)。
--pct-appswitch &percent&
调整启动Activity的百分比。在随机间隔里,Monkey将执行一个startActivity()调用,作为最大程度覆盖包中全部Activity的一种方法。
--pct-anyevent &percent&
调整其它类型事件的百分比。它包罗了所有其它类型的事件,如:按键、其它不常用的设备按钮、等等。
-p &allowed-package-name&
如果用此参数指定了一个或几个包,Monkey将只允许系统启动这些包里的Activity。如果你的应用程序还需要访问其它包里的Activity(如选择取一个联系人),那些包也需要在此同时指定。如果不指定任何包,Monkey将允许系统启动全部包里的Activity。要指定多个包,需要使用多个 -p选项,每个-p选项只能用于一个包。
-c &main-category&
如果用此参数指定了一个或几个类别,Monkey将只允许系统启动被这些类别中的某个类别列出的Activity。如果不指定任何类别,Monkey将选 择下列类别中列出的Activity: Intent.CATEGORY_LAUNCHER或Intent.CATEGORY_MONKEY。要指定多个类别,需要使用多个-c选项,每个-c选 项只能用于一个类别。
--dbg-no-events
设置此选项,Monkey将执行初始启动,进入到一个测试Activity,然后不会再进一步生成事件。为了得到最佳结果,把它与-v、一个或几个包约 束、以及一个保持Monkey运行30秒或更长时间的非零值联合起来,从而提供一个环境,可以监视应用程序所调用的包之间的转换。
设置此选项,将在Monkey事件序列之前和之后立即生成profiling报告。这将会在data/misc中生成大文件(~5Mb),所以要小心使用它。
--ignore-crashes
通常,当应用程序崩溃或发生任何失控异常时,Monkey将停止运行。如果设置此选项,Monkey将继续向系统发送事件,直到计数完成。
--ignore-timeouts
通常,当应用程序发生任何超时错误(如“Application Not Responding”对话框)时,Monkey将停止运行。如果设置此选项,Monkey将继续向系统发送事件,直到计数完成。
--ignore-security-exceptions
通常,当应用程序发生许可错误(如启动一个需要某些许可的Activity)时,Monkey将停止运行。如果设置了此选项,Monkey将继续向系统发送事件,直到计数完成。
--kill-process-after-error
通常,当Monkey由于一个错误而停止时,出错的应用程序将继续处于运行状态。当设置了此选项时,将会通知系统停止发生错误的进程。注意,正常的(成功的)结束,并没有停止启动的进程,设备只是在结束事件之后,简单地保持在最后的状态。
--monitor-native-crashes
监视并报告Android系统中本地代码的崩溃事件。如果设置了--kill-process-after-error,系统将停止运行。
--wait-dbg
停止执行中的Monkey,直到有调试器和它相连接。-v
命令行的每一个-v将增加反馈信息的级别。Level 0(缺省值)除启动提示、测试完成和最终结果之外,提供较少信息。Level 1提供较为详细的测试信息,如逐个发送到Activity的事件。Level 2提供更加详细的设置信息,如测试中被选中的或未被选中的Activity。
伪随机数生成器的seed值。如果用相同的seed值再次运行Monkey,它将生成相同的事件序列。
--throttle &milliseconds&
在事件之间插入固定延迟。通过这个选项可以减缓Monkey的执行速度。如果不指定该选项,Monkey将不会被延迟,事件将尽可能快地被产成。
--pct-touch &percent&
调整触摸事件的百分比(触摸事件是一个down-up事件,它发生在屏幕上的某单一位置)。
--pct-motion &percent&
调整动作事件的百分比(动作事件由屏幕上某处的一个down事件、一系列的伪随机事件和一个up事件组成)。
--pct-trackball &percent&
调整轨迹事件的百分比(轨迹事件由一个或几个随机的移动组成,有时还伴随有点击)。
--pct-nav &percent&
调整“基本”导航事件的百分比(导航事件由来自方向输入设备的up/down/left/right组成)。
--pct-majornav &percent&
调整“主要”导航事件的百分比(这些导航事件通常引发图形界面中的动作,如:5-way键盘的中间按键、回退按键、菜单按键)
--pct-syskeys &percent&
调整“系统”按键事件的百分比(这些按键通常被保留,由系统使用,如Home、Back、Start Call、End Call及音量控制键)。
--pct-appswitch &percent&
调整启动Activity的百分比。在随机间隔里,Monkey将执行一个startActivity()调用,作为最大程度覆盖包中全部Activity的一种方法。
--pct-anyevent &percent&
调整其它类型事件的百分比。它包罗了所有其它类型的事件,如:按键、其它不常用的设备按钮、等等。
-p &allowed-package-name&
如果用此参数指定了一个或几个包,Monkey将只允许系统启动这些包里的Activity。如果你的应用程序还需要访问其它包里的Activity(如选择取一个联系人),那些包也需要在此同时指定。如果不指定任何包,Monkey将允许系统启动全部包里的Activity。要指定多个包,需要使用多个 -p选项,每个-p选项只能用于一个包。
-c &main-category&
如果用此参数指定了一个或几个类别,Monkey将只允许系统启动被这些类别中的某个类别列出的Activity。如果不指定任何类别,Monkey将选 择下列类别中列出的Activity: Intent.CATEGORY_LAUNCHER或Intent.CATEGORY_MONKEY。要指定多个类别,需要使用多个-c选项,每个-c选 项只能用于一个类别。
--dbg-no-events
设置此选项,Monkey将执行初始启动,进入到一个测试Activity,然后不会再进一步生成事件。为了得到最佳结果,把它与-v、一个或几个包约 束、以及一个保持Monkey运行30秒或更长时间的非零值联合起来,从而提供一个环境,可以监视应用程序所调用的包之间的转换。
设置此选项,将在Monkey事件序列之前和之后立即生成profiling报告。这将会在data/misc中生成大文件(~5Mb),所以要小心使用它。
--ignore-crashes
通常,当应用程序崩溃或发生任何失控异常时,Monkey将停止运行。如果设置此选项,Monkey将继续向系统发送事件,直到计数完成。
--ignore-timeouts
通常,当应用程序发生任何超时错误(如“Application Not Responding”对话框)时,Monkey将停止运行。如果设置此选项,Monkey将继续向系统发送事件,直到计数完成。
--ignore-security-exceptions
通常,当应用程序发生许可错误(如启动一个需要某些许可的Activity)时,Monkey将停止运行。如果设置了此选项,Monkey将继续向系统发送事件,直到计数完成。
--kill-process-after-error
通常,当Monkey由于一个错误而停止时,出错的应用程序将继续处于运行状态。当设置了此选项时,将会通知系统停止发生错误的进程。注意,正常的(成功的)结束,并没有停止启动的进程,设备只是在结束事件之后,简单地保持在最后的状态。
--monitor-native-crashes
监视并报告Android系统中本地代码的崩溃事件。如果设置了--kill-process-after-error,系统将停止运行。
--wait-dbg
停止执行中的Monkey,直到有调试器和它相连接。
三、Monkey实例测试
Windows下(注:2—4步是为了查看我们可以测试哪些应用程序包,可省略):
1、 通过eclipse启动一个Android的emulator
2、 在命令行中输入:adb devices查看设备连接情况
List of devices attached
emulator-5554
3、 在有设备连接的前提下,在命令行中输入:adb shell 进入shell界面
4、 查看data/data文件夹下的应用程序包。注:我们能测试的应用程序包都在这个目录下面
com.android.htmlviewer
com.android.settings
com.android.netspeed
com.android.providers.userdictionary
com.android.browser
com.android.contacts
com.android.alarmclock
5.在其中找到我们需要测试的包名com.marshalchen.MonkeyTest1
6、 以com.marshalchen.MonkeyTest1 作为对象进行MonkeyTest
#monkey -p com.marshalchen.MonkeyTest1 -v 500
其中-p表示对象包 &v 表示事件数量
运行过程中,Emulator中的应用程序在不断地切换画面。
按照选定的不同级别的反馈信息,在Monkey中还可以看到其执行过程报告和生成的事件。
如:Sending Pointer ACTION_DOWN x=35.0 y=259.0
:Sending Pointer ACTION_UP x=195.0 y=259.0
:Sending Pointer ACTION_DOWN x=295.0 y=223.0
:Dropped: keys=0 pointers=0 trackballs=0 flips=0
等等信息。
四、Monkey停止的条件
Monkey Test执行过程中在下列三种情况下会自动停止:
1、如果限定了Monkey运行在一个或几个特定的包上,那么它会监测试图转到其它包的操作,并对其进行阻止。
2、如果应用程序崩溃或接收到任何失控异常,Monkey将停止并报错。
3、如果应用程序产生了应用程序不响应(application not responding)的错误,Monkey将会停止并报错。
通过多次并且不同设定下的Monkey测试才算它是一个稳定性足够的程序。
MonkeyRunner 使用
Monkey的使用简洁有效,但是总是给人感觉功能不够强大。所以,接下来向大家介绍非常给力的工具MonkeyRunner。
一、什么是MonkeyRunner
monkeyrunner工具提供了一个API,使用此API写出的程序可以在Android代码之外控制Android设备和模拟器。通过monkeyrunner,您可以写出一个程序去安装一个Android应用程序或测试包,运行它,向它发送模拟击键,截取它的用户界面图片,并将截图存储于工作站上。monkeyrunner工具的主要设计目的是用于测试功能/框架水平上的应用程序和设备,或用于运行单元测试套件,但您当然也可以将其用于其它目的。
monkeyrunner工具与monkey工具并无关联。monkey工具直接运行在设备或模拟器的adbshell中,生成用户或系统的伪随机事件流。而monkeyrunner工具则是在工作站上通过API定义的特定命令和事件控制设备或模拟器。
monkeyrunner工具为Android测试提供了以下特性:
1.多设备控制:monkeyrunner
API可以跨多个设备或模拟器实施测试套件。您可以在同一时间接上所有的设备或一次启动全部模拟器(或统统一起),依据程序依次连接到每一个,然后运行一个或多个测试。您也可以用程序启动一个配置好的模拟器,运行一个或多个测试,然后关闭模拟器。
2.功能测试:
monkeyrunner可以为一个应用自动贯彻一次功能测试。您提供按键或触摸事件的输入数值,然后观察输出结果的截屏。
3.回归测试:monkeyrunner可以运行某个应用,并将其结果截屏与既定已知正确的结果截屏相比较,以此测试应用的稳定性。
4.可扩展的自动化:由于monkeyrunner是一个API工具包,您可以基于Python模块和一整套系统,以此来控制Android设备。除了使用monkeyrunner API之外,您还可以使用标准的Python os和subpress模块来调用如adb这样的Android工具。
您还可以向monkeyrunner API中添加您自己的类。
monkeyrunner工具使用Jython(使用语言的一种Python实现)。Jython允许monkeyrunnerAPI与Android框架轻松的进行交互。使用Jython,您可以使用Python语法来获取API中的常量、类以及方法。
二、一个简单的MonkeyRunner实例
您可以直接使用一个代码文件运行monkeyrunner,抑或在交互式对话中输入monkeyrunner语句。不论使用哪种方式,您都需要调用SDK目录的tools子目录下的monkeyrunner命令。如果您提供一个文件名作为运行参数,则monkeyrunner将视文件内容为Python程序,并加以运行;否则,它将提供一个交互对话环境。
monkeyrunner的命令语法为:
monkeyrunner -plugin &plugin_jar& &program_filename& &program_options&
monkeyrunnerbasic.py:
# 导入此程序所需的monkeyrunner模块
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# 连接当前设备,返回一个MonkeyDevice对象
device = MonkeyRunner.waitForConnection()
# 安装Android包,注意,此方法返回的返回值为boolean,由此您可以判断安装过程是否正常
device.installPackage('myproject/bin/MyApplication.apk')
# 运行此应用中的一个活动device.startActivity(component='com.marshalchen.Monkeyrunner.MainActivity')
# 按下菜单按键
device.press('KEYCODE_MENU','DOWN_AND_UP')
# 截取屏幕截图
result = device.takeSnapShot
# 将截图保存至文件
result.writeToFile('myproject/shot1.png','png')
# 导入此程序所需的monkeyrunner模块
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# 连接当前设备,返回一个MonkeyDevice对象
device = MonkeyRunner.waitForConnection()
# 安装Android包,注意,此方法返回的返回值为boolean,由此您可以判断安装过程是否正常
device.installPackage('myproject/bin/MyApplication.apk')
# 运行此应用中的一个活动device.startActivity(component='com.marshalchen.Monkeyrunner.MainActivity')
# 按下菜单按键
device.press('KEYCODE_MENU','DOWN_AND_UP')
# 截取屏幕截图
result = device.takeSnapShot
# 将截图保存至文件
result.writeToFile('myproject/shot1.png','png')
然后转到$SDK\TOOLS下执行 monkeyrunner monkeyrunnerbasic.py 就可执行测试了。
PS:上述内容,部分参考了 子杨 的博客,在此表示感谢。
三、常用功能的Monkeyrunner python脚本介绍:
1.输入等基本操作测试
import sys
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner import MonkeyDevice as md
from com.android.monkeyrunner import MonkeyImage as mi
#connect device 连接设备
#第一个参数为等待连接设备时间
#第二个参数为具体连接的设备
device = mr.waitForConnection(1.0,'emulator-5554')
if not device:
print && sys.stderr,"fail"
sys.exit(1)
#定义要启动的Activity
componentName='kg.monkey/.MonkeyActivity'
#启动特定的Activity
device.startActivity(component=componentName)
mr.sleep(3.0)
#do someting 进行我们的操作
#输入 a s d
device.type('asd')
device.press('KEYCODE_ENTER')
#return keyboard 点击返回用于取消等下看到截图的下方的白条
#device.press('KEYCODE_BACK')
#takeSnapshot截图
mr.sleep(3.0)
result = device.takeSnapshot()
#save to file 保存到文件
result.writeToFile('takeSnapshot\\result1.png','png');
import sys
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner import MonkeyDevice as md
from com.android.monkeyrunner import MonkeyImage as mi
#connect device 连接设备
#第一个参数为等待连接设备时间
#第二个参数为具体连接的设备
device = mr.waitForConnection(1.0,'emulator-5554')
if not device:
print && sys.stderr,"fail"
sys.exit(1)
#定义要启动的Activity
componentName='kg.monkey/.MonkeyActivity'
#启动特定的Activity
device.startActivity(component=componentName)
mr.sleep(3.0)
#do someting 进行我们的操作
#输入 a s d
device.type('asd')
device.press('KEYCODE_ENTER')
#return keyboard 点击返回用于取消等下看到截图的下方的白条
#device.press('KEYCODE_BACK')
#takeSnapshot截图
mr.sleep(3.0)
result = device.takeSnapshot()
#save to file 保存到文件
result.writeToFile('takeSnapshot\\result1.png','png');
2.图形化记录与回放
SPAN style="FONT-FAMILY: SimSun"&monkeyrunner monkey_recorder.py&/SPAN&
monkeyrunner monkey_recorder.py
脚本,可以打开如图所示可视化模拟器,各种操作可以显示在屏幕右侧,并且通过“Export Actions”导出。
导出之后可以运行monkeyrunner monkey_playback.py monkey_test1.mr,(monkey_test1.mr为刚才保存的脚本),这时可以看到模拟器,进行刚才一样的操作。
补充多设备操作:可以在monkey_playback.py中的main()方法的device设备获取时指定多设备。
下面是这两个有用的脚本:
monkey_recorder.py:
#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
device = mr.waitForConnection()
recorder.start(device)
#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
device = mr.waitForConnection()
recorder.start(device)
monkey_playback.py:
#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from com.android.monkeyrunner import MonkeyRunner
# The format of the file we are parsing is very carfeully constructed.
# Each line corresponds to a single command.
The line is split into 2
# parts with a | character.
Text to the left of the pipe denotes
# which command to run.
The text to the right of the pipe is a python
# dictionary (it can be evaled into existence) that specifies the
# arguments for the command.
In most cases, this directly maps to the
# keyword argument dictionary that could be passed to the underlying
# command.
# Lookup table to map command strings to functions that implement that
# command.
CMD_MAP = {
'TOUCH': lambda dev, arg: dev.touch(**arg),
'DRAG': lambda dev, arg: dev.drag(**arg),
'PRESS': lambda dev, arg: dev.press(**arg),
'TYPE': lambda dev, arg: dev.type(**arg),
'WAIT': lambda dev, arg: MonkeyRunner.sleep(**arg)
# Process a single file for the specified device.
def process_file(fp, device):
for line in fp:
(cmd, rest) = line.split('|')
# Parse the pydict
rest = eval(rest)
print 'unable to parse options'
if cmd not in CMD_MAP:
print 'unknown command: ' + cmd
CMD_MAP[cmd](device, rest)
def main():
file = sys.argv[1]
fp = open(file, 'r')
device = MonkeyRunner.waitForConnection()
process_file(fp, device)
fp.close();
if __name__ == '__main__':
#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from com.android.monkeyrunner import MonkeyRunner
# The format of the file we are parsing is very carfeully constructed.
# Each line corresponds to a single command.
The line is split into 2
# parts with a | character.
Text to the left of the pipe denotes
# which command to run.
The text to the right of the pipe is a python
# dictionary (it can be evaled into existence) that specifies the
# arguments for the command.
In most cases, this directly maps to the
# keyword argument dictionary that could be passed to the underlying
# command.
# Lookup table to map command strings to functions that implement that
# command.
CMD_MAP = {
'TOUCH': lambda dev, arg: dev.touch(**arg),
'DRAG': lambda dev, arg: dev.drag(**arg),
'PRESS': lambda dev, arg: dev.press(**arg),
'TYPE': lambda dev, arg: dev.type(**arg),
'WAIT': lambda dev, arg: MonkeyRunner.sleep(**arg)
# Process a single file for the specified device.
def process_file(fp, device):
for line in fp:
(cmd, rest) = line.split('|')
# Parse the pydict
rest = eval(rest)
print 'unable to parse options'
if cmd not in CMD_MAP:
print 'unknown command: ' + cmd
CMD_MAP[cmd](device, rest)
def main():
file = sys.argv[1]
fp = open(file, 'r')
device = MonkeyRunner.waitForConnection()
process_file(fp, device)
fp.close();
if __name__ == '__main__':
PS:脚本内容 部分参考了 youxilua ,非常感谢。
四、使用插件扩展Monkeyrunner
您可以用Java语言创建新的类,并打包成一个或多个.jar文件,以此来扩展monkeyrunnerAPI。您可以使用您自己写的类或者继承现有的类来扩展monkeyrunnerAPI。您还可以使用此功能来初始化monkeyrunner环境。
为了使monkeyrunner加载一个插件,您应当如使用如表1中所述的-plugin参数来调用monkeyrunner命令。
在您编写的插件中,您可以导入或继承位于com.android.monkeyrunner包中的几个主要的monkeyrunner类:MonkeyDevice, MonkeyImage和MonkeyRunner.
请注意,插件无法让你访问Android的SDK。您不能导入com.android.app等包。这是因为monkeyrunner是在框架API层次之下与设备或模拟器进行交互的。
插件启动类
用于插件的.jar文件可以指定一个类,使其在脚本执行之前就实例化。如欲指定这个类,您需要在.jar文件的manifest中添加键MonkeyRunnerStartupRunner。其值为启动时运行的类的名称。以下代码段显示了如何在一个ant构建脚本达到这样的目的:
如欲访问monkeyrunner的运行时环境,启动类可以实现com.google.common.base.Predicate。例如,用这个类在默认的命名空间中设置一些变量:
package com.android.
import com.google.common.base.P
import org.python.util.PythonI
public class Main implements Predicate {
public boolean apply(PythonInterpreter anInterpreter) {
* Examples of creating and initializing variables in the monkeyrunner environment's
* namespace. During execution, the monkeyrunner program can refer to the variables "newtest"
* and "use_emulator"
anInterpreter.set("newtest", "enabled");
anInterpreter.set("use_emulator", 1);
package com.android.
import com.google.common.base.P
import org.python.util.PythonI
public class Main implements Predicate {
public boolean apply(PythonInterpreter anInterpreter) {
* Examples of creating and initializing variables in the monkeyrunner environment's
* namespace. During execution, the monkeyrunner program can refer to the variables "newtest"
* and "use_emulator"
anInterpreter.set("newtest", "enabled");
anInterpreter.set("use_emulator", 1);
五、常见问题(评论中的问题会不断补充)
1.“device.touch(10,100, 'DOWN_AND_UP')” 为什么报错?ANS:可以把 'DOWN_AND_UP' 替换为 'MonkeyDevice.DOWN_AND_UP' ,这个问题的主要原因跟Monkeyrunner有关。
2.我输入了很多指令,但是很多没有执行Ans:可以尝试
MonkeyRunner.sleep(time_in_seconds) 方法,让不同的动作之间有间隔。
红黑联盟&版权所有
Copyright&& 2017
All rights reserved.}

我要回帖

更多关于 missing before code 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信