acceptance_test 1.5.5 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGES +5 -1
  3. data/Gemfile +4 -1
  4. data/Gemfile.lock +11 -11
  5. data/Rakefile +0 -6
  6. data/features/wikipedia/step_definitions/steps.rb +2 -2
  7. data/lib/acceptance_test/acceptance_test.rb +57 -140
  8. data/lib/acceptance_test/driver_manager.rb +138 -0
  9. data/lib/acceptance_test/{gherkin_helper.rb → gherkin_ext.rb} +2 -5
  10. data/lib/acceptance_test/page_set.rb +38 -1
  11. data/lib/acceptance_test/turnip_ext.rb +177 -0
  12. data/lib/acceptance_test/version.rb +1 -1
  13. data/lib/tasks/rspec.rake +7 -0
  14. data/spec/{features/data.csv → data.csv} +0 -0
  15. data/spec/features/search_with_drivers.feature +4 -3
  16. data/spec/features/search_with_examples_from_csv.feature +1 -1
  17. data/spec/features/search_with_pages.feature +13 -0
  18. data/spec/support/pages/main_page.rb +17 -0
  19. data/spec/support/{wikipedia/wikipedia_page_set.rb → pages/wikipedia_pages.rb} +8 -5
  20. data/spec/{features → support}/steps/common_steps.rb +0 -0
  21. data/spec/{features → support}/steps/search_with_drivers_steps.rb +2 -17
  22. data/spec/{features → support}/steps/search_with_examples_from_csv_steps.rb +1 -1
  23. data/spec/support/steps/search_with_pages_steps.rb +37 -0
  24. data/spec/{features → support}/steps/search_with_table_steps.rb +1 -1
  25. data/spec/test_helper.rb +1 -0
  26. data/spec/turnip_helper.rb +8 -9
  27. data/spec/wikipedia_search_spec.rb +5 -0
  28. data/spec/wikipedia_search_with_pages_spec.rb +8 -8
  29. metadata +26 -19
  30. data/lib/acceptance_test/turnip_helper.rb +0 -76
  31. data/spec/support/wikipedia/main_page.rb +0 -13
  32. data/turnip +0 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzIxZjhmY2Y3ODZhODMyOWYwNGJm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mFiN2I4MjU4ZjcxYmNlNGExM2M=
data/CHANGES CHANGED
@@ -135,4 +135,8 @@
135
135
 
136
136
  == Version 1.5.5
137
137
 
138
- * Bug fixes
138
+ * Bug fixes
139
+
140
+ == Version 1.6.0
141
+
142
+ * Refactor the code
data/Gemfile CHANGED
@@ -12,7 +12,7 @@ end
12
12
 
13
13
  group :acceptance_test do
14
14
  gem "activesupport", "~> 4.1.6"
15
- gem "capybara", "~> 2.4.1"
15
+ gem "capybara", "~> 2.4.3"
16
16
  gem "capybara-firebug", "~> 2.1.0"
17
17
  gem "selenium-webdriver", "~> 2.43.0"
18
18
 
@@ -27,6 +27,9 @@ group :acceptance_test do
27
27
  # Debian: sudo apt-get install libqt4-dev
28
28
  # Fedora: yum install qt-webkit-devell
29
29
 
30
+ # for chrome support:
31
+ # brew install chromedriver
32
+
30
33
  # brew install phantomjs
31
34
  gem "poltergeist", "~> 1.5.1"
32
35
  end
data/Gemfile.lock CHANGED
@@ -8,7 +8,7 @@ GEM
8
8
  thread_safe (~> 0.1)
9
9
  tzinfo (~> 1.1)
10
10
  builder (3.2.2)
11
- capybara (2.4.1)
11
+ capybara (2.4.3)
12
12
  mime-types (>= 1.16)
13
13
  nokogiri (>= 1.3.3)
14
14
  rack (>= 1.0.0)
@@ -20,7 +20,7 @@ GEM
20
20
  capybara-webkit (1.3.0)
21
21
  capybara (>= 2.0.2, < 2.5.0)
22
22
  json
23
- childprocess (0.5.3)
23
+ childprocess (0.5.5)
24
24
  ffi (~> 1.0, >= 1.0.11)
25
25
  cliver (0.3.2)
26
26
  cucumber (1.3.17)
@@ -31,7 +31,7 @@ GEM
31
31
  multi_test (>= 0.1.1)
32
32
  debugger-ruby_core_source (1.3.5)
