WebDriverについての最近の
記事は、Webアプリケーションのテストを自動化するために使用する複雑さについて少し思い出しました。
そのため、テストは
RSpec +
Watir WebDriverバンドルに基づいています(Railsアプリケーションの場合は、Capybaraの方が適切です)。 BundlerおよびローカルWebDriversのサポートにより、テスターの職場で簡単なインストールが実行されます(Ruby 1.9、Rubygems、Bundlerの
bundle install
、および
bundle install
)。 Gemfileソース:
source :rubygems gem "watir-webdriver", "~>0.6.1" gem "rspec-core", "~> 2.0" gem "rspec-expectations", "~> 2.0" gem "rr", "~> 1.0" gem "ci_reporter", "~> 1.7"
ci_reporter gemにより、Jenkins CIとの統合が実行され、parallel_tests gemおよびSelenium Gridにより、テストの並列化が実行されます(現在、本番環境ではまだ並列テストは使用されていません)。
テスト例を次に示します。
describe "FirstSite" do before(:all) do site! "first" end
テスト対象のサイトとテスト方法は、設定で定義されています。
--- production: sites: first: "http://staging.example.com" webdriver: hub: "http://192.168.13.6:8888/wd/hub" test: sites: first: "http://staging.example.com" webdriver: hub: "http://192.168.13.6:8888/wd/hub" development: sites: first: "localhost:5678" webdriver: local: true
環境変数WATIR_ENVおよびWATIR_BROWSERを設定することにより、特定のテスト実行のテスト環境を定義します。
すべてのカスタマイズは2つのファイルによって実行されます。 .rspec:
--format nested
--color
--require ./spec_helper.rb
spec_helper.rb:
require "rubygems" require "bundler/setup" require "yaml" require "watir-webdriver" require "rspec/core" $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')