Skip to content

Commit

Permalink
Merge pull request alibaba#1 from alibaba/main
Browse files Browse the repository at this point in the history
Merge alibaba/tidevice

Former-commit-id: 9b801da
  • Loading branch information
vdavdev authored Jan 26, 2021
2 parents 5b82c05 + d3bbe8b commit dea2fb3
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 97 deletions.
9 changes: 9 additions & 0 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ hdiutil mount /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.plat
tree /Volumes/DeveloperDiskImage
```

## How to Package WDA.ipa
Build `WebDriverAgentRunnerUITests-Runner.app` with the following command. `.app` should located in `/tmp/derivedDataPath/Release-iphoneos`

```bash
xcodebuild build-for-testing -workspace WebDriverAgent.xcworkspace/ -scheme WebDriverAgent -sdk iphoneos -configuration Release -derivedDataPath /tmp/derivedDataPath
```

Created folder `Payload` and put `.app` into it, then compressed to zip, change extention name to `.ipa`, and resign. That's all.

## References
- C implementation <https://github.com/libimobiledevice>
- Python implement of libimobiledevice: <https://github.com/iOSForensics/pymobiledevice>
Expand Down
63 changes: 42 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,86 @@
![tidevice](assets/tidevice-logo.png)
# tidevice
## tidevice

[![PyPI](https://img.shields.io/pypi/v/tidevice)](https://pypi.org/project/tidevice/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/tidevice)](https://pypistats.org/search/tidevice)

[中文文档](README_CN.md)
[English](README_EN.md)

Command line tool to communicate with iOS device, support the following functions
该工具能够用于与iOS设备进行通信, 提供以下功能

- ipa install and uninstall
- launch and kill app
- list installed app info
- retrieve performance data
- screenshot
- simulate run xctest, eg: WebDriverAgent
- other
- ipa包的安装和卸载
- 根据bundleID 启动和停止应用
- 列出安装应用信息
- 获取指定应用性能(CPU,MEM,FPS)
- 截图
- 模拟Xcode运行XCTest,如启动WebDriverAgent测试(此方法不依赖xcodebuild)
- 其他

## Install
## 安装
```bash
pip3 install -U tidevice
```

## Usage
## 使用

### Show version number
### 查看版本号
```bash
$ tidevice version
0.1.0
```

### App management
### 列出连接设备
```bash
$ tidevice list
List of apple devices attached
00008030-001A35E40212345678 codeskyblue的iPhoneSE

$ tidevice list --json
[
{
"udid": "00008030-001A35E40212345678",
"name": "codeskyblue的iPhoneSE"
}
]
```

### 应用管理
```bash
# 安装应用
$ tidevice install example.ipa
$ tidevice install https://example.org/example.ipa

# 卸载应用
$ tidevice uninstall com.example.demo

# 启动应用
$ tidevice launch com.example.demo

# 停止应用
$ tidevice kill com.example.demo

# show installed app list
# 查看已安装应用
$ tidevice applist
```

### Run XCTest
### 运行XCTest
```bash
# 运行XCTEST
$ tidevice xctest -B com.facebook.wda.WebDriverAgent.Runner
```

### Other
### 其他常用
```bash
# mount developer image (need more test)
# 挂载开发者镜像 (需要更多的测试)
$ tidevice developer

# reboot device
# 重启
$ tidevice reboot

# 截图
$ tidevice screenshot screenshot.jpg

# TODO(ssx): collect performance
# 性能采集 (TODO)
# $ tidevice perf -o fps,mem,cpu -B com.example.demo
```

Expand All @@ -77,4 +98,4 @@ See [DEVELOP](DEVELOP.md)
- [使用纯 python 实现 Instruments 协议,跨平台 (win,mac,linux) 获取 iOS 性能数据](https://testerhome.com/topics/27159)

## LICENSE
[MIT](LICENSE.md)
[MIT](LICENSE)
63 changes: 37 additions & 26 deletions README_CN.md → README_EN.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,80 @@
![tidevice](assets/tidevice-logo.png)
## tidevice
# tidevice

[![PyPI](https://img.shields.io/pypi/v/tidevice)](https://pypi.org/project/tidevice/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/tidevice)](https://pypistats.org/search/tidevice)

该工具能够用于与iOS设备进行通信, 提供以下功能
[中文文档](README.md)

- ipa包的安装和卸载
- 根据bundleID 启动和停止应用
- 列出安装应用信息
- 获取指定应用性能(CPU,MEM,FPS)
- 截图
- 模拟Xcode运行XCTest,如启动WebDriverAgent测试
- 其他
Command line tool to communicate with iOS device, support the following functions

## 安装
- ipa install and uninstall
- launch and kill app
- list installed app info
- retrieve performance data
- screenshot
- simulate run xctest, eg: WebDriverAgent
- other

## Install
```bash
pip3 install -U tidevice
```

## 使用
## Usage

### 查看版本号
### Show version number
```bash
$ tidevice version
0.1.0
```

### 应用管理
### List connected devices
```bash
$ tidevice list
List of apple devices attached
00008030-001A35E40212345678 codeskyblue的iPhoneSE

$ tidevice list --json
[
{
"udid": "00008030-001A35E40212345678",
"name": "codeskyblue的iPhoneSE"
}
]
```

### App management
```bash
# 安装应用
$ tidevice install example.ipa
$ tidevice install https://example.org/example.ipa

