cucumber-selenium-standalone 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cucumber_standalone'
4
+ CucumberStandalone.start
@@ -0,0 +1,51 @@
1
+ require 'thor'
2
+ require 'thor/group'
3
+ require 'fileutils'
4
+
5
+ class CucumberStandalone < Thor::Group
6
+ include Thor::Actions
7
+
8
+ VERSION = "0.0.1"
9
+
10
+ argument :dir_name
11
+
12
+ def self.source_root
13
+ File.join(File.dirname(__FILE__), '..', 'templates')
14
+ end
15
+
16
+ def create_new_cucumber_directory
17
+ self.destination_root = File.expand_path(dir_name, destination_root)
18
+ make_empty_directory
19
+ FileUtils.cd(destination_root)
20
+ gemfile_rakefile_cukeyml
21
+ features_directory_and_files
22
+ end
23
+
24
+ protected
25
+
26
+ def make_empty_directory
27
+ empty_directory '.'
28
+ end
29
+
30
+ def features_directory_and_files
31
+ empty_directory 'features'
32
+
33
+ inside 'features' do
34
+ template 'example.feature', 'example.feature'
35
+ empty_directory 'support'
36
+ template 'support/env.rb', 'support/env.rb'
37
+ template 'support/hooks.rb', 'support/hooks.rb'
38
+ template 'support/paths.rb', 'support/paths.rb'
39
+ template 'step_definitions/web_steps.rb'
40
+ end
41
+ end
42
+
43
+ def gemfile_rakefile_cukeyml
44
+ inside destination_root do
45
+ template 'Gemfile'
46
+ template 'Rakefile'
47
+ template 'cucumber.yml'
48
+ end
49
+ end
50
+
51
+ end
data/templates/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rake', '0.8.7'
4
+ gem 'rspec', '2.2.0'
5
+ gem 'cucumber', '0.10.6'
6
+ gem 'cucumber-rails', "0.4.1"
7
+ gem 'nokogiri', "1.5.0"
8
+ gem 'capybara', '1.0'
9
+ gem 'selenium-webdriver', '0.2.2'
10
+
@@ -0,0 +1,68 @@
1
+ vendored_cucumber_bin = Dir["#{File.expand_path(File.dirname(__FILE__))}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
2
+ $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
3
+
4
+ begin
5
+ require 'cucumber/rake/task'
6
+
7
+ namespace :cucumber do
8
+ Cucumber::Rake::Task.new('ok', 'Run features that should pass') do |t|
9
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
10
+ t.fork = true # You may get faster startup if you set this to false
11
+ t.profile = 'default'
12
+ end
13
+
14
+ Cucumber::Rake::Task.new('wip', 'Run features that are being worked on') do |t|
15
+ t.binary = vendored_cucumber_bin
16
+ t.fork = true # You may get faster startup if you set this to false
17
+ t.profile = 'wip'
18
+ end
19
+
20
+ # Add a new Thread if there is a new profile in the feature files that
21
+ # you'd like to run in parallel
22
+ @cucumber_profile_categories = [].each do |profile|
23
+ Cucumber::Rake::Task.new(profile, "Run features annotated with @#{profile}") do |t|
24
+ t.binary = vendored_cucumber_bin
25
+ t.fork = true # You may get faster startup if you set this to false
26
+ t.profile = profile
27
+ end
28
+ end
29
+
30
+ desc('Run the functional test suite in parallel on your local or on a Selenium Grid enabled CI server')
31
+ task :parallel_tests do
32
+
33
+ all_tests_passed = true
34
+
35
+ @cucumber_profile_categories.each do |profile|
36
+ Thread.new { system("bundle exec rake cucumber:#{profile}") }
37
+ end
38
+
39
+ Thread.list.each do |t|
40
+ # Wait for the thread to finish if it isn't this thread (i.e. the main thread).
41
+ if t != Thread.current
42
+ t.join
43
+ all_tests_passed = false unless t.value
44
+ end
45
+ end
46
+
47
+ raise "Some of the functional tests failed" unless all_tests_passed
48
+ end
49
+
50
+ Cucumber::Rake::Task.new('rerun', 'Record failing features and run only them if any exist') do |t|
51
+ t.binary = vendored_cucumber_bin
52
+ t.fork = true # You may get faster startup if you set this to false
53
+ t.profile = 'rerun'
54
+ end
55
+
56
+ desc 'Run all features'
57
+ task :all => [:ok, :wip]
58
+ end
59
+ desc 'Alias for cucumber:ok'
60
+ task :cucumber => 'cucumber:ok'
61
+
62
+ task :default => :cucumber
63
+ rescue LoadError
64
+ desc 'cucumber rake task not available (cucumber not installed)'
65
+ task :cucumber do
66
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ default: --format progress --strict --tags ~@wip features
2
+ wip: --tags @wip:3 --wip features
3
+ rerun: --format progress features --format rerun --out rerun.txt --strict --tags ~@wip
@@ -0,0 +1,10 @@
1
+ Feature: Google Search for "Functional Testing"
2
+ As a developer that wants to learn more about functional testing with Cucumber
3
+ I should be able to search "Functional Testing with Cucumber" on Google
4
+
5
+ @async_off
6
+ Scenario: Search "Functional Testing with Cucumber" on Google
7
+ Given I go to http://google.com
8
+ When I fill in "q" with "Functional Testing with Cucumber"
9
+ And I press "Google Search"
10
+ Then I should see "Search Results"
@@ -0,0 +1,212 @@
1
+ require 'uri'
2
+ require 'cgi'
3
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
4
+
5
+ module WithinHelpers
6
+ def with_scope(locator)
7
+ locator ? within(locator) { yield } : yield
8
+ end
9
+ end
10
+ World(WithinHelpers)
11
+
12
+ Given /^(?:|I )am on (.+)$/ do |page_name|
13
+ visit path_to(page_name)
14
+ end
15
+
16
+ When /^(?:|I )go to (.+)$/ do |page_name|
17
+ visit path_to(page_name)
18
+ end
19
+
20
+ When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
21
+ with_scope(selector) do
22
+ click_button(button)
23
+ end
24
+ end
25
+
26
+ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
27
+ with_scope(selector) do
28
+ click_link(link)
29
+ end
30
+ end
31
+
32
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
33
+ with_scope(selector) do
34
+ fill_in(field, :with => value)
35
+ end
36
+ end
37
+
38
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
39
+ with_scope(selector) do
40
+ fill_in(field, :with => value)
41
+ end
42
+ end
43
+
44
+ # Use this to fill in an entire form with data from a table. Example:
45
+ #
46
+ # When I fill in the following:
47
+ # | Account Number | 5002 |
48
+ # | Expiry date | 2009-11-01 |
49
+ # | Note | Nice guy |
50
+ # | Wants Email? | |
51
+ #
52
+ # TODO: Add support for checkbox, select og option
53
+ # based on naming conventions.
54
+ #
55
+ When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
56
+ with_scope(selector) do
57
+ fields.rows_hash.each do |name, value|
58
+ When %{I fill in "#{name}" with "#{value}"}
59
+ end
60
+ end
61
+ end
62
+
63
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
64
+ with_scope(selector) do
65
+ select(value, :from => field)
66
+ end
67
+ end
68
+
69
+ When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
70
+ with_scope(selector) do
71
+ check(field)
72
+ end
73
+ end
74
+
75
+ When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
76
+ with_scope(selector) do
77
+ uncheck(field)
78
+ end
79
+ end
80
+
81
+ When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
82
+ with_scope(selector) do
83
+ choose(field)
84
+ end
85
+ end
86
+
87
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
88
+ with_scope(selector) do
89
+ attach_file(field, path)
90
+ end
91
+ end
92
+
93
+ Then /^(?:|I )should see JSON:$/ do |expected_json|
94
+ require 'json'
95
+ expected = JSON.pretty_generate(JSON.parse(expected_json))
96
+ actual = JSON.pretty_generate(JSON.parse(response.body))
97
+ expected.should == actual
98
+ end
99
+
100
+ Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
101
+ with_scope(selector) do
102
+ if page.respond_to? :should
103
+ page.should have_content(text)
104
+ else
105
+ assert page.has_content?(text)
106
+ end
107
+ end
108
+ end
109
+
110
+ Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
111
+ regexp = Regexp.new(regexp)
112
+ with_scope(selector) do
113
+ if page.respond_to? :should
114
+ page.should have_xpath('//*', :text => regexp)
115
+ else
116
+ assert page.has_xpath?('//*', :text => regexp)
117
+ end
118
+ end
119
+ end
120
+
121
+ Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
122
+ with_scope(selector) do
123
+ if page.respond_to? :should
124
+ page.should have_no_content(text)
125
+ else
126
+ assert page.has_no_content?(text)
127
+ end
128
+ end
129
+ end
130
+
131
+ Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
132
+ regexp = Regexp.new(regexp)
133
+ with_scope(selector) do
134
+ if page.respond_to? :should
135
+ page.should have_no_xpath('//*', :text => regexp)
136
+ else
137
+ assert page.has_no_xpath?('//*', :text => regexp)
138
+ end
139
+ end
140
+ end
141
+
142
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
143
+ with_scope(selector) do
144
+ field = find_field(field)
145
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
146
+ if field_value.respond_to? :should
147
+ field_value.should =~ /#{value}/
148
+ else
149
+ assert_match(/#{value}/, field_value)
150
+ end
151
+ end
152
+ end
153
+
154
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
155
+ with_scope(selector) do
156
+ field = find_field(field)
157
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
158
+ if field_value.respond_to? :should_not
159
+ field_value.should_not =~ /#{value}/
160
+ else
161
+ assert_no_match(/#{value}/, field_value)
162
+ end
163
+ end
164
+ end
165
+
166
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
167
+ with_scope(selector) do
168
+ field_checked = find_field(label)['checked']
169
+ if field_checked.respond_to? :should
170
+ field_checked.should be_true
171
+ else
172
+ assert field_checked
173
+ end
174
+ end
175
+ end
176
+
177
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
178
+ with_scope(selector) do
179
+ field_checked = find_field(label)['checked']
180
+ if field_checked.respond_to? :should
181
+ field_checked.should be_false
182
+ else
183
+ assert !field_checked
184
+ end
185
+ end
186
+ end
187
+
188
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
189
+ current_path = URI.parse(current_url).path
190
+ if current_path.respond_to? :should
191
+ current_path.should == path_to(page_name)
192
+ else
193
+ assert_equal path_to(page_name), current_path
194
+ end
195
+ end
196
+
197
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
198
+ query = URI.parse(current_url).query
199
+ actual_params = query ? CGI.parse(query) : {}
200
+ expected_params = {}
201
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
202
+
203
+ if actual_params.respond_to? :should
204
+ actual_params.should == expected_params
205
+ else
206
+ assert_equal expected_params, actual_params
207
+ end
208
+ end
209
+
210
+ Then /^show me the page$/ do
211
+ save_and_open_page
212
+ end
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require "bundler/setup"
3
+
4
+ require 'cucumber'
5
+ require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
6
+ require 'cucumber/web/tableish'
7
+
8
+ require 'capybara'
9
+ require 'capybara/cucumber'
10
+ require 'capybara/session'
11
+
12
+ require 'rspec'
13
+ require 'selenium-webdriver'
14
+
15
+ Capybara.default_selector = :css
16
+ Capybara.default_wait_time = 60
17
+
18
+ #Swap this for the environment you are testing
19
+ Capybara.app_host = ENV['FUNCTIONAL_TESTING_HOST'] || "http://localhost"
20
+
21
+ Capybara.default_driver = :selenium
22
+
23
+ custom_firefox_profile = Selenium::WebDriver::Firefox::Profile.new
24
+ # this setting prevents the loading of images which speeds things up dramatically
25
+ custom_firefox_profile["permissions.default.image"] = 2
26
+
27
+ if ENV['REMOTE_SELENIUM'] == true || ENV['REMOTE_SELENIUM'] == "true"
28
+ Capybara.register_driver :selenium do |app|
29
+ remote_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
30
+ remote_capabilities.firefox_profile = custom_firefox_profile
31
+ Capybara::Selenium::Driver.new(app,
32
+ :browser => :remote,
33
+ :desired_capabilities => remote_capabilities,
34
+ :url => "#{ENV['REMOTE_SELENIUM_HOST']}:4444/wd/hub")
35
+ end
36
+ else
37
+ Capybara.register_driver :selenium do |app|
38
+ Capybara::Selenium::Driver.new(app,
39
+ :profile => custom_firefox_profile)
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ Before('@async_off') do
2
+ page.driver.options[:resynchronize] = false
3
+ end
@@ -0,0 +1,35 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in web_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the home\s?page/
12
+ '/'
13
+ when /http:\/\/google.com/
14
+ 'http://google.com'
15
+
16
+ # Add more mappings here.
17
+ # Here is an example that pulls values out of the Regexp:
18
+ #
19
+ # when /^(.*)'s profile page$/i
20
+ # user_profile_path(User.find_by_login($1))
21
+
22
+ else
23
+ begin
24
+ page_name =~ /the (.*) page/
25
+ path_components = $1.split(/\s+/)
26
+ self.send(path_components.push('path').join('_').to_sym)
27
+ rescue Object => e
28
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
29
+ "Now, go and add a mapping in #{__FILE__}"
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ World(NavigationHelpers)
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cucumber-selenium-standalone
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Nick Zalabak
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-26 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thor
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 14
31
+ - 6
32
+ version: 0.14.6
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - "="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 8
46
+ - 7
47
+ version: 0.8.7
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: cucumber-rails
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - "="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ - 4
61
+ - 1
62
+ version: 0.4.1
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: cucumber
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - "="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ - 10
76
+ - 6
77
+ version: 0.10.6
78
+ type: :runtime
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: selenium-webdriver
82
+ prerelease: false
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - "="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ - 2
91
+ - 2
92
+ version: 0.2.2
93
+ type: :runtime
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: capybara
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - "="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 1
105
+ - 0
106
+ version: "1.0"
107
+ type: :runtime
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: bundler
111
+ prerelease: false
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ segments:
118
+ - 1
119
+ - 0
120
+ - 15
121
+ version: 1.0.15
122
+ type: :runtime
123
+ version_requirements: *id007
124
+ - !ruby/object:Gem::Dependency
125
+ name: rake
126
+ prerelease: false
127
+ requirement: &id008 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - "="
131
+ - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
134
+ - 8
135
+ - 7
136
+ version: 0.8.7
137
+ type: :runtime
138
+ version_requirements: *id008
139
+ - !ruby/object:Gem::Dependency
140
+ name: nokogiri
141
+ prerelease: false
142
+ requirement: &id009 !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - "="
146
+ - !ruby/object:Gem::Version
147
+ segments:
148
+ - 1
149
+ - 5
150
+ - 0
151
+ version: 1.5.0
152
+ type: :runtime
153
+ version_requirements: *id009
154
+ - !ruby/object:Gem::Dependency
155
+ name: rspec
156
+ prerelease: false
157
+ requirement: &id010 !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - "="
161
+ - !ruby/object:Gem::Version
162
+ segments:
163
+ - 2
164
+ - 5
165
+ - 0
166
+ version: 2.5.0
167
+ type: :runtime
168
+ version_requirements: *id010
169
+ description: generates directory and required files for any type of project needing to test with Cucumber/Capybara/Selenium
170
+ email: techwhizbang@gmail.com
171
+ executables:
172
+ - cucumber-selenium-standalone
173
+ extensions: []
174
+
175
+ extra_rdoc_files: []
176
+
177
+ files:
178
+ - bin/cucumber-selenium-standalone
179
+ - lib/cucumber_standalone.rb
180
+ - templates/cucumber.yml
181
+ - templates/Gemfile
182
+ - templates/Rakefile
183
+ - templates/features/example.feature
184
+ - templates/features/step_definitions/web_steps.rb
185
+ - templates/features/support/env.rb
186
+ - templates/features/support/hooks.rb
187
+ - templates/features/support/paths.rb
188
+ has_rdoc: true
189
+ homepage: http://github.com/techwhizbang/cucumber-selenium-standalone
190
+ licenses: []
191
+
192
+ post_install_message:
193
+ rdoc_options: []
194
+
195
+ require_paths:
196
+ - lib
197
+ required_ruby_version: !ruby/object:Gem::Requirement
198
+ none: false
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ segments:
203
+ - 0
204
+ version: "0"
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ segments:
211
+ - 0
212
+ version: "0"
213
+ requirements: []
214
+
215
+ rubyforge_project:
216
+ rubygems_version: 1.3.7
217
+ signing_key:
218
+ specification_version: 3
219
+ summary: A basic archetype for a standalone Cucumber/Capybara/Selenium test suite
220
+ test_files: []
221
+