Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoye committed Jul 12, 2018
0 parents commit dab721b
Show file tree
Hide file tree
Showing 399 changed files with 90,117 additions and 0 deletions.
134 changes: 134 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Created by .ignore support plugin (hsz.mobi)
### macOS template
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

#IDEA
.idea/

#mock
mock/record/
data/
tmp/

.vscode/
.pytest_cache/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018-present, 美团点评

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.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
graft lyrebird
recursive-exclude * *.pyc *.pyo *.swo *.swp *.map *.DS_Store
163 changes: 163 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Lyrebird
![lyrebird](./image/lyrebird.png)

----

# 简介

**Lyrebird** 是一个基于拦截以及模拟HTTP/HTTPS网络请求的面向移动应用的插件化测试平台。

**Lyrebird** 不止提供UI操作,也可以通过API控制所有功能。

**Lyrebird** 也可作为服务端接口测试mock工具使用。


> Lyrebird (琴鸟) 不但美丽壮观,且能歌善舞。它不但能模仿各种鸟类的鸣叫声,还能学人间的各种声音。如汽车喇叭声、火车喷气声、斧头伐木声、修路碎石机声及领号人的喊叫声等。歌声婉转动听,舞姿轻盈合拍,是澳洲鸟类中最受人喜爱的珍禽之一。

## 注意
> 使用Lyrebird后客户端完全和后端API服务器分离。API服务器相关的缺陷将不会被测到。可使用接口测试工具继续完成API接口服务的测试工作,以保障客户端质量。
<img src="./image/Inspector.png" style="width: 800px">

----


# 快速开始


## 环境要求

* macOS

* Python3.6及以上

## 安装
pip3 install lyrebird
## 启动

lyrebird

## 连接移动设备

* 启动Lyrebird后,移动设备需要通过代理的方式将请求数据接入。

* 将移动设备的代理地址设为当前电脑地址,默认端口为4272(IP地址可查看Lyrebird启动时输出的日志)

* 被测设备上用浏览器打开 http://mitm.it, 选择对应操作系统安装证书

> 现在,可以开始操作移动设备了。Lyrebird将显示捕获到的http请求。
## 查看及录制数据

<img src="./image/Inspector-with-tag.png" style="width: 800px">

* 如上图,准备工作完成后,操作手机即可以看到HTTP请求的数据。

* 上图中按钮栏的按钮依次是:

1. 录制按钮
2. 清除inspector数据按钮
3. 新建mock数据组按钮
4. 激活mock数据组选择器
5. 取消激活mock数据按钮

* 操作图中(1)按钮栏的录制按钮,则可开始数据的录制工作。

> 录制数据要求新建或选中一组mock数据。即操作按钮3或4。
* 按钮4 - 激活mock数据选择器,选择mock数据后。经过Lyrebird的请求会被mock,如果mock数据中没有匹配的数据,则会代理该请求。

> mock数据可由左边导航栏切换到DataManager界面进行编辑管理
----

# 基本命令

* **lyrebird**

以缺省参数启动lyrebird


* **lyrebird start**

以缺省参数启动lyrebird

* **lyrebird v start**

以输出详细日志模式启动lyrebird

* **lyrebird no-browser start**

启动lyrebird不默认打开浏览器

* **lyrebird start --mock 9090 --proxy 4272 --data . --name foo**

指定参数启动lyrebird

参数:

--mock 默认9090 , mock服务及前端端口

--proxy 默认4272, 代理服务端口

--data 默认./data, mock数据根目录

--name 默认lyrebird,服务别名(用于通过别名停止指定的lyrebird服务)

* **lyrebird stop**

停止lyrebird

* **lyrebird stop --name foo**

停止别名为foo的lyrebird

----

# 在代码中使用lyrebird

```python
import lyrebird
server = lyrebird.Server()

# 设置服务端口及数据根目录, 不设置可以使用默认值 mock port = 9090, proxy port = 4272, data root dir = ./data
server.mock_port(9090)
server.proxy_port(4272)
server.data_root_dir('./data')

# 启动服务
server.start()

# 停止服务
server.stop()
```

----

# 开发者指南

## 配置Lyrebird工程

```bash
# clone 代码
git clone https://github.com/Meituan-Dianping/lyrebird.git

# 进入工程目录
cd lyrebird

# 初始化开发环境
sh dev.sh

# 使用IDE打开工程(推荐Pycharm或vscode)

# 在IDE中执行debug.py即可开始调试
```

----

# 感谢

本工具中代理功能使用[mitmproxy](https://github.com/mitmproxy/mitmproxy)实现

5 changes: 5 additions & 0 deletions debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import lyrebird


if __name__ == '__main__':
lyrebird.debug()
31 changes: 31 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

echo "***************************"
echo " Lyrebird setup start "
echo "***************************"

# 如果已经有venv目录,删除此目录
if [ -e "./venv/" ]; then
rm -rf ./venv/
fi

mkdir venv
python3 -m venv ./venv

# 有些设备上虚拟环境中没有pip,需要通过easy_install安装
if [ ! -e "./venv/bin/pip" ] ;then
echo "pip no exist, install pip with easy_install"
./venv/bin/easy_install pip
fi

source ./venv/bin/activate
pip3 install -r ./requirements.txt

# 如果没有data目录,创建此目录
if [ ! -e "./data/" ]; then
mkdir ./data
fi

echo "***************************"
echo " Lyrebird setup finish "
echo "***************************"
Binary file added image/Inspector-with-tag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/Inspector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/lyrebird.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dab721b

Please sign in to comment.