# GAutomatorAndroid
![PyPI - Downloads](https://img.shields.io/badge/qintianchen-gauto--android-orange)
[![0.1.4](https://img.shields.io/badge/version-v0.1.4-blue)](https://pypi.org/manage/project/gauto-android/releases/)
[中文文档](./README_cn.md)
A simplified version of the Android script in GAutomator, removing support for the cloud platform, removing compatibility with python2.7, and modifying some interfaces.
### Download and Install
```shell script
pip install gauto-android
```
### the simplest usage
```python
import os
import gauto.manager as manager
device = manager.get_device()
engine = manager.get_engine()
logger = logging.getLogger("gauto") # The global default logger name is "gauto"
def init():
os.environ["FORWARD_LOCAL_PORT"] = "53001" # Local port, one for each android device
os.environ["ANDROID_SERIAL"] = "emulator-5554" # Android device serial number
os.environ["PKGNAME"] = "com.tencent.sgame" # Package name
os.environ["LAUNCHACTIVITY"] = "com.tencent.sgame.MainActivity" # Main Activity
def run():
logger.info("Launch app")
device.launch_app()
time.sleep(2)
logger.info("Click the button named Button.close")
e = engine.find_element("/Canvas/Button.close")
engine.click(e)
logger.info("screenshot")
device.mini_screencap("./screenshot.png")
logger.info("Kill app")
device.kill_app()
run()
```
### Another way to start your script —— Read the arguments from the command line
```python
import getopt
import optparse
import os
import gauto.manager as manager
os.chdir(os.path.dirname(os.path.abspath(__file__)))
logger = manager.logger
def run():
# dosomething...
pass
def main():
usage = "usage:%prog [options] --qqname= --qqpwd= --engineport= --uiport= --serial="
parser = optparse.OptionParser(usage)
parser.add_option("-w", "--localport", dest="FORWARD_LOCAL_PORT", help="forward local port")
parser.add_option("-s", "--serial", dest="ANDROID_SERIAL", help="adb devices android mobile serial")
parser.add_option("-k", "--package", dest="PKGNAME", help="upload password")
parser.add_option("-j", "--mainactivity", dest="LAUNCHACTIVITY", help="upload password")
(options, args) = parser.parse_args()
try:
if options.FORWARD_LOCAL_PORT:
os.environ["FORWARD_LOCAL_PORT"] = options.FORWARD_LOCAL_PORT
if options.ANDROID_SERIAL:
os.environ["ANDROID_SERIAL"] = options.ANDROID_SERIAL
if options.PKGNAME:
os.environ["PKGNAME"] = options.PKGNAME
if options.LAUNCHACTIVITY:
os.environ["LAUNCHACTIVITY"] = options.LAUNCHACTIVITY
except getopt.error as msg:
logger.info("for help use --help")
return 2
run()
if __name__ == "__main__":
sys.exit(main())
```
In the entry script above, your can code your automation logic in 'run()'. Before that, the script takes arguments from the command line and initializes some environment variables.The reason is simple, for some global environment variables are used in gauto-android package, and if you don't set the required global variables, you might get some exceptions.You can then launch it with the following command:
```shell script
python main.py --serial=emular-5554 --localport=53001 --package=com.tencent.sgame --mainactivity=com.tencent.sgame.MainActivity
```
The parameters of the script are described as follows:
|param|param abbreviation|description|
|------|------|------|
|--localport|-e|Establish a local port for adb forwarding|
|--serial|-s|Device serial number|
|--package|-k|Package name|
|--mainactivity|-j|Main activity, get it from client programmer|
### Device API
|Device API|description|
|---|---|
|launch_app|Launch APP|
|is_app_launched|Determine if the app is started|
|relaunch_app|Relaunch app|
|kill_app|Kill app process|
|get_screenshot|Screenshot (slightly slower, adb‘s built-in capabilities)|
|mini_screencap|Screenshot (good performance, but with possible compatibility issues)|
### Engine API
The Unity engine-related APIs are placed in the engine.py module
| Engine API | Description |
| ------| ------ |
| find_element | Gets an instance of an object by its fullpath |
| find_elements_path|Returns a list of objects that correspond to a particular fullpath (expression)|
|find_elements_by_component|Find the object by given type and return a list|
|get_element_bound|Gets the boundary information of the object|
|get_element_text|Returns the text of the TextView component on an object|
|get_element_image|Returns the texture name in the Render component on an object|
|get_scene|Gets the name of the current scene|
|get_element_world_bound|Gets the boundary information of the object in world coordinates|
|click_position|Click by coordinates|
|click|Click on the center of an object|
|press_position|Press by coordinate|
|press|Press the center of an object|
|swipe_position|Swipe by coordinates|
|swipe|Slide from the center of one object to the center of another|
|swipe_and_press|joystick simulation|
|input|Set the text for a TextView in an object|
|get_touchable_elements_bound|Gets the boundary information for all touchable objects|
|get_registered_handlers|Returns the list of name of the methods registered in SDK|
|call_registered_handler|Call a method registered in SDK|
|get_component_methods|Gets a list of method in a component|
|call_component_method|Gets a component's method to call a method on a component|
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
gauto-android-0.1.4.tar.gz (73个子文件)
gauto-android-0.1.4
PKG-INFO 7KB
gauto_android.egg-info
PKG-INFO 7KB
requires.txt 62B
SOURCES.txt 2KB
top_level.txt 6B
dependency_links.txt 1B
setup.cfg 42B
gauto
manager.py 2KB
httptools
utils.py 4KB
remote_connection.py 14KB
errorhandler.py 2KB
__init__.py 745B
command.py 1KB
exceptions.py 931B
__init__.py 1KB
common
rpc_thread.py 3KB
wetest_exceptions.py 2KB
utils.py 2KB
platform_helper.py 7KB
coordinate_transfer.py 3KB
__init__.py 723B
socket_client.py 5KB
adb_process.py 4KB
wrapper.py 1KB
protocol.py 2KB
wetest
engine.py 34KB
__init__.py 748B
element.py 2KB
device.py 5KB
uiautomator
login_tencent.py 15KB
login_getter.py 6KB
accout_handler.py 6KB
uiautomator_manager.py 6KB
__init__.py 727B
Minitouch
__init__.py 0B
Minitouch.py 8KB
libs
urllib3
request.py 6KB
filepost.py 2KB
connectionpool.py 34KB
__init__.py 3KB
connection.py 12KB
fields.py 6KB
_collections.py 11KB
response.py 19KB
poolmanager.py 13KB
util
request.py 2KB
url.py 6KB
timeout.py 10KB
__init__.py 938B
ssl_.py 12KB
connection.py 5KB
retry.py 11KB
response.py 2KB
packages
ssl_match_hostname
__init__.py 473B
_implementation.py 4KB
__init__.py 114B
ordered_dict.py 9KB
six.py 30KB
backports
makefile.py 1KB
__init__.py 0B
contrib
appengine.py 8KB
ntlmpool.py 5KB
__init__.py 0B
socks.py 6KB
pyopenssl.py 12KB
exceptions.py 6KB
uiauto
uiautomator.py 52KB
__init__.py 72B
__init__.py 72B
six.py 30KB
imap_utf7.py 3KB
setup.py 968B
README.md 5KB
共 73 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功