monkeyrunner help api 文档导出具体实例

1. 行文目的

相信很多做自动化的小伙伴,都遇到了monkeyrunner api文档无法导出的困惑,我也遇到了,很痛苦。为了让各位小伙伴愉快进行自动化测试,我将把api接口文档导出步骤详细列出,方便大家查询、使用!

废话不多说了,让我们走起!

 注:该方法100%可以导出monkeyrunner help文档!

2. monkeyrunner help文档导出步骤

  • 下载help.py文档
    http://androidxref.com/source/xref/sdk/monkeyrunner/scripts/help.py
注:为了防止有些人不能下载,我下面将help.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

import os
import sys

supported_formats = ['html', 'text', 'sdk-docs']

if len(sys.argv) != 3:
  print 'help.py: format output'
  sys.exit(1)

(format, saveto_path) = sys.argv[1:]

if not format.lower() in supported_formats:
  print 'format %s is not a supported format' % format
  sys.exit(2)

output = mr.help(format=format)
if not output:
  print 'Error generating help format'
  sys.exit(3)

dirname = os.path.dirname(saveto_path)
try:
    os.makedirs(dirname)
except:
    print 'oops'
    pass # It already existed

fp = open(saveto_path, 'w')
fp.write(output)
fp.close()

sys.exit(0)

  • 将组织好的help.py移动到monkeyrunner.bat同级目录下
注:将help.py放在monkeyrunner.bat同级目录方便后续命令行输入。

我的monkeyrunner.bat的位置是D:\Android\sdk\tools,所以我将help.py放在D:\Android\sdk\tools目录下。

  • 添加.cs文档移动到monkeyrunner.jar中
注:该步是为了解决运行程序报出 html.cs不存在问题的。

使用360解压软件打开monkeyrunner.jar(D:\Android\sdk\tools\lib\monkeyrunner.jar)

将monkeyrunner.jar\resources\com\android\monkeyrunner文件夹下的html.cs、sdk-docs.cs、text.cs 拷贝到 monkeyrunner.jar\com\android\monkeyrunner文件夹中

  • 运行monkeyrunner help.py命令

此时,一切准备完毕,只待执行命令了,打开cmd命令行,执行如下命令:

monkeyrunner help.py html help.html

运行完成,命令行会输出“oops”,恭喜你!操作成功!你在D:\Android\sdk\tools就可以找到help.html文档。

注1:此处我提前将D:\Android\sdk\tools添加到了系统path中。
注2:help.html下载链接如下:https://share.weiyun.com/f3c858d28d000c11fbdeab01da1609b2

你可能感兴趣的:(monkeyrunner help api 文档导出具体实例)