watircraft 是基于watir的BDD(行为驱动开发)
安装:
要先装ruby环境
gem install bret-watircraft --remote
使用:
以google为例
1.运行- cmd,输入:watircraft google。google为项目名称,这里会生成批量的文件和目录。
2.打开config/environments.yml,编辑文件如下:
test:
url: http://www.google.com
3.dos里输入:cd google
4.dos里输入:scriptgenerate spec search
5.编辑test/specs/search_spec.rb
如下:
$LOAD_PATH.unshift File.dirname(__FILE__) unless
$LOAD_PATH.include? File.dirname(__FILE__)
require 'spec_helper'
describe "Search" do
# TODO: Change this string to describe your test
it "should find WatirCraft" do
# TODO: Add your test steps here. Remove "pending"
browser.text_field(:name, 'q').set 'WatirCraft'
browser.button(:name, 'btnG').click
browser.text.should include('Test automation for web applications')
end
# TODO: Add additional tests here. Each test should look like
# it "test description" do
# ... test steps ...
# end
end
6. 执行search_spec.rb
rake spec
或 ruby test/specs/search_spec.rb