33
33
  diff-lcs (1.2.5)
34
- ffi (1.9.3)
34
+ ffi (1.9.6)
35
35
  file_utils (1.0.7)
36
36
  gemcutter (0.7.1)
37
37
  gemspec_deps_gen (1.1.2)
@@ -42,9 +42,9 @@ GEM
42
42
  i18n (0.6.11)
43
43
  json (1.8.1)
44
44
  metaclass (0.0.4)
45
- mime-types (2.3)
45
+ mime-types (2.4.1)
46
46
  mini_portile (0.6.0)
47
- minitest (5.4.1)
47
+ minitest (5.4.2)
48
48
  mocha (1.1.0)
49
49
  metaclass (~> 0.0.1)
50
50
  multi_json (1.10.1)
@@ -64,16 +64,16 @@ GEM
64
64
  rspec-core (~> 3.1.0)
65
65
  rspec-expectations (~> 3.1.0)
66
66
  rspec-mocks (~> 3.1.0)
67
- rspec-core (3.1.3)
67
+ rspec-core (3.1.6)
68
68
  rspec-support (~> 3.1.0)
69
69
  rspec-example_steps (3.0.2)
70
70
  rspec-core (>= 3.0.0)
71
- rspec-expectations (3.1.1)
71
+ rspec-expectations (3.1.2)
72
72
  diff-lcs (>= 1.2.0, < 2.0)
73
73
  rspec-support (~> 3.1.0)
74
- rspec-mocks (3.1.0)
74
+ rspec-mocks (3.1.3)
75
75
  rspec-support (~> 3.1.0)
76
- rspec-support (3.1.0)
76
+ rspec-support (3.1.2)
77
77
  ruby-debug-base19x (0.11.30.pre12)
78
78
  debugger-ruby_core_source (>= 1.1.4)
79
79
  rake (>= 0.8.1)
@@ -92,7 +92,7 @@ GEM
92
92
  tzinfo (1.2.2)
93
93
  thread_safe (~> 0.1)
94
94
  websocket (1.2.1)
95
- websocket-driver (0.3.4)
95
+ websocket-driver (0.3.5)
96
96
  xpath (2.0.0)
97
97
  nokogiri (~> 1.3)
98
98
 
@@ -101,7 +101,7 @@ PLATFORMS
101
101
 
102
102
  DEPENDENCIES
103
103
  activesupport (~> 4.1.6)
104
- capybara (~> 2.4.1)
104
+ capybara (~> 2.4.3)
105
105
  capybara-firebug (~> 2.1.0)
106
106
  capybara-webkit (~> 1.3.0)
107
107
  cucumber (~> 1.3.17)
data/Rakefile CHANGED
@@ -40,9 +40,3 @@ end
40
40
  # system "mkdir -p $GEM_HOME/gems/debugger-ruby_core_source-1.2.3/lib"
41
41
  # system "cp -R ~/debugger-ruby_core_source/lib $GEM_HOME/gems/debugger-ruby_core_source-1.2.3"
42
42
  # end
43
-
44
- task :turnip do
45
- ARGV.shift
46
-
47
- system "bundle exec rspec -r turnip/rspec #{ARGV.join(' ')}"
48
- end
@@ -3,10 +3,10 @@ require 'yaml'
3
3
 
4
4
  require 'acceptance_test'
5
5
 
6
- require 'acceptance_test/gherkin_helper'
6
+ require 'acceptance_test/gherkin_ext'
7
7
 
8
8
  data_reader = lambda {|source_path| CSV.read(File.expand_path(source_path)) }
9
- GherkinHelper.instance.enable_external_source data_reader
9
+ GherkinExt.instance.enable_external_source data_reader
10
10
 
11
11
  acceptance_test = AcceptanceTest.instance
12
12
 
@@ -1,83 +1,72 @@
1
1
  require 'uri'
2
- require 'fileutils'
3
2
  require 'singleton'
4
3
 
5
- require 'capybara'
6
- require "capybara/dsl"
7
4
  require 'active_support/core_ext/hash'
8
5
 
9
- require 'acceptance_test/gherkin_helper'
10
- require 'acceptance_test/turnip_helper'
6
+ require 'acceptance_test/driver_manager'
7
+ require 'acceptance_test/gherkin_ext'
8
+ require 'acceptance_test/turnip_ext'
11
9
 
12
10
  class AcceptanceTest
13
11
  include Singleton
14
12
 
