Created
April 6, 2009 02:22
-
-
Save gugod/90615 to your computer and use it in GitHub Desktop.
Cucumber + Watir Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default: --language zh-TW --format progress . | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'jcode' | |
$KCODE = 'u' | |
require 'spec/expectations' | |
if ENV['FIREWATIR'] | |
require 'firewatir' | |
Browser = FireWatir::Firefox | |
else | |
case RUBY_PLATFORM | |
when /darwin/ | |
require 'safariwatir' | |
Browser = Watir::Safari | |
when /win32|mingw/ | |
require 'watir' | |
Browser = Watir::IE | |
WIN32OLE.codepage = WIN32OLE::CP_UTF8 | |
when /java/ | |
require 'celerity' | |
Browser = Celerity::Browser | |
else | |
raise "This platform is not supported (#{PLATFORM})" | |
end | |
end | |
# "before all" | |
browser = Browser.new | |
Before do | |
@browser = browser | |
@test_server = "http://example.com" | |
end | |
# "after all" | |
at_exit do | |
browser.close | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
功能: 登入與註冊 | |
為了使用微笑餐盤的功能 | |
身為訪客 | |
我應能進行註冊,並且登入 | |
場景: 看見登入與註冊的連結 | |
假設我正在看首頁 | |
而且我是個訪客 | |
那麼我應能看見登入及註冊的連結 | |
場景: 看見登入的表單 | |
假設我是個訪客 | |
而且我能在首頁看見登入的連結 | |
而且我點擊了登入的連結 | |
那麼我應能看見登入的表單 | |
場景: 看見註冊的表單 | |
假設我是個訪客 | |
而且我能在首頁看見註冊的連結 | |
而且我點擊了註冊的連結 | |
那麼我應能看見註冊的表單 | |
場景: 以測試使用者登入 | |
假設我是使用者 user1 | |
而且我正在看首頁 | |
而且我點擊了登入的連結 | |
那麼我應能利用首頁的登入表單,以帳號 "user1", 密碼 "password1" 登入此網站。 | |
場景大綱: 登入失敗時 | |
假設我是個訪客 | |
而且我以 <帳號> 及 <密碼> 進行登入 | |
那麼我應再次看見登入畫面,並告知我登入失敗 | |
例子: | |
| 帳號 | 密碼 | | |
| qoo | kkyy | | |
| root | kkyyzz | | |
| nonexists | asdfg | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
Given /^我正在看首頁$/ do | |
@browser.goto @test_server | |
end | |
And /^我是個訪客$/ do | |
if @browser.url.match(/dashboard/) | |
@browser.goto @test_server + "/logout" | |
@browser.goto @test_server | |
end | |
end | |
Then /^我應能看見登入及註冊的連結$/ do | |
@browser.link(:href, /\/login$/).exists?.should be_true | |
@browser.link(:href, /\/signup$/).exists?.should be_true | |
end | |
Given /^我能在首頁看見登入的連結$/ do | |
@browser.goto @test_server | |
@browser.link(:href, /\/login$/).exists?.should be_true | |
end | |
And /^我點擊了登入的連結$/ do | |
@browser.link(:href, /\/login$/).click | |
end | |
Then /^我應能看見登入的表單$/ do | |
@browser.form(:action, /\/session$/).exists?.should be_true | |
end | |
Given /^我能在首頁看見註冊的連結$/ do | |
@browser.goto @test_server | |
@browser.link(:href, /\/signup$/).exists?.should be_true | |
end | |
And /^我點擊了註冊的連結$/ do | |
@browser.link(:href, /\/signup$/).click | |
end | |
Then /^我應能看見註冊的表單$/ do | |
@browser.form(:action, /\/users$/).exists?.should be_true | |
end | |
Given /^我是使用者 qoo$/ do | |
@current_test_account = "qoo" | |
end | |
Then /^我應能利用首頁的登入表單,以帳號 "([^\"]*)", 密碼 "([^\"]*)" 登入此網站。$/ do |arg1, arg2| | |
@browser.text_field(:name, "login").set(arg1) | |
@browser.text_field(:name, "password").set(arg2) | |
@browser.form(:action, /\/session$/).submit; | |
@browser.url.should match(/dashboard/) | |
end | |
And /^我以 (.+) 及 (.+) 進行登入$/ do |username, password| | |
@browser.goto @test_server | |
@browser.link(:href, /\/login$/).click | |
@browser.text_field(:name, "login").set(username) | |
@browser.text_field(:name, "password").set(password) | |
@browser.form(:action, /\/session$/).submit | |
end | |
Then /^我應再次看見登入畫面,並告知我登入失敗$/ do | |
@browser.url.should match(/\/login$/) | |
@browser.div(:class, "error_stickie").exists?.should be_true | |
@browser.div(:class, "error_stickie").text.should include("登入失敗") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment