jvm版本: 1.8.0_65javascript
sahi版本: Sahi Pro 6.1.0html
参考来源:java
Sahi官网chrome
Sahi运行须要Java 1.5 或更高版本jvm
从官网下载Sahi Pro须要注册获取30天的试用期。目前Sahi貌似已不在提供社区版。测试
install_sahi_pro_v610_20150617.jar
双击“install_sahi_pro_xxx.jar”而后运行安装包ui
或命令行运行lua
java -jar install_sahi_pro_xxx.jar
咱们支持正版,想延长试用期的童鞋私聊。firefox
Sahi Dashboard自动启动Sahi代理,而且能够启动配置好的浏览器。
启动Sahi Dashboard有三种方式:
命令行
在新的窗口打开“Sahi Controller”
在"Sahi Controller"上打开选项卡“Record”
在“Script Name:”处填上 first_script.sah,而后点击“Record”
点击“Sample Application”
打开Sahi的示例程序后,输入用户名“test”和密码“secret”,而后点击“Login”按钮登录
最后一步的记录可在“Evaluate Expression”中查看
登录后是一个购物车,添加数量2,3,1而后点击“Add”按钮,底部会计算出总价。
一个脚本一般包括网页上的操做以及功能验证,Sahi能够在录制脚本的过程当中增长断言,来实现验证。
为总价加一个断言:
将鼠标移至页面html元素上,而后按住CRTL键
若是是Mac系统,应用程序窗体须要在focus状态下接受鼠标的事件。
“Accessor”字段会出如今Controller上,在这个例子中,咱们将鼠标悬浮在“Grand Total”字段上
点击“Assert”按钮,为元素生成断言
这些断言会在“Evaluate Expression”中看到
点击“Test-->” 验证断言是否为真
一旦断言为真,点击“Append to Script”将断言加入脚本
用“Evaluate Expression”和“Test-->”能够执行任何javascript脚本,在Controller上的操做不会被录下,只有页面上的直接操做才会被记录。
点击“登出”
在Controller上点击“Stop”完成录制
输入测试的开始地址
http://sahitest.com/demo/training/login.htm
点击“Play”按钮
脚本中的步骤会被执行,Controller也会在“Statement”里面输出执行的结果,一旦执行完毕,会在底部出现“SUCCSESS”或者“FAILURE”的字样。
/* --Objects Definitions Above-- */ function login($user, $password){ _setValue(_textbox("user"), $user); _setValue(_password("password"), $password); _click(_submit("Login")); } function addBooks($qJava, $qRuby, $qPython){ _setValue(_textbox("q"), $qJava); _setValue(_textbox("q[1]"), $qRuby); _setValue(_textbox("q[2]"), $qPython); _click(_button("Add")); } function verifyTotal($total){ _assertExists(_textbox("total")); _assert(_isVisible(_textbox("total"))); _assertEqual($total, _getValue(_textbox("total"))); } function logout(){ _click(_button("Logout")); } /* --Functions Above-- */ _navigateTo("http://sahi.co.in/demo/training/"); login("test", "secret"); addBooks("2", "3", "1"); verifyTotal("1550"); logout();
first_script_lib.sah
function login($user, $password){ _setValue(_textbox("user"), $user); _setValue(_password("password"), $password); _click(_submit("Login")); } function addBooks($qJava, $qRuby, $qPython){ _setValue(_textbox("q"), $qJava); _setValue(_textbox("q[1]"), $qRuby); _setValue(_textbox("q[2]"), $qPython); _click(_button("Add")); } function verifyTotal($total){ _assertExists(_textbox("total")); _assert(_isVisible(_textbox("total"))); _assertEqual($total, _getValue(_textbox("total"))); } function logout(){ _click(_button("Logout")); }
first_script.sah
_include("first_script_lib.sah"); _navigateTo("http://sahi.co.in/demo/training/"); login("test", "secret"); addBooks("2", "3", "1"); verifyTotal("1550"); logout();
$ ./testrunner.sh first_script.sah http://sahitest.com/demo/training/ firefox
invalid_login.sah
_setValue(_textbox("user"), "test"); _setValue(_password("password"), "badpassword"); _click(_submit("Login")); _assert(_isVisible(_div("errorMessage"))); _assertEqual("Invalid username or password", _getText(_div("errorMessage")));
tutorial.suite
first_script.sah invalid_login.sah
命令行运行
$ ./testrunner.sh tutorial.suite http://sahitest.com/demo/training/ chrome
执行结果