15
- attr_reader :config
13
+ attr_reader :config, :driver_manager
14
+
15
+ def initialize
16
+ @driver_manager = DriverManager.new
17
+ end
16
18
 
17
19
  def configure config={}
18
20
  if config
19
21
  @config = config.kind_of?(HashWithIndifferentAccess) ? config : HashWithIndifferentAccess.new(config)
20
22
  else
21
23
  @config = HashWithIndifferentAccess.new
22
-
23
- config[:screenshot_dir] = File.expand_path('tmp')
24
24
  end
25
25
 
26
- set_app_host
26
+ @config[:browser] = 'firefox' unless @config[:browser]
27
+ @config[:screenshot_dir] = File.expand_path('tmp') unless @config[:screenshot_dir]
28
+ end
29
+
30
+ def setup
31
+ Capybara.app_host = AcceptanceTest.instance.config[:webapp_url]
27
32
 
28
33
  Capybara.configure do |conf|
29
34
  conf.default_wait_time = timeout_in_seconds
30
- conf.match = :first
31
-
32
- conf.ignore_hidden_elements = false
33
35
  end
34
36
 
35
- ENV['APP_HOST'] ||= config[:webapp_url]
36
37
  ENV['WAIT_TIME'] ||= Capybara.default_wait_time.to_s
37
38
 
38
- # try to load capybara-related rspec library
39
- begin
40
- require 'capybara/rspec'
41
-
42
- RSpec.configure do |config|
43
- config.filter_run_excluding :exclude => true
44
- end
39
+ Capybara.default_driver = :selenium
40
+ end
45
41
 
46
- RSpec.configure do |config|
47
- config.include Capybara::DSL
48
- end
42
+ def teardown
43
+ Capybara.app_host = nil
49
44
 
50
- RSpec::Core::ExampleGroup.send :include, Capybara::DSL
51
- rescue
52
- ;
45
+ Capybara.configure do |conf|
46
+ conf.default_wait_time = 5
53
47
  end
54
48
 
55
- Capybara.default_driver = :selenium
56
- end
57
-
58
- def set_app_host
59
- Capybara.app_host = AcceptanceTest.instance.config[:webapp_url]
49
+ Capybara.default_driver = :rack_test
60
50
  end
61
51
 
62
- def enable_external_source data_reader
63
- GherkinHelper.instance.enable_external_source data_reader
64
- end
52
+ def before_test metadata={}, page=nil
53
+ setup unless Capybara.app_host
65
54
 
66
- def extend_turnip
67
- TurnipHelper.instance.extend_turnip
68
- end
55
+ tag = driver(metadata)
69
56
 
70
- def before metadata={}
71
- driver = driver(metadata)
57
+ if tag
58
+ driver_name = driver_manager.register_driver tag, config[:browser].to_sym, config[:selenium_url]
72
59
 
73
- if driver
74
- register_driver driver
60
+ if driver_name and Capybara.drivers[driver_name]
61
+ Capybara.current_driver = driver_name
62
+ Capybara.javascript_driver = driver_name
75
63
 
76
- select_driver driver
64
+ page.instance_variable_set(:@mode, driver_name) if page
65
+ end
77
66
  end
78
67
  end
79
68
 
80
- def after metadata={}, exception=nil, page=nil
69
+ def after_test metadata={}, exception=nil, page=nil
81
70
  driver = driver(metadata)
82
71
 
83
72
  if driver and exception and page and not [:webkit].include? driver
@@ -94,6 +83,7 @@ class AcceptanceTest
94
83
  end
95
84
 
96
85
  Capybara.current_driver = Capybara.default_driver
86
+ Capybara.javascript_driver = Capybara.default_driver
97
87
  end
98
88
 
99
89
  def create_shared_context name
@@ -120,7 +110,7 @@ class AcceptanceTest
120
110
  if tags.size > 0
121
111
  tag = tags.first.to_sym
122
112
 
123
- if AcceptanceTest.supported_drivers.include? tag
113
+ if driver_manager.supported_drivers.include? tag
124
114
  metadata[:driver] = tag
125
115
  end
126
116
  end
@@ -128,12 +118,24 @@ class AcceptanceTest
128
118
  metadata
129
119
  end
130
120
 
121
+ def extend_turnip
122
+ shared_context_name = "#{random_name}AcceptanceTest"
123
+
124
+ create_shared_context shared_context_name
125
+
126
+ TurnipExt.shared_context_with_turnip shared_context_name
127
+ end
128
+
129
+ def enable_external_source data_reader
130
+ GherkinExt.enable_external_source data_reader
131
+ end
132
+
131
133
  def driver metadata
