- End to End Test
- Integration Test
- Unit Test
In my mind, smoking test is end to end test, feature test is integration test. We want to enable everybody writing automation test.
- cover main path/feature
- make sure product 80% correct
- good feedback for product
- running time is long, slow feedback
- easy to break, hard to maintain
- not somebody's responsibility, everyone's
- cover most case of specific feature
- make sure all path/case is correct
- good feedback for specific feature
- running time is short, fast feedback
- easy to break, not hard to maintain
- not somebody's responsibility, everyone's
- start in ThoughtWorks, currently host by community
- a lot of tools, such as IDE
- webdriver introduced in version 2.0
- different webdriver control different browser
control browser, simulate end user interacte with browser
- selenium, firefox
- webkit, web browser engine
- poltergeist, phantomjs
- watir, IE
- ruby gem
- provide high level DSL, adapted by differ webdirver
- integrate with rails, rspec, cucumber and minitest
fill_in('username', 'support')
capybara -> webdriver -> browser
We use rspec to write feature test
short test == feature test
long test == smoking test
require "rails_helper"
RSpec.feature "Widget management", :type => :feature do
scenario "User creates a new widget" do
visit "/widgets/new"
fill_in "Name", :with => "My Widget"
click_button "Create Widget"
expect(page).to have_text("Widget was successfully created.")
end
end
- 咱哥的文章
- extract visit, fill_in into object, ready to reuse in next test
- introduction
- page model
- on_page_with method
- step method
- plain ruby module
- use
PageWith
as prefix - need
include Gizmo::PageMixin
- has
valid
,state
,query
andaction
method
module PageWithGithubSearch
include Gizmo::PageMixin
# valid method
def valid?
has_selector?("form[action='/search']")
end
# state method
def link_with_text(value)
find("a", :text => value)
end
# query method
def have_content(value)
has_content?(value)
end
# action method
define_action :click_element do |element|
locate(element).click
end
end
feature 'smoke test', :smoking do
scenario 'support create organizations ' do
on_page_with :github_search do
expect(page.link_with_text('search')).to be_truthy
page.click_element('.search')
expect(page).to have_content('search results')
end
end
end
we refactor that
on_page_with : github_search do
step :-, :click_element, with: { element: '.search' }
sleep(1)
expect(page).to have_text 'search results'
end
- spec/features/smokingtest, test file
- lib/active_document/lib/dsl.rb, DSL in test file
- lib/gizmo/pages, page object
- create new test fil in
spec/features
- create/reuse page object in
lib/gizmo/pages
- add new method in page object
- run and debug
- start web server
- setup database
- write code to control browser
- asset result on browser page
- prepare assets file, such as js, css, running command
webpack && gulp vendor
- run feature test, running command
TEST_TYPE=smoking rake test:smoking_locally
, capybara will start web server - test file and page object file will be loaded and run
- run feature test, runnning command
REMOTE=https://www.gcbeta.com TEST_TYPE=smoking rake test:smoking_remotely
- no need start web server, just simulate user click
- need remove data after running