Ios For Monkey

简介:

如果你要再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;i<this.config.numberOfEvents;i++){this.triggerRandomEvent();if(this.config.screenshotInterval)this.takeScreenShotIfItIsTime();this.delay();}};UIAutoMonkey.prototype.triggerRandomEvent=function(){varname=this.chooseEventName();// Find the event method based on the name of the eventvarevent=this.allEvents[name];event.apply(this);};UIAutoMonkey.prototype.target=function(){// Return the local target.returnUIATarget.localTarget();};UIAutoMonkey.prototype.delay=function(seconds){// Delay the target by `seconds` (can be a fraction)// Defaults to setting in configurationseconds=seconds||this.config.delayBetweenEvents;this.target().delay(seconds);};UIAutoMonkey.prototype.chooseEventName=function(){// Randomly chooses an event name from the `eventsWeight` dictionary// based on the given weights.varcalculatedEventWeights=[];vartotalWeight=0;varevents=this.config.eventWeights;for(vareventinevents){if(events.hasOwnProperty(event)){calculatedEventWeights.push({weight:events[event]+totalWeight,event:event});totalWeight+=events[event];}}varchosenWeight=Math.random()*1000%totalWeight;for(vari=0;i<calculatedEventWeights.length;i++){if(chosenWeight<calculatedEventWeights[i].weight){returncalculatedEventWeights[i].event;}}throw"No even was chosen!";};UIAutoMonkey.prototype.screenWidth=function(){// Need to adjust by one to stay within rectanglereturnthis.target().rect().size.width-1;};UIAutoMonkey.prototype.screenHeight=function(){// Need to adjust by one to stay within rectanglereturnthis.target().rect().size.height-1;};UIAutoMonkey.prototype.randomX=function(){varmin,max;if(this.config.frame){// Limits coordinates to given frame. if set in configmin=this.config.frame.origin.x;max=this.config.frame.size.width+min;}else{// Returns a random X coordinate within the screen rectanglemin=0;max=this.screenWidth();}returnMath.floor(Math.random()*(max-min)+min)+1;};UIAutoMonkey.prototype.randomY=function(){varmin,max;if(this.config.frame){// Limits coordinates to given frame. if set in configmin=this.config.frame.origin.y;max=this.config.frame.size.height+min;}else{// Returns a random Y coordinate within the screen rectanglemin=0;max=this.screenHeight();}returnMath.floor(Math.random()*(max-min)+min)+1;};UIAutoMonkey.prototype.randomTapCount=function(){// Calculates a tap count for tap events based on touch probabilitiesif(this.config.touchProbability.multipleTaps>Math.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了!!!

相关文章
|
JavaScript Shell iOS开发
|
20天前
|
开发框架 前端开发 Android开发
安卓与iOS开发中的跨平台策略
在移动应用开发的战场上,安卓和iOS两大阵营各据一方。随着技术的演进,跨平台开发框架成为开发者的新宠,旨在实现一次编码、多平台部署的梦想。本文将探讨跨平台开发的优势与挑战,并分享实用的开发技巧,帮助开发者在安卓和iOS的世界中游刃有余。
|
7天前
|
开发框架 Android开发 iOS开发
安卓与iOS开发中的跨平台策略:一次编码,多平台部署
在移动应用开发的广阔天地中,安卓和iOS两大阵营各占一方。随着技术的发展,跨平台开发框架应运而生,它们承诺着“一次编码,到处运行”的便捷。本文将深入探讨跨平台开发的现状、挑战以及未来趋势,同时通过代码示例揭示跨平台工具的实际运用。
|
11天前
|
Java 调度 Android开发
安卓与iOS开发中的线程管理差异解析
在移动应用开发的广阔天地中,安卓和iOS两大平台各自拥有独特的魅力。如同东西方文化的差异,它们在处理多线程任务时也展现出不同的哲学。本文将带你穿梭于这两个平台之间,比较它们在线程管理上的核心理念、实现方式及性能考量,助你成为跨平台的编程高手。
|
13天前
|
存储 前端开发 Swift
探索iOS开发:从新手到专家的旅程
本文将带您领略iOS开发的奇妙之旅,从基础概念的理解到高级技巧的掌握,逐步深入iOS的世界。文章不仅分享技术知识,还鼓励读者在编程之路上保持好奇心和创新精神,实现个人成长与技术突破。
|
16天前
|
安全 IDE Swift
探索iOS开发之旅:从初学者到专家
在这篇文章中,我们将一起踏上iOS开发的旅程,从基础概念的理解到深入掌握核心技术。无论你是编程新手还是希望提升技能的开发者,这里都有你需要的指南和启示。我们将通过实际案例和代码示例,展示如何构建一个功能齐全的iOS应用。准备好了吗?让我们一起开始吧!
|
21天前
|
安全 Swift iOS开发
Swift 与 UIKit 在 iOS 应用界面开发中的关键技术和实践方法
本文深入探讨了 Swift 与 UIKit 在 iOS 应用界面开发中的关键技术和实践方法。Swift 以其简洁、高效和类型安全的特点,结合 UIKit 丰富的组件和功能,为开发者提供了强大的工具。文章从 Swift 的语法优势、类型安全、编程模型以及与 UIKit 的集成,到 UIKit 的主要组件和功能,再到构建界面的实践技巧和实际案例分析,全面介绍了如何利用这些技术创建高质量的用户界面。
24 2
|
27天前
|
安全 数据处理 Swift
深入探索iOS开发中的Swift语言特性
本文旨在为开发者提供对Swift语言在iOS平台开发的深度理解,涵盖从基础语法到高级特性的全面分析。通过具体案例和代码示例,揭示Swift如何简化编程过程、提高代码效率,并促进iOS应用的创新。文章不仅适合初学者作为入门指南,也适合有经验的开发者深化对Swift语言的认识。
45 9
|
23天前
|
vr&ar Android开发 iOS开发
安卓与iOS开发中的用户界面设计原则
【10月更文挑战第41天】探索移动应用开发的精髓,本文将深入分析安卓和iOS平台上用户界面设计的核心原则。通过比较两大操作系统的设计哲学,我们将揭示如何打造直观、易用且美观的应用程序界面。无论你是初学者还是资深开发者,这篇文章都将为你提供宝贵的见解和实用的技巧,帮助你在竞争激烈的应用市场中脱颖而出。