132
134
  driver = ENV['DRIVER'].nil? ? nil : ENV['DRIVER'].to_sym
133
135
 
134
136
  driver = metadata[:driver] if driver.nil?
135
137
 
136
- self.class.supported_drivers.each do |supported_driver|
138
+ driver_manager.supported_drivers.each do |supported_driver|
137
139
  driver = supported_driver if metadata[supported_driver]
138
140
  break if driver
139
141
  end
@@ -143,13 +145,9 @@ class AcceptanceTest
143
145
  driver
144
146
  end
145
147
 
146
- def selenium_driver? driver
147
- driver.to_s =~ /selenium/
148
- end
149
-
150
- def self.supported_drivers
151
- [:webkit, :selenium, :poltergeist, :selenium_remote]
152
- end
148
+ # def selenium_driver? driver
149
+ # driver.to_s =~ /selenium/
150
+ # end
153
151
 
154
152
  def configure_rspec object=nil
155
153
  acceptance_test = self
@@ -165,11 +163,11 @@ class AcceptanceTest
165
163
  end
166
164
 
167
165
  rspec_conf.around(:each) do |example|
168
- acceptance_test.before(example.metadata)
166
+ acceptance_test.before_test(example.metadata, page)
169
167
 
170
168
  example.run
171
169
 
172
- acceptance_test.after(example.metadata, example.exception, page)
170
+ acceptance_test.after_test(example.metadata, example.exception, page)
173
171
  end
174
172
  end
175
173
 
@@ -187,92 +185,8 @@ class AcceptanceTest
187
185
  end
188
186
  end
189
187
 
190
- def register_driver driver
191
- case driver
192
- when :webkit
193
- require "capybara-webkit"
194
-
195
- when :selenium
196
- # nothing
197
-
198
- when :selenium_with_firebug
199
- require 'capybara/firebug'
200
-
201
- #Capybara.register_driver :selenium_with_firebug do |app|
202
- # profile = Selenium::WebDriver::Firefox::Profile.new
203
- # profile.enable_firebug
204
- # Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
205
- #end
206
-
207
- #Selenium::WebDriver::Firefox::Profile.firebug_version = '1.11.2'
208
- when :selenium_chrome
209
- unless Capybara.drivers[:selenium_chrome]
210
- Capybara.register_driver :selenium_chrome do |app|
211
- Capybara::Selenium::Driver.new(app, :browser => :chrome)
212
- end
213
- end
214
-
215
- when :poltergeist
216
- require 'capybara/poltergeist'
217
-
218
- unless Capybara.drivers[:poltergeist]
219
- Capybara.register_driver :poltergeist do |app|
220
- Capybara::Poltergeist::Driver.new(app, { debug: false })
221
- end
222
- end
223
-
224
- when :selenium_remote
225
- unless Capybara.drivers[:selenium_remote]
226
- Capybara.register_driver :selenium_remote do |app|
227
- Capybara::Selenium::Driver.new(app, {:browser => :remote, :url => config[:selenium_url]})
228
-
229
- #profile = Selenium::WebDriver::Firefox::Profile.new
230
- #profile.enable_firebug
231
- #
232
- #Capybara::Driver::Selenium.new(app, {
233
- # :browser => :remote,
234
- # :url => selenium_url,
235
- # :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
236
- #})
237
- end
238
- end
239
- when :selenium_safari
240
- unless Capybara.drivers[:selenium_safari]
241
- Capybara.register_driver :selenium_safari do |app|
242
- Capybara::Selenium::Driver.new(app, :browser => :safari)
243
- end
244
- end
245
- else
246
- # nothing
247
- end
248
- end
249
-
250
- def select_driver driver
251
- if selenium_driver?(driver)
252
- if driver == :selenium_remote
253
- Capybara.current_driver = driver
254
- Capybara.javascript_driver = driver
255
- else
256
- if acceptance_config_exist?
257
- Capybara.current_driver = driver
258
- Capybara.javascript_driver = driver
259
- else
260
- if Capybara.drivers[driver]
261
- Capybara.current_driver = driver
262
- Capybara.javascript_driver = driver
263
- end
264
- end
265
- end
266
- else
267
- if Capybara.drivers[driver]
268
- Capybara.current_driver = driver
269
- Capybara.javascript_driver = driver
270
- end
271
- end
272
- end
273
-
274
- def acceptance_config_exist?
275
- not config.nil?
188
+ def random_name
189
+ ('a'..'z').to_a.shuffle[0, 12].join
276
190
  end
