Skip to content

Commit

Permalink
Initial revision with everything running in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Grove committed Sep 20, 2010
0 parents commit a0caf80
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default: --format html --out <%= ENV['SELENIUM_REPORT_FILENAME'] %> --format pretty -r features/support/env.rb -r features/support/enhanced.rb -r features/step_definitions features/enhanced
19 changes: 19 additions & 0 deletions features/enhanced/search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: As a user, I want search results returned

Scenario Outline: Return Search Results for a term
Given I am on the Google Homepage
When I enter a "<term>"
Then the search results should include "<result>"

Examples: Correct Results
| term | result |
| banana | fruit |
| cheese | Cheddar |

Examples: Incorrect Results
| term | result |
| banana | Jim Hacker |
| cheese | Humphrey Appleby |
| steak | Bernard Woolley |


13 changes: 13 additions & 0 deletions features/step_definitions/steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Given /^I am on the Google Homepage$/ do
@browser.open "/"
end

When /^I enter a "([^\"]*)"$/ do |term|
@browser.type "q", term
@browser.click "btnG"
end

Then /^the search results should include "([^\"]*)"$/ do |result|
source = @browser.get_html_source
raise Exception unless source.include?(result)
end
29 changes: 29 additions & 0 deletions features/support/enhanced.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
host = ENV['host'] || "http://google.com"

ondemand = YAML.load_file("ondemand.yml")

Before do |scenario|
outline = scenario.scenario_outline
job_name = "#{outline.name.capitalize}: #{scenario.name}"

@browser = Selenium::Client::Driver.new(
:host => "saucelabs.com",
:port => 4444,
:browser =>
{
"username" => ondemand["username"],
"access-key" => ondemand["api_key"],
"os" => ENV['SELENIUM_BROWSER_OS'],
"browser" => ENV['SELENIUM_BROWSER_NAME'],
"browser-version" => ENV['SELENIUM_BROWSER_VERSION'],
"job-name" => job_name
}.to_json,
:url => host,
:timeout_in_second => 90)

@browser.start_new_browser_session
end

After do |scenario|
@browser.close_current_browser_session
end
10 changes: 10 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'selenium/client'
require 'json'
require 'yaml'

Before do |scenario|
end

# "after all"
at_exit do
end
1 change: 1 addition & 0 deletions features/support/plain.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'cucumber/formatter/unicode'
2 changes: 2 additions & 0 deletions ondemand.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
username: your-sauce-labs-username
api_key: your-sauce-labs-api-key
45 changes: 45 additions & 0 deletions rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'rubygems'
require 'cucumber/rake/task'
require 'selenium/rake/tasks'
require 'parallel'

# Change these to specify which browsers on which
# platforms you want to cover
@browsers = [{:os => "Windows 2003", :name => "iehta", :version => "6."},
{:os => "Windows 2003", :name => "iehta", :version => "7."},
{:os => "Windows 2003", :name => "iehta", :version => "8."},
{:os => "Windows 2003", :name => "firefox", :version => "3."},
{:os => "Windows 2003", :name => "safari", :version => "4."},
{:os => "Windows 2003", :name => "googlechrome", :version => ""}]


desc "Invoke behaviours on all browsers on specified platform"
task :test do
year, month, day = Date.today.strftime("%Y,%m,%d").split(",")
dir = "reports/#{year}/#{month}"
FileUtils::mkdir_p(dir)

Parallel.map(@browsers, :in_processes => @browsers.count) do |browser|
begin
ENV['SELENIUM_BROWSER_OS'] = browser[:os]
ENV['SELENIUM_BROWSER_NAME'] = browser[:name]
ENV['SELENIUM_BROWSER_VERSION'] = browser[:version]
ENV['SELENIUM_REPORT_FILENAME'] = "#{dir}/#{day}-#{browser[:os]}_#{browser[:name]}_#{browser[:version]}.html".gsub(/\s/, "_").gsub("..", ".")

year, month, day = Date.today.strftime("%Y,%m,%d").split(",")
dir = "reports/#{year}/#{month}"

Rake::Task[ :run_browser_tests ].execute({ :browser_name => browser[:name],
:browser_version => browser[:version],
:browser_od => browser[:os] })
rescue RuntimeError
puts "Error while running task"
end
end
end

Cucumber::Rake::Task.new(:'run_browser_tests') do |t|
t.cucumber_opts = "--format pretty --format html features"
end

task :default => [:test]

0 comments on commit a0caf80

Please sign in to comment.