‘壹’ monkeyrunner 怎么录制脚本的
1. 保证有android sdk, sdk的tools文件夹里有一个monkeyrunner.bat.
2.建文件: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 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)
3.建文件: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 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('|')
try:
# Parse the pydict
rest = eval(rest)
except:
print 'unable to parse options'
continue
if cmd not in CMD_MAP:
print 'unknown command: ' + cmd
continue
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__':
main()
4. cd到monkeyrunner.bat 的目录里, 运行 monkeyrunner ..\..\monkey_recorder.py (绝对路径)
5.点击屏幕即会生成坐标,还有按button,输入文本,滑动等事件 ,录制完毕后选择Export Actions就将脚本保存下来了,保存的时候不需要后缀名。(也可加后缀名:*.mr)
6.回放:
cd到monkeyrunner.bat 的目录里, 运行 monkeyrunner ..\..\monkey_playback.py ..\..\第5步中保存的文件名(均为绝对路径)
‘贰’ monkey测试怎么执行script脚本
一、利用fontMonkey测试工具包 1、下载FoneMonkey.zip文件并解压 2、用xcode打开工程目录 3、添加一个测试用的target并重命名: 4、选取刚才创建的target并将解压好的FontMonkey倒入工程目录 也可以直接拖入到文件目录:倒入时确保你的target为...
‘叁’ monkeyrunner 编写python脚本运行时遇到的几个问题
你需要添加一句转换目录: chdir(%ANDROID_HOME/sdk/tools)
添加Except异常到文件
‘肆’ 请问用python写monkeyrunner的脚本,在哪里可以调试脚本
pycharm 是一个很好的调试环境
‘伍’ ios中monkey测试脚本怎么写
一、利用fontMonkey测试工具包
1、下载FoneMonkey.zip文件并解压
2、用xcode打开工程目录
3、添加一个测试用的target并重命名:
4、选取刚才创建的target并将解压好的FontMonkey倒入工程目录 也可以直接拖入到文件目录:倒入时确保你的target为刚才添加的
5、此时在你的框架中会默认添加两个文件
libFoneMonkey.5.4a.beta.a
libFoneMonkeyOCUnit.5.4a.beta.a
这两个文件在FoneMonkey的lib文件夹中,如果框架管理中没有,则可以直接拖过去;
然后再添加几个框架文件(默认有三个),libxml2.dylib、SenTestingKit.framework、QuartzCore.framework
6、修改工程的配置文件 Buile Seting->Linking->Other Linker Flags
添加选项 -all_load
7、开始编译程序 选择测试target以及模拟器(真机器还没试验),运行
二在Instrument中编写脚本进行测试(不能录制)
1、打开Instruments工具 一般路径:/Developer/Applications/instrument
2、选择Automation
3、添加测试脚本(如果有现成的,可以导入)
4、编写脚本
给出测试几个按钮点击的脚本
var target = UIATarget.localTarget(); //变量用来表示这是一个测试系统
var application = target.frontMostApp(); //确定要测试的程序
var window = application.mainWindow(); //确定要册书的窗口
window.logElementTree(); //获取要测试界面的所有元素
var bt=window.buttons()[2];
if(bt.isValid()){
bt.tap();
}
else{
UIAlogger.logMessage("some error show!");
}
5、倒入程序的xx.app 包
6、点击Record将会直接通过脚本去点击程序中的一个按钮
‘陆’ 你好 关于monkeyrunner测试,如何写一个bat文件执行多个测试脚本
请用start 否则P处理会等待第一条执行结束后才会执行第二条。
start "" monkeyrunner D:\Python\sanity\test1.py
start "" monkeyrunner D:\Python\sanity\test2.py
start "" monkeyrunner D:\Python\sanity\test3.py
‘柒’ 如何利用java语言编写monkeyrunner功能测试脚本
请用start 否则P处理会等待第一条执行结束后才会执行第二条。
start "" monkeyrunner D:\Python\sanity\test1.py
start "" monkeyrunner D:\Python\sanity\test2.py
start "" monkeyrunner D:\Python\sanity\test3.py
‘捌’ 如何编写monkey脚本
s MyFrame(wx.Frame):
delayDefault = "2"
seedDefault = ""
executionFrequencyDefault = ""
logDir = "./"
def __init__(self):
wx.Frame.__init__(self, None, -1, "My Frame", size=(500, 800))
panel = wx.Panel(self, -1)
xPos = 10
xPos1 = 180
yPos = 12
yDelta = 40
excuteMode = ["忽略程序崩溃",
"忽略程序无响应",
"忽略安全异常",
"出错中断程序",
"本地代码导致的崩溃",
"默认"
]
logMode = ["简单","普通","详细"]
executionModeDefault = excuteMode[0]
menuBar = wx.MenuBar()
menu1 = wx.Menu("")
menuBar.Append(menu1, "File")
self.SetMenuBar(menuBar)
wx.StaticText(panel, -1, "种子数:", pos=(xPos, yPos))
self.seedCtrl = wx.TextCtrl(panel, -1, "", pos=(xPos1, yPos))
self.seedCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnAction)
self.seedCtrl.SetFocus()
wx.StaticText(panel, -1, "执行次数:", pos=(xPos, yPos+yDelta))
self.excuteNumCtrl = wx.TextCtrl(panel, -1, "", pos=(xPos1, yPos+yDelta))