277
191
 
278
192
  # def self.get_localhost
@@ -285,4 +199,7 @@ class AcceptanceTest
285
199
  # ensure
286
200
  # Socket.do_not_reverse_lookup = orig
287
201
  # end
202
+
203
+ # ip = `ifconfig | grep 'inet ' | grep -v 127.0.0.1 | cut -d ' ' -f2`.strip
204
+ # Capybara.app_host = http://#{ip}:#{Capybara.server_port}
288
205
  end
@@ -0,0 +1,138 @@
1
+ require 'capybara'
2
+ #require "capybara/dsl"
3
+
4
+ class DriverManager
5
+
6
+ def initialize
7
+ Capybara.configure do |conf|
8
+ #conf.default_wait_time = timeout_in_seconds
9
+ conf.match = :first
10
+
11
+ conf.ignore_hidden_elements = false
12
+ end
13
+
14
+ # try to load capybara-related rspec library
15
+ begin
16
+ require 'capybara/rspec'
17
+
18
+ RSpec.configure do |conf|
19
+ conf.filter_run_excluding :exclude => true
20
+ end
21
+
22
+ RSpec.configure do |conf|
23
+ conf.include Capybara::DSL
24
+ end
25
+
26
+ RSpec::Core::ExampleGroup.send :include, Capybara::DSL
27
+ rescue
28
+ ;
29
+ end
30
+ end
31
+
32
+ def supported_drivers
33
+ [:selenium, :selenium_remote, :webkit, :poltergeist]
34
+ end
35
+
36
+ def register_driver tag, browser, selenium_url
37
+ driver_name, properties = *recognize_driver(tag, browser)
38
+
39
+ if driver_name
40
+ unless Capybara.drivers[driver_name]
41
+ if driver_name == :poltergeist
42
+ Capybara.register_driver :poltergeist do |app|
43
+ Capybara::Poltergeist::Driver.new(app, { debug: false })
44
+ end
45
+ else
46
+ if driver_name =~ /remote/
47
+ properties[:browser] = :remote
48
+ properties[:url] = selenium_url
49
+ properties[:desired_capabilities] = capabilities if capabilities
50
+
51
+ Capybara.register_driver driver_name do |app|
52
+ Capybara::Selenium::Driver.new(app, properties)
53
+ end
54
+ else
55
+ properties[:browser] = browser
56
+
57
+ Capybara.register_driver driver_name do |app|
58
+ Capybara::Selenium::Driver.new(app, properties)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ driver_name
66
+ end
67
+
68
+ private
69
+
70
+ def recognize_driver tag, browser
71
+ properties = {}
72
+
73
+ driver_name =
74
+ case tag
75
+ when :webkit
76
+ require "capybara-webkit"
77
+
78
+ :webkit
79
+
80
+ when :selenium
81
+
82
+ case browser
83
+ when :firefox
84
+ :selenium_firefox
85
+
86
+ when :firefox_with_firebug
87
+ require 'capybara/firebug'
88
+
89
+ :selenium_firefox_with_firebug
90
+
91
+ when :chrome
92
+ :selenium_chrome
93
+
94
+ when :safari
95
+ :selenium_safari
96
+
97
+ when :ie, :internet_explorer
98
+ :selenium_ie
99
+
100
+ else
101
+ :unsupported
102
+ end
103
+
104
+ when :poltergeist
105
+ require 'capybara/poltergeist'
106
+
107
+ :poltergeist
108
+
109
+ when :selenium_remote
110
+ case browser
111
+ when :firefox
112
+ :selenium_remote_firefox
113
+
114
+ when :firefox_with_firebug
115
+ require 'capybara/firebug'
116
+
117
+ profile = Selenium::WebDriver::Firefox::Profile.new
118
+ profile.enable_firebug
119
+
120
+ properties[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_profile => profile)
121
+
122
+ :selenium_remote_firefox_with_firebug
123
+
124
+ when :ie
125
+ properties[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.internet_explorer
126
+
127
+ :selenium_remote_ie
128
+ else
129
+ :unsupported
130
+ end
131
+ else
132
+ :unsupported
133
+ end
134
+
135
+ [driver_name, properties]
136
+ end
137
+
138
+ end