本文共 5624 字,大约阅读时间需要 18 分钟。
如果你要再IOS上面跑monkey 前提是要有 被测APP的源码@!
真机测试monkey我还没研究到!后续!
本帖面向对象是初学IOS monkey的 哥们,高手别吐槽!!!!
我会后续更新
第一步:打开Xcode 再把AppDebug到你模拟器上
第二步:再打开profile
第三步:选择automation
第四步:选择js
第五步:贴如代码
// Copyright (c) 2013 Jonathan Penn (http://cocoamanifest.net/)// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to deal// in the Software without restriction, including without limitation the rights// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell// copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// The above copyright notice and this permission notice shall be included in// all copies or substantial portions of the Software.// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE."use strict";functionUIAutoMonkey(){ this.config={ numberOfEvents:1000,delayBetweenEvents:0.05,// In seconds// If the following line is uncommented, then screenshots are taken// every "n" seconds.//screenshotInterval: 5,// Events are triggered based on the relative weights here. The event// with this highest number gets triggered the most.//// If you want to add your own "events", check out the event method// definitions below.eventWeights:{ tap:500,drag:1,flick:1,orientation:1,clickVolumeUp:1,clickVolumeDown:1,lock:1,pinchClose:10,pinchOpen:10,shake:1},// Probability that touch events will have these different propertiestouchProbability:{ multipleTaps:0.05,multipleTouches:0.05,longPress:0.05}// Uncomment the following to restrict events to a rectangluar area of// the screen/* frame. { origin: {x: 0, y: 0}, size: {width: 100, height: 50} } */};}// --- --- --- ---// Event Methods//// Any event probability in the hash above corresponds to a related event// method below. So, a "tap" probability will trigger a "tap" method.//// If you want to add your own events, just add a probability to the hash// above and then add a corresponding method below. Boom!//// Each event method can call any other method on this UIAutoMonkey object.// All the methods at the end are helpers at your disposal and feel free to// add your own.UIAutoMonkey.prototype.allEvents={ tap:function(){ this.target().tapWithOptions({ x:this.randomX(),y:this.randomY()},{ tapCount:this.randomTapCount(),touchCount:this.randomTouchCount(),duration:this.randomTapDuration()});},drag:function(){ this.target().dragFromToForDuration({ x:this.randomX(),y:this.randomY()},{ x:this.randomX(),y:this.randomY()},0.5);},flick:function(){ this.target().flickFromTo({ x:this.randomX(),y:this.randomY()},{ x:this.randomX(),y:this.randomY()});},orientation:function(){ varorientations=[UIA_DEVICE_ORIENTATION_PORTRAIT,UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN,UIA_DEVICE_ORIENTATION_LANDSCAPELEFT,UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT];vari=Math.floor(Math.random()*10)%orientations.length;varnewOrientation=orientations[i];this.target().setDeviceOrientation(newOrientation);this.delay(0.9);},clickVolumeUp:function(){ this.target().clickVolumeUp();},clickVolumeDown:function(){ this.target().clickVolumeUp();},lock:function(){ this.target().lockForDuration(Math.random()*3);},pinchClose:function(){ this.target().pinchCloseFromToForDuration({ x:this.randomX(),y:this.randomY()},{ x:this.randomX(),y:this.randomY()},0.5);},pinchOpen:function(){ this.target().pinchOpenFromToForDuration({ x:this.randomX(),y:this.randomY()},{ x:this.randomX(),y:this.randomY()},0.5);},shake:function(){ this.target().shake();}};// --- --- --- ---// Helper methods//UIAutoMonkey.prototype.RELEASE_THE_MONKEY=function(){ // Called at the bottom of this script. to, you know...//// RELEASE THE MONKEY!for(vari=0;iMath.random()){ returnMath.floor(Math.random()*10)%3+1;}elsereturn1;};UIAutoMonkey.prototype.randomTouchCount=function(){ // Calculates a touch count for tap events based on touch probabilitiesif(this.config.touchProbability.multipleTouches>Math.random()){ returnMath.floor(Math.random()*10)%3+1;}elsereturn1;};UIAutoMonkey.prototype.randomTapDuration=function(){ // Calculates whether or not a tap should be a long press based on// touch probabilitiesif(this.config.touchProbability.longPress>Math.random()){ return0.5;}elsereturn0;};UIAutoMonkey.prototype.randomRadians=function(){ // Returns a random radian valuereturnMath.random()*10%(3.14159*2);};UIAutoMonkey.prototype.takeScreenShotIfItIsTime=function(){ varnow=(newDate()).valueOf();if(!this._lastScreenshotTime)this._lastScreenshotTime=0;if(now-this._lastScreenshotTime>this.config.screenshotInterval*1000){ varfilename="monkey-"+(newDate()).toISOString().replace(/[:\.]+/g,"-");this.target().captureScreenWithName(filename);this._lastScreenshotTime=now;}};// Commodity function to call RELEASE_THE_MONKEY directly on UIAutoMonkey// if you don't need to customize your instanceUIAutoMonkey.RELEASE_THE_MONKEY=function(){ (newUIAutoMonkey()).RELEASE_THE_MONKEY();};UIAutoMonkey.RELEASE_THE_MONKEY();
第六步:点击播放
这就OK了!!!
转载地址:http://jhabl.baihongyu.com/