私だってやれば出来る子!♥Multi-Mechanize♥
@ayakomuro
2012年6月24日日曜日
Multi-Mechanizeとは
Pythonで書かれたパフォーマンス・テスト・フレームワーク
Pylotの後継版
Python2.6以降~
GUIなし
2012年6月24日日曜日
インストール方法
virtualenvで仮想実行環境を作成する
pip install multi-Mechanize
pip install numpy, matplotlib #Lionだと動かないので個別にインストールする
2012年6月24日日曜日
プロジェクト作成方法
$ multimech-newproject hoge_prj
/hoge_prj
\__config.cfg
\__test_scripts \__v_user.py
2012年6月24日日曜日
設定ファイル[global] #共通設定run_time = 300 #テストの時間(秒)*rampup = 300 #全スレッドを生成する時間(秒)*
results_ts_interval = 30 #結果解析用の時間(秒)* progress_bar = on #テストが走っている時に処理中バーを表示するかどうか(ディフォルトOn)
console_logging = off #標準出力にログを出すかどうか(ディフォルトoff)
xml_report = off #xml/拡張子jtlのレポートを出力する(ディフォルトoff) results_database = sqlite:///hoge_prj/results.db #データーベース接続
post_run_script = python hoge_prj/foo.py #テスト完了をフックにして呼び出せるスクリプト
[user_group-1] #個別設定 threads = 30 #ユーザー毎のスレッド数
script = vu_script1.py#ユーザー毎に走らせるスクリプト hoge_prj/test_scripts/配下
2012年6月24日日曜日
GETでリクエストする
import mechanize
class Transaction(object): def run(self): br = mechanize.Browser() br.set_handle_robots(False)
resp = br.open('http://www.example.com/') resp.read()
assert (resp.code == 200), 'Bad Response: HTTP %s' % resp.code assert ('Example Web Page' in resp.get_data())
2012年6月24日日曜日
POSTでログインするimport httplibimport urllibimport time
class Transaction(object): def __init__(self): self.custom_timers = {}
def run(self): post_body=urllib.urlencode({ 'USERNAME': 'corey', 'PASSWORD': 'secret',}) headers = {'Content-type': 'application/x-www-form-urlencoded'}
start_timer = time.time() conn = httplib.HTTPConnection('www.example.com') conn.request('POST', '/login.cgi', post_body, headers) resp = conn.getresponse() content = resp.read() latency = time.time() - start_timer
self.custom_timers['LOGIN'] = latency assert (resp.status == 200), 'Bad Response: HTTP %s' % resp.status assert ('Example Web Page' in content), 'Text Assertion Failed'
2012年6月24日日曜日
結果./hoge_prj \__results \__results_2012.06.11_23.26.14 \__results.csv \__results.html
2012年6月24日日曜日
詳細はこちら!
http://testutils.org/multi-mechanize/
https://sites.google.com/site/ayakomuro/infra-app/mutli-machanize
2012年6月24日日曜日