# 卸载应用
$ tidevice uninstall com.example.demo

# 启动应用
$ tidevice launch com.example.demo

# 停止应用
$ tidevice kill com.example.demo

# 查看已安装应用
# show installed app list
$ tidevice applist
```

### 运行XCTest
### Run XCTest
```bash
# 运行XCTEST
$ tidevice xctest -B com.facebook.wda.WebDriverAgent.Runner
```

### 其他常用
### Other
```bash
# 挂载开发者镜像
# mount developer image (need more test)
$ tidevice developer

# 重启
# reboot device
$ tidevice reboot

# 截图
$ tidevice screenshot screenshot.jpg

# 性能采集 (TODO)
# TODO(ssx): collect performance
# $ tidevice perf -o fps,mem,cpu -B com.example.demo
```

Expand All @@ -81,4 +92,4 @@ See [DEVELOP](DEVELOP.md)
- [使用纯 python 实现 Instruments 协议,跨平台 (win,mac,linux) 获取 iOS 性能数据](https://testerhome.com/topics/27159)

## LICENSE
[MIT](LICENSE)
[MIT](LICENSE.md)
8 changes: 0 additions & 8 deletions publish.sh

This file was deleted.

16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""Created on Mon Jan 25 2021 10:42:05 by codeskyblue
"""

import pytest
import os


curdir = os.path.dirname(os.path.abspath(__file__))


@pytest.fixture
def wda_filepath():
return os.path.join(curdir, "testdata/WebDriverAgentRunner.ipa")
17 changes: 17 additions & 0 deletions tests/test_ipautil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""Created on Mon Jan 25 2021 10:38:39 by codeskyblue
"""

from tidevice._ipautil import IPAReader, IPAError



def test_get_infoplist(wda_filepath: str):
ir = IPAReader(wda_filepath)
assert ir.get_bundle_id() == "com.facebook.WebDriverAgentRunner.xctrunner"

data = ir.get_mobileprovision()
assert "Version" in data
assert data['Version'] == 1
1 change: 1 addition & 0 deletions tests/testdata/WebDriverAgentRunner.ipa.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
49a9ae763db6c7d29f67d720ad9fda87a46bd8a5
60 changes: 55 additions & 5 deletions tidevice/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

from ._device import Device
from ._ipautil import IPAReader
from ._utils import get_app_dir, get_app_file, get_binary_by_name, is_atty
from ._utils import get_app_dir, get_binary_by_name, is_atty
from ._usbmux import Usbmux
from ._version import __version__
from .exceptions import MuxError, ServiceError
from .exceptions import MuxError, MuxServiceError, ServiceError

from ._proto import MODELS, PROGRAM_NAME

Expand Down Expand Up @@ -73,7 +73,7 @@ def _udid2device(udid: Optional[str] = None) -> Device:
return Device(_udid, um)


def cmd_devices(args: argparse.Namespace):
def cmd_list(args: argparse.Namespace):
if not args.json and is_atty:
print("List of apple devices attached", file=sys.stderr)

Expand Down Expand Up @@ -263,14 +263,63 @@ def cmd_kill(args: argparse.Namespace):
print("Kill pid:", pid)


def _check_mounted(d: Device) -> bool:
try:
d._unsafe_start_service("com.apple.mobile.diagnostics_relay")
return True
except MuxServiceError:
return False


def cmd_developer(args: argparse.Namespace):
d = _udid2device(args.udid)
if _check_mounted(d):
logger.info("DeveloperImage already mounted")
return

product_version = d.get_value("ProductVersion")
logger.info("ProductVersion: %s", product_version)
major, minor = product_version.split(".")[:2]
version = major + "." + minor

device_support_paths = [
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport", # Xcode
get_app_dir("DeviceSupport"),
]
for _dir in device_support_paths:
logger.debug("Search developer disk image in Path:%r", _dir)
dimgdir = os.path.join(_dir, version)
if os.path.isdir(dimgdir):
d.imagemounter.mount(
os.path.join(dimgdir, "DeveloperDiskImage.dmg"),
os.path.join(dimgdir, "DeveloperDiskImage.dmg.signature"))
return
zippath = os.path.join(_dir, version+".zip")
if os.path.isfile(zippath):
# TODO
pass
else:
raise RuntimeError("DeveloperDiskImage nout found")

def cmd_test(args: argparse.Namespace):
print("Just test")
# files = os.listdir(path)



# Here need device unlocked
# signatures = d.imagemounter.lookup()
# if signatures:
# logger.info("DeveloperImage already mounted")
# return




_commands = [
dict(action=cmd_version, command="version", help="show current version"),
dict(action=cmd_devices,
command="devices",
dict(action=cmd_list,
command="list",
flags=[
dict(args=['--json'],
action='store_true',
Expand Down Expand Up @@ -333,6 +382,7 @@ def cmd_test(args: argparse.Namespace):
dict(args=['arguments'], nargs='*', help='app arguments'),
],
help="launch app with bundle_id"),
dict(action=cmd_developer, command="developer", help="mount developer image to device"),
dict(action=cmd_kill,
command="kill",
flags=[dict(args=['name'], help='pid or bundle_id')],
Expand Down
Loading

0 comments on commit dea2fb3

Please sign in to comment.