effective_test_bot 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -1
- data/lib/effective_test_bot.rb +11 -0
- data/lib/effective_test_bot/version.rb +1 -1
- data/lib/generators/templates/effective_test_bot.rb +3 -0
- data/lib/generators/templates/test_helper.rb +5 -15
- data/test/concerns/test_botable/crud_dsl.rb +1 -1
- data/test/concerns/test_botable/devise_dsl.rb +1 -1
- data/test/concerns/test_botable/member_dsl.rb +1 -1
- data/test/concerns/test_botable/page_dsl.rb +1 -1
- data/test/concerns/test_botable/redirect_dsl.rb +1 -1
- data/test/concerns/test_botable/wizard_dsl.rb +1 -1
- data/test/fixtures/documents._test +0 -0
- data/test/fixtures/logo.png +0 -0
- data/test/support/effective_test_bot_assertions.rb +9 -4
- data/test/support/effective_test_bot_form_filler.rb +50 -26
- data/test/support/effective_test_bot_form_helper.rb +2 -2
- data/test/support/effective_test_bot_screenshots_helper.rb +0 -1
- data/test/support/effective_test_bot_test_helper.rb +17 -0
- data/test/test_botable/base_test.rb +14 -7
- data/test/test_botable/crud_test.rb +4 -8
- metadata +18 -3
- data/test/support/important_documents._test +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8411cc5cae54d4456303dea648f1030f427c134f
|
4
|
+
data.tar.gz: 971478e8e7a6b523ca81e40152dc6f018023e7a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41f82b5ef61e3addd71989a4171772ac0acc98869108eb9c5daf2cbf887271bd00fa69d2d5cbd43c91fffe2e4e9cf4215dd964269e66ed46274e70bb3c86dae3
|
7
|
+
data.tar.gz: 5c341d462afb03a6b2ecc4e839f0f690217b5160c56eb1bc2c35e09b766254ddb36645c0802d3af348234678ac092fb26e30e6cbf021e28c05ae63caf687ef8f
|
data/README.md
CHANGED
@@ -79,7 +79,11 @@ rake test:load_fixture_seeds
|
|
79
79
|
|
80
80
|
Your initial user may be created by any of the above 3 tasks.
|
81
81
|
|
82
|
-
Finally, to test that your testing environment is set up correctly run
|
82
|
+
Finally, to test that your testing environment is set up correctly run and work through any issues with:
|
83
|
+
|
84
|
+
```
|
85
|
+
rake test:bot:environment
|
86
|
+
```
|
83
87
|
|
84
88
|
You now have effective_test_bot configured and you're ready to go.
|
85
89
|
|
@@ -570,6 +574,18 @@ rake test:tour
|
|
570
574
|
rake test:tourv
|
571
575
|
```
|
572
576
|
|
577
|
+
### Fail Fast
|
578
|
+
|
579
|
+
Set `config.fail_fast = true` to exit immediately if there is a test failure.
|
580
|
+
|
581
|
+
Or, override the config setting by running the following:
|
582
|
+
|
583
|
+
```
|
584
|
+
rake test:bot FAILFAST=true
|
585
|
+
```
|
586
|
+
|
587
|
+
This functionality is provided thanks to [minitest-fail-fast](https://github.com/teoljungberg/minitest-fail-fast/)
|
588
|
+
|
573
589
|
## License
|
574
590
|
|
575
591
|
MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
data/lib/effective_test_bot.rb
CHANGED
@@ -5,6 +5,7 @@ require "effective_test_bot/version"
|
|
5
5
|
module EffectiveTestBot
|
6
6
|
mattr_accessor :except
|
7
7
|
mattr_accessor :only
|
8
|
+
mattr_accessor :fail_fast
|
8
9
|
mattr_accessor :screenshots
|
9
10
|
mattr_accessor :autosave_animated_gif_on_failure
|
10
11
|
mattr_accessor :tour_mode
|
@@ -55,6 +56,16 @@ module EffectiveTestBot
|
|
55
56
|
screenshots && autosave_animated_gif_on_failure
|
56
57
|
end
|
57
58
|
|
59
|
+
def self.fail_fast?
|
60
|
+
fails = ENV['FAIL_FAST'] || ENV['FAILFAST'] || ENV['FAIL']
|
61
|
+
|
62
|
+
if fails.present?
|
63
|
+
['true', '1'].include?(fails).to_s.downcase)
|
64
|
+
else
|
65
|
+
fail_fast
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
58
69
|
def self.tour_mode?
|
59
70
|
if ENV['TOUR'].present?
|
60
71
|
['true', 'verbose', 'debug'].include?(ENV['TOUR'].to_s.downcase)
|
@@ -17,6 +17,9 @@ if Rails.env.test?
|
|
17
17
|
# 'posts', 'events#index'
|
18
18
|
# ]
|
19
19
|
|
20
|
+
# Exits immediately if there is a test failure
|
21
|
+
config.fail_fast = true
|
22
|
+
|
20
23
|
# Should capybara generate a series of *.png screenshots as it goes through the test?
|
21
24
|
# Disabling screenshots will also disable animated_gifs and touring
|
22
25
|
config.screenshots = true
|
@@ -16,7 +16,6 @@ require 'capybara/slow_finder_errors'
|
|
16
16
|
class ActiveSupport::TestCase
|
17
17
|
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
18
18
|
fixtures :all
|
19
|
-
# Add more helper methods to be used by all tests here...
|
20
19
|
use_transactional_fixtures = true
|
21
20
|
end
|
22
21
|
|
@@ -26,19 +25,8 @@ class ActionDispatch::IntegrationTest
|
|
26
25
|
include Capybara::Assertions
|
27
26
|
include Capybara::Screenshot::MiniTestPlugin
|
28
27
|
include Warden::Test::Helpers if defined?(Devise)
|
29
|
-
|
30
|
-
# def setup # Called before every test
|
31
|
-
# end
|
32
|
-
|
33
|
-
# def teardown # Called after every test
|
34
|
-
# end
|
35
|
-
|
36
|
-
def after_teardown # I reset sessions here so capybara-screenshot can still make screenshots when tests fail
|
37
|
-
super(); Capybara.reset_sessions!
|
38
|
-
end
|
39
28
|
end
|
40
29
|
|
41
|
-
|
42
30
|
Capybara.default_driver = :webkit
|
43
31
|
Capybara.javascript_driver = :webkit
|
44
32
|
Capybara::Screenshot.autosave_on_failure = true
|
@@ -52,9 +40,7 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
|
52
40
|
Rails.backtrace_cleaner.remove_silencers!
|
53
41
|
Rails.backtrace_cleaner.add_silencer { |line| line =~ /minitest/ }
|
54
42
|
|
55
|
-
|
56
|
-
### So this is EffectiveTestBot 'code' here
|
57
|
-
### That gets run just once before the whole test suite loads
|
43
|
+
### Effective Test Bot specific stuff below ###
|
58
44
|
|
59
45
|
# So the very first thing I do is set up a consistent database
|
60
46
|
silence_stream(STDOUT) do
|
@@ -75,6 +61,10 @@ Rake::Task['db:fixtures:load'].invoke # There's just no way to get the seeds fir
|
|
75
61
|
Rake::Task['db:seed'].invoke
|
76
62
|
Rake::Task['test:load_fixture_seeds'].invoke # This is included by effective_test_bot. It just runs the app's test/fixtures/seeds.rb if it exists
|
77
63
|
|
64
|
+
if EffectiveTestBot.fail_fast?
|
65
|
+
require 'minitest/fail_fast'
|
66
|
+
end
|
67
|
+
|
78
68
|
# Make all database transactions use the same thread, otherwise signing up in capybara won't get rolled back
|
79
69
|
# This must be run after the Rake::Tasks above
|
80
70
|
class ActiveRecord::Base
|
@@ -46,7 +46,7 @@ module TestBotable
|
|
46
46
|
|
47
47
|
method_name = test_bot_method_name('crud_test', label || options_for_method[:current_test])
|
48
48
|
|
49
|
-
define_method(method_name) { crud_action_test(test: test, resource: resource, user: user,
|
49
|
+
define_method(method_name) { crud_action_test(test: test, resource: resource, user: user, **options_for_method) }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -23,7 +23,7 @@ module TestBotable
|
|
23
23
|
|
24
24
|
method_name = test_bot_method_name('devise_test', options[:current_test])
|
25
25
|
|
26
|
-
define_method(method_name) { devise_action_test(test: test, options
|
26
|
+
define_method(method_name) { devise_action_test(test: test, **options) }
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -22,7 +22,7 @@ module TestBotable
|
|
22
22
|
|
23
23
|
method_name = test_bot_method_name('member_test', options[:current_test])
|
24
24
|
|
25
|
-
define_method(method_name) { member_action_test(controller: controller, action: action, user: user, member: member, options
|
25
|
+
define_method(method_name) { member_action_test(controller: controller, action: action, user: user, member: member, **options) }
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
@@ -21,7 +21,7 @@ module TestBotable
|
|
21
21
|
|
22
22
|
method_name = test_bot_method_name('page_test', options[:current_test])
|
23
23
|
|
24
|
-
define_method(method_name) { page_action_test(path: path, user: user, options
|
24
|
+
define_method(method_name) { page_action_test(path: path, user: user, **options) }
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
@@ -20,7 +20,7 @@ module TestBotable
|
|
20
20
|
|
21
21
|
method_name = test_bot_method_name('redirect_test', options[:current_test])
|
22
22
|
|
23
|
-
define_method(method_name) { redirect_action_test(from: from, to: to, user: user, options
|
23
|
+
define_method(method_name) { redirect_action_test(from: from, to: to, user: user, **options) }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -31,7 +31,7 @@ module TestBotable
|
|
31
31
|
|
32
32
|
method_name = test_bot_method_name('wizard_test', options[:current_test])
|
33
33
|
|
34
|
-
define_method(method_name) { wizard_action_test(from: from, to: to, user: user, options
|
34
|
+
define_method(method_name) { wizard_action_test(from: from, to: to, user: user, **options) }
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
Binary file
|
Binary file
|
@@ -30,11 +30,11 @@ module EffectiveTestBotAssertions
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def assert_jquery_present(message = "Expected jquery ($.fn.jquery) to be present")
|
33
|
-
assert((page.evaluate_script('$.fn.jquery') rescue
|
33
|
+
assert((page.evaluate_script('$.fn.jquery') rescue nil).to_s.length > 0, message)
|
34
34
|
end
|
35
35
|
|
36
36
|
def assert_jquery_ujs_present(message = "Expected rails' jquery_ujs ($.rails) to be present")
|
37
|
-
assert((page.evaluate_script('$.rails') rescue
|
37
|
+
assert((page.evaluate_script('$.rails') rescue nil).to_s.length > 0, message)
|
38
38
|
end
|
39
39
|
|
40
40
|
def assert_page_title(title = :any, message = '(page_title) Expected page title to be present')
|
@@ -50,8 +50,8 @@ module EffectiveTestBotAssertions
|
|
50
50
|
assert all(selector).present?, message.sub(':selector:', selector)
|
51
51
|
end
|
52
52
|
|
53
|
-
def assert_submit_input(message = "(submit_input) Expected one or more visible input[type='submit'] to be present")
|
54
|
-
assert all(
|
53
|
+
def assert_submit_input(message = "(submit_input) Expected one or more visible input[type='submit'] or button[type='submit'] to be present")
|
54
|
+
assert all("input[type='submit'],button[type='submit']").present?, message
|
55
55
|
end
|
56
56
|
|
57
57
|
def assert_page_status(status = 200, message = '(page_status) Expected :status: HTTP status code')
|
@@ -73,6 +73,11 @@ module EffectiveTestBotAssertions
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
def assert_no_ajax_requests(message = "(no_ajax_requests) :count: Unexpected AJAX requests present")
|
77
|
+
active = page.evaluate_script('jQuery.active')
|
78
|
+
assert (active.blank? || active.zero?), message.sub(':count:', active.to_s)
|
79
|
+
end
|
80
|
+
|
76
81
|
def assert_no_js_errors(message = nil)
|
77
82
|
errors = page.driver.error_messages
|
78
83
|
assert errors.blank?, message || "(no_js_errors) Unexpected javascript error:\n#{errors.first.to_s}"
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'timeout'
|
2
|
+
require 'faker'
|
2
3
|
|
3
4
|
module EffectiveTestBotFormFiller
|
4
5
|
DIGITS = ('1'..'9').to_a
|
@@ -53,7 +54,7 @@ module EffectiveTestBotFormFiller
|
|
53
54
|
save_test_bot_screenshot
|
54
55
|
|
55
56
|
# Support for the cocoon gem
|
56
|
-
all('a.add_fields[data-association-insertion-template]').each do |field|
|
57
|
+
all('a.add_fields[data-association-insertion-template],a.has_many_add').each do |field|
|
57
58
|
next if skip_form_field?(field)
|
58
59
|
|
59
60
|
if EffectiveTestBot.tour_mode_extreme?
|
@@ -69,11 +70,11 @@ module EffectiveTestBotFormFiller
|
|
69
70
|
skip_field_screenshot = false
|
70
71
|
|
71
72
|
case [field.tag_name, field['type']].compact.join('_')
|
72
|
-
when 'input_text', 'input_email', 'input_password', 'input_tel', 'input_number', 'input_checkbox', 'input_radio'
|
73
|
+
when 'input_text', 'input_email', 'input_password', 'input_tel', 'input_number', 'input_checkbox', 'input_radio', 'input_url'
|
73
74
|
field.set(value_for_field(field, fills))
|
74
75
|
when 'textarea'
|
75
76
|
value = value_for_field(field, fills)
|
76
|
-
|
77
|
+
ckeditor_text_area?(field) ? fill_ckeditor_text_area(field, value) : field.set(value)
|
77
78
|
when 'select'
|
78
79
|
if EffectiveTestBot.tour_mode_extreme? && field['class'].to_s.include?('select2') # select2
|
79
80
|
page.execute_script("try { $('select##{field['id']}').select2('open'); } catch(e) {};")
|
@@ -91,7 +92,7 @@ module EffectiveTestBotFormFiller
|
|
91
92
|
else
|
92
93
|
field.set(value_for_field(field, fills))
|
93
94
|
end
|
94
|
-
when 'input_submit', 'input_search'
|
95
|
+
when 'input_submit', 'input_search', 'input_button'
|
95
96
|
skip_field_screenshot = true
|
96
97
|
# Do nothing
|
97
98
|
else
|
@@ -107,6 +108,7 @@ module EffectiveTestBotFormFiller
|
|
107
108
|
@filled_numeric_fields = nil
|
108
109
|
@filled_password_fields = nil
|
109
110
|
@filled_radio_fields = nil
|
111
|
+
@filled_country_fields = nil
|
110
112
|
|
111
113
|
save_test_bot_screenshot
|
112
114
|
end
|
@@ -121,7 +123,7 @@ module EffectiveTestBotFormFiller
|
|
121
123
|
attributes = field['name'].to_s.gsub(']', '').split('[') # user[something_attributes][last_name] => ['user', 'something_attributes', 'last_name']
|
122
124
|
attribute = attributes.last.to_s
|
123
125
|
|
124
|
-
fill_value = fill_value_for_field(fills, attributes)
|
126
|
+
fill_value = fill_value_for_field(fills, attributes, field['value'])
|
125
127
|
|
126
128
|
# If there is a predefined fill value for this field return it now
|
127
129
|
# except for select, checkbox and radio fields which we want to match by value or label
|
@@ -136,12 +138,16 @@ module EffectiveTestBotFormFiller
|
|
136
138
|
if classes.include?('date') # Let's assume this is a date input.
|
137
139
|
if attribute.include?('end') # Make sure end dates are after start dates
|
138
140
|
Faker::Date.forward(365).strftime('%Y-%m-%d')
|
141
|
+
elsif attribute.include?('closing')
|
142
|
+
Faker::Date.forward(30).strftime('%Y-%m-%d')
|
139
143
|
else
|
140
144
|
Faker::Date.backward(365).strftime('%Y-%m-%d')
|
141
145
|
end
|
142
146
|
elsif classes.include?('datetime')
|
143
147
|
if attribute.include?('end')
|
144
148
|
Faker::Date.forward(365).strftime('%Y-%m-%d %H:%m')
|
149
|
+
elsif attribute.include?('closing')
|
150
|
+
Faker::Date.forward(30).strftime('%Y-%m-%d %H:%m')
|
145
151
|
else
|
146
152
|
Faker::Date.backward(365).strftime('%Y-%m-%d %H:%m')
|
147
153
|
end
|
@@ -170,6 +176,12 @@ module EffectiveTestBotFormFiller
|
|
170
176
|
Faker::Address.street_address
|
171
177
|
elsif attribute.include?('name')
|
172
178
|
Faker::Name.name
|
179
|
+
elsif attribute.include?('postal_code')
|
180
|
+
if @filled_country_fields == 'US'
|
181
|
+
DIGITS.sample + DIGITS.sample + DIGITS.sample + DIGITS.sample + DIGITS.sample
|
182
|
+
else
|
183
|
+
LETTERS.sample + DIGITS.sample + LETTERS.sample + ' ' + DIGITS.sample + LETTERS.sample + DIGITS.sample
|
184
|
+
end
|
173
185
|
elsif attribute.include?('postal') # Make a Canadian postal code
|
174
186
|
LETTERS.sample + DIGITS.sample + LETTERS.sample + ' ' + DIGITS.sample + LETTERS.sample + DIGITS.sample
|
175
187
|
elsif attribute.include?('zip') && attribute.include?('code') # Make a US zip code
|
@@ -187,8 +199,11 @@ module EffectiveTestBotFormFiller
|
|
187
199
|
Faker::Internet.email
|
188
200
|
|
189
201
|
when 'input_file'
|
190
|
-
|
191
|
-
|
202
|
+
if field['class'].to_s.include?('asset-box-uploader-fileinput')
|
203
|
+
"#{File.dirname(__FILE__)}/../fixtures/documents._test"
|
204
|
+
else
|
205
|
+
"#{File.dirname(__FILE__)}/../fixtures/logo.png"
|
206
|
+
end
|
192
207
|
when 'input_number'
|
193
208
|
value_for_input_numeric_field(field, "input[type='number'][name$='[#{attribute}]']")
|
194
209
|
|
@@ -202,16 +217,25 @@ module EffectiveTestBotFormFiller
|
|
202
217
|
when 'select'
|
203
218
|
if fill_value.present? # accept a value or text
|
204
219
|
field.all('option:enabled').each do |option|
|
205
|
-
|
220
|
+
if (option.text == fill_value || option.value.to_s == fill_value)
|
221
|
+
@filled_country_fields = option.value if attribute == 'country_code'
|
222
|
+
return option.text
|
223
|
+
end
|
206
224
|
end
|
207
225
|
end
|
208
226
|
|
209
|
-
field.all('option:enabled').select { |option| option.value.present? }.sample
|
227
|
+
option = field.all('option:enabled').select { |option| option.value.present? }.sample
|
210
228
|
|
229
|
+
@filled_country_fields = option.try(:value) if attribute == 'country_code' # So Postal Code can be set to a valid one
|
230
|
+
|
231
|
+
option.try(:text) || ''
|
211
232
|
when 'input_tel'
|
212
233
|
d = 10.times.map { DIGITS.sample }
|
213
234
|
d[0] + d[1] + d[2] + '-' + d[3] + d[4] + d[5] + '-' + d[6] + d[7] + d[8] + d[9]
|
214
235
|
|
236
|
+
when 'input_url'
|
237
|
+
Faker::Internet.url
|
238
|
+
|
215
239
|
when 'textarea'
|
216
240
|
Faker::Lorem.paragraph
|
217
241
|
|
@@ -221,24 +245,19 @@ module EffectiveTestBotFormFiller
|
|
221
245
|
end
|
222
246
|
|
223
247
|
def value_for_input_checkbox_field(field, fill_value)
|
224
|
-
if
|
248
|
+
if ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(fill_value)
|
249
|
+
true
|
250
|
+
elsif ::ActiveRecord::ConnectionAdapters::Column::FALSE_VALUES.include?(fill_value)
|
251
|
+
false
|
252
|
+
elsif fill_value.present?
|
225
253
|
fill_values = Array(fill_value) # Allow an array of fill values to be passed
|
226
|
-
|
227
|
-
if ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(fill_value)
|
228
|
-
fill_values = ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.to_a
|
229
|
-
end
|
230
|
-
|
231
|
-
if ::ActiveRecord::ConnectionAdapters::Column::FALSE_VALUES.include?(fill_value)
|
232
|
-
fill_values = ::ActiveRecord::ConnectionAdapters::Column::FALSE_VALUES.to_a
|
233
|
-
end
|
234
|
-
|
235
254
|
(fill_values.include?(field['value']) || fill_values.include?(field.find(:xpath, '..').text))
|
255
|
+
elsif field['required'].present?
|
256
|
+
true
|
236
257
|
elsif field['value'] == 'true'
|
237
258
|
true
|
238
259
|
elsif field['value'] == 'false'
|
239
260
|
false
|
240
|
-
elsif field['required'].present?
|
241
|
-
true
|
242
261
|
else
|
243
262
|
[true, false].sample
|
244
263
|
end
|
@@ -337,8 +356,8 @@ module EffectiveTestBotFormFiller
|
|
337
356
|
|
338
357
|
private
|
339
358
|
|
340
|
-
def fill_value_for_field(fills, attributes)
|
341
|
-
return if fills.blank? || attributes.blank?
|
359
|
+
def fill_value_for_field(fills, attributes, value)
|
360
|
+
return if fills.blank? || (attributes.blank? && value.blank?)
|
342
361
|
|
343
362
|
key = nil
|
344
363
|
attributes.reverse_each do |name| # match last_name, then something_attributes.last_name, then user.something_attributes.last_name
|
@@ -346,6 +365,8 @@ module EffectiveTestBotFormFiller
|
|
346
365
|
return fills[key].to_s if fills.key?(key)
|
347
366
|
end
|
348
367
|
|
368
|
+
return fills[value] if fills.key?(value)
|
369
|
+
|
349
370
|
nil
|
350
371
|
end
|
351
372
|
|
@@ -356,12 +377,15 @@ module EffectiveTestBotFormFiller
|
|
356
377
|
@test_bot_excluded_fields_xpath = nil
|
357
378
|
end
|
358
379
|
|
380
|
+
def ckeditor_text_area?(field)
|
381
|
+
return false unless field.tag_name == 'textarea'
|
382
|
+
(field['class'].to_s.include?('ckeditor') || all("span[id='cke_#{field['id']}']").present?)
|
383
|
+
end
|
384
|
+
|
359
385
|
def skip_form_field?(field)
|
360
386
|
field.reload # Handle a field changing visibility/disabled state from previous form field manipulations
|
361
387
|
|
362
|
-
|
363
|
-
|
364
|
-
(field.visible? == false && !ckeditor) ||
|
388
|
+
(field.visible? == false && !ckeditor_text_area?(field)) ||
|
365
389
|
field.disabled? ||
|
366
390
|
['true', true, 1].include?(field['data-test-bot-skip']) ||
|
367
391
|
(@test_bot_excluded_fields_xpath.present? && field.path.include?(@test_bot_excluded_fields_xpath))
|
@@ -68,8 +68,8 @@ module EffectiveTestBotFormHelper
|
|
68
68
|
submit = find(:link_or_button, label)
|
69
69
|
assert submit.present?, "TestBotError: Unable to find a visible submit link or button on #{page.current_path} with the label #{label}"
|
70
70
|
else
|
71
|
-
submit = first(:css, "input[type='submit']")
|
72
|
-
assert submit.present?, "TestBotError: Unable to find a visible input[type='submit'] on #{page.current_path}"
|
71
|
+
submit = first(:css, "input[type='submit'],button[type='submit']")
|
72
|
+
assert submit.present?, "TestBotError: Unable to find a visible input[type='submit'] or button[type='submit'] on #{page.current_path}"
|
73
73
|
end
|
74
74
|
|
75
75
|
if EffectiveTestBot.screenshots?
|
@@ -15,7 +15,6 @@ module EffectiveTestBotScreenshotsHelper
|
|
15
15
|
|
16
16
|
# This gets called after every test. Minitest hook for plugin developers
|
17
17
|
def after_teardown
|
18
|
-
super
|
19
18
|
return unless EffectiveTestBot.screenshots? && (@test_bot_screenshot_id || 0) > 0
|
20
19
|
|
21
20
|
if !passed? && EffectiveTestBot.autosave_animated_gif_on_failure?
|
@@ -2,6 +2,23 @@ module EffectiveTestBotTestHelper
|
|
2
2
|
# This makes sure capybara is done, and breaks out of any 'within' blocks
|
3
3
|
def synchronize!
|
4
4
|
page.document.find('html')
|
5
|
+
wait_for_ajax
|
6
|
+
end
|
7
|
+
|
8
|
+
# https://gist.github.com/josevalim/470808#gistcomment-1268491
|
9
|
+
def wait_for_ajax
|
10
|
+
begin
|
11
|
+
Timeout.timeout(Capybara.default_max_wait_time) do
|
12
|
+
loop until finished_all_ajax_requests?
|
13
|
+
end
|
14
|
+
rescue => e
|
15
|
+
assert_no_ajax_requests
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def finished_all_ajax_requests?
|
20
|
+
ajax_request_count = page.evaluate_script('jQuery.active')
|
21
|
+
ajax_request_count.blank? || ajax_request_count.zero?
|
5
22
|
end
|
6
23
|
|
7
24
|
# Because capybara-webkit can't make delete requests, we need to use rack_test
|
@@ -36,13 +36,20 @@ module BaseTest
|
|
36
36
|
obj = resource_class.last
|
37
37
|
return obj if obj.present? && !obj.kind_of?(User)
|
38
38
|
|
39
|
-
hint = "Unable to find_or_create_resource!\nEither fixture/seed an instance of #{resource_class} or ensure that submitting form#new_#{resource_name} on #{(new_resource_path rescue nil) || 'the resource new page'} creates a new #{resource_name}"
|
40
|
-
|
41
39
|
# It doesn't exist, so lets go to the new page and submit a form to build one
|
42
40
|
without_screenshots do
|
43
|
-
|
41
|
+
new_resource_paths = [ # TODO: enumerate all controller namespaces instead of just admin
|
42
|
+
(new_resource_path rescue nil),
|
43
|
+
(new_polymorphic_path(resource) rescue nil),
|
44
|
+
(new_polymorphic_path([:admin, resource]) rescue nil),
|
45
|
+
(new_polymorphic_path([:members, resource]) rescue nil)
|
46
|
+
].compact
|
47
|
+
|
48
|
+
hint = "Unable to find_or_create_resource!\nEither fixture/seed an instance of #{resource_class} or ensure that submitting form#new_#{resource_name} on #{(new_resource_paths.first rescue nil) || 'the resource new page'} creates a new #{resource_name}"
|
49
|
+
|
50
|
+
assert(new_resource_paths.present?, "TestBotError: Generated polymorphic route new_#{[*controller_namespace, resource_name].compact.join('_')}_path is undefined. #{hint}")
|
44
51
|
|
45
|
-
visit(
|
52
|
+
visit(new_resource_paths.first)
|
46
53
|
|
47
54
|
assert_form("form#new_#{resource_name}", "TestBotError: Failed to find form#new_#{resource_name}. #{hint}") unless test_bot_skip?(:form)
|
48
55
|
|
@@ -52,10 +59,10 @@ module BaseTest
|
|
52
59
|
assert_submit_input "TestBotError: Failed to find a visible input[type='submit'] on #{page.current_path}. #{hint}"
|
53
60
|
submit_novalidate_form
|
54
61
|
end
|
55
|
-
end
|
56
62
|
|
57
|
-
|
58
|
-
|
63
|
+
obj = resource_class.last
|
64
|
+
assert obj.present?, "TestBotError: Failed to create a resource after submitting form. Errors: #{(assigns[resource_name] || {})['errors']}\n#{hint}."
|
65
|
+
end
|
59
66
|
|
60
67
|
obj
|
61
68
|
end
|
@@ -118,9 +118,9 @@ module CrudTest
|
|
118
118
|
|
119
119
|
assert_page_normal
|
120
120
|
assert_assigns(resource_name) # unskippable
|
121
|
-
assert_form("form
|
121
|
+
assert_form("form[id^='edit_#{resource_name}']") unless test_bot_skip?(:form)
|
122
122
|
|
123
|
-
within_if("form
|
123
|
+
within_if("form[id^='edit_#{resource_name}']", !test_bot_skip?(:form)) do
|
124
124
|
assert_submit_input unless test_bot_skip?(:submit_input)
|
125
125
|
assert_jquery_ujs_disable_with unless test_bot_skip?(:jquery_ujs_disable_with)
|
126
126
|
end
|
@@ -134,9 +134,7 @@ module CrudTest
|
|
134
134
|
|
135
135
|
before = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
within_if("form#edit_#{resource_name}_#{resource.id}", !test_bot_skip?(:form)) do
|
137
|
+
within_if("form[id^='edit_#{resource_name}']", !test_bot_skip?(:form)) do
|
140
138
|
clear_form
|
141
139
|
submit_novalidate_form
|
142
140
|
end
|
@@ -169,9 +167,7 @@ module CrudTest
|
|
169
167
|
|
170
168
|
before = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
|
171
169
|
|
172
|
-
|
173
|
-
|
174
|
-
within_if("form#edit_#{resource_name}_#{resource.id}", !test_bot_skip?(:form)) do
|
170
|
+
within_if("form[id^='edit_#{resource_name}']", !test_bot_skip?(:form)) do
|
175
171
|
fill_form(resource_attributes)
|
176
172
|
submit_form
|
177
173
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_test_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-fail-fast
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: minitest-rails-capybara
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -233,13 +247,14 @@ files:
|
|
233
247
|
- test/concerns/test_botable/page_dsl.rb
|
234
248
|
- test/concerns/test_botable/redirect_dsl.rb
|
235
249
|
- test/concerns/test_botable/wizard_dsl.rb
|
250
|
+
- test/fixtures/documents._test
|
251
|
+
- test/fixtures/logo.png
|
236
252
|
- test/support/effective_test_bot_assertions.rb
|
237
253
|
- test/support/effective_test_bot_form_filler.rb
|
238
254
|
- test/support/effective_test_bot_form_helper.rb
|
239
255
|
- test/support/effective_test_bot_login_helper.rb
|
240
256
|
- test/support/effective_test_bot_screenshots_helper.rb
|
241
257
|
- test/support/effective_test_bot_test_helper.rb
|
242
|
-
- test/support/important_documents._test
|
243
258
|
- test/test_bot/integration/application_test.rb
|
244
259
|
- test/test_bot/integration/environment_test.rb
|
245
260
|
- test/test_botable/base_test.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
This is a file that the EffectiveAssets file uploader will accept regardless of any :file_types passed
|