effective_test_bot 1.7.0 → 1.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b4f8b032c99230c6fcee477b0b80ace59c6d2bfae02936c1e4b0e3c6b366233
4
- data.tar.gz: 2826d465044bdd27544a4d8dc4be38f2ce78109fafabc953d9c6541b6e6f5e07
3
+ metadata.gz: 914a9df1a597575ab9150aeed63569eb8d76066822f8cdb746a7204f1235d5fe
4
+ data.tar.gz: 240e22997753bf272671a9ceb8709b863052d3039f55b84fe673cdc7b029f2dc
5
5
  SHA512:
6
- metadata.gz: 16cea9eb462395b662a10005cd577a305c67b2f405801cd5ed48d0e6478d4a5a30f72cb662ab7f9d9e71e22df614a971cdf4e5cc5e0f62519f501ba4316355b7
7
- data.tar.gz: 8fdac06110cdde7a0e7ef41eb24e4f67156c1afad7c82856e1c15b0c36c2eaf2d9abba2df7a49a189c0d9f3a4ab8bbeac16f4486a4083eb46179701b5dd62d3e
6
+ metadata.gz: 62624653851827706582229b697e9cfeb7644e3a11372c832432c96acccd1de929ef6dd676b023c540c004d376b4cceb08d936f2bfcd2631a4e0fac5a04e3cdf
7
+ data.tar.gz: 5054abd3cfe3d42acca6b467349365d41221afe0381112939839e6847725d27ad905b1a44b1ef9c312d86acffe427521ad0c827a003ac943476bdbd2847b6a0e
@@ -1,3 +1,3 @@
1
1
  module EffectiveTestBot
2
- VERSION = '1.7.0'.freeze
2
+ VERSION = '1.7.1'.freeze
3
3
  end
@@ -19,17 +19,24 @@ module EffectiveTestBotFormHelper
19
19
  true
20
20
  end
21
21
 
22
- def submit_page(label = nil, last: false, assert_path_changed: true, debug: false)
23
- submit_form(label, last: last, assert_path_changed: assert_path_changed, debug: debug)
22
+ def submit_page(label = nil, last: false, assert_path_changed: true, wait: true, debug: false)
23
+ submit_form(label, last: last, assert_path_changed: assert_path_changed, wait: wait, debug: debug)
24
+ end
25
+
26
+ def submit_ajax_form(label = nil, last: false, assert_path_changed: false, wait: false, debug: false)
27
+ submit_form(label, last: last, assert_path_changed: assert_path_changed, wait: wait, debug: debug)
24
28
  end
25
29
 
26
30
  # This submits the form, while checking for html5 form validation errors and unpermitted params
27
- def submit_form(label = nil, last: false, assert_path_changed: false, debug: false)
31
+ def submit_form(label = nil, last: false, assert_path_changed: false, wait: true, debug: false)
28
32
  assert_no_html5_form_validation_errors unless test_bot_skip?(:no_html5_form_validation_errors)
29
33
  assert_jquery_ujs_disable_with(label) unless test_bot_skip?(:jquery_ujs_disable_with)
30
34
 
31
- # Add a unique class to the body before submission
32
- page.execute_script("document.body.classList.add('effective-test-bot-submitting-form');")
35
+ # Add a div to track form submission
36
+ if wait
37
+ page.execute_script("$('body').prepend($('<div id=\"effective-test-bot-submitting-form\"></div>'));")
38
+ page.assert_selector(:xpath, '//div[@id="effective-test-bot-submitting-form"]')
39
+ end
33
40
 
34
41
  before_path = page.current_path
35
42
  before_path = 'ignore' unless assert_path_changed
@@ -42,10 +49,23 @@ module EffectiveTestBotFormHelper
42
49
 
43
50
  assert_no_assigns_errors unless test_bot_skip?(:no_assigns_errors)
44
51
 
45
- # Make sure the page has fully loaded afer submission
46
- assert_no_selector('body.effective-test-bot-submitting-form', wait: Capybara.default_max_wait_time * 10)
47
52
  assert_no_current_path(before_path.to_s, wait: Capybara.default_max_wait_time * 10)
48
53
 
54
+ # Wait for form-submitting div to disappear via JS (not Capybara element)
55
+ if wait
56
+ begin
57
+ Timeout.timeout(Capybara.default_max_wait_time * 10) do
58
+ loop do
59
+ gone = page.evaluate_script("document.querySelector('#effective-test-bot-submitting-form') === null")
60
+ break if gone
61
+ sleep 0.1
62
+ end
63
+ end
64
+ rescue Timeout::Error
65
+ raise Timeout::Error, "Form submission did not disappear after #{Capybara.default_max_wait_time * 10} seconds. The form submission may have stalled or failed."
66
+ end
67
+ end
68
+
49
69
  assert_no_exceptions unless test_bot_skip?(:exceptions)
50
70
  assert_authorization unless test_bot_skip?(:authorization)
51
71
  assert_page_status unless test_bot_skip?(:page_status)
@@ -193,11 +213,14 @@ module EffectiveTestBotFormHelper
193
213
  elsif submit['data-confirm']
194
214
  page.accept_confirm { submit.click }
195
215
  else
196
- submit.click
216
+ begin
217
+ submit.click
218
+ rescue => e
219
+ submit.click
220
+ end
197
221
  end
198
222
 
199
- synchronize ? synchronize! : sleep(2)
200
-
223
+ synchronize! if synchronize
201
224
  save_test_bot_screenshot if EffectiveTestBot.screenshots?
202
225
 
203
226
  true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_test_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect