effective_test_bot 1.0.2 → 1.0.3
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 +4 -4
- data/README.md +1 -1
- data/config/application_system_test_case.rb +12 -1
- data/lib/effective_test_bot/dsl.rb +5 -0
- data/lib/effective_test_bot/version.rb +1 -1
- data/test/support/effective_test_bot_form_filler.rb +6 -2
- data/test/support/effective_test_bot_form_helper.rb +4 -4
- data/test/test_botable/base_test.rb +8 -11
- data/test/test_botable/crud_test.rb +9 -5
- data/test/test_botable/devise_test.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 974ef4a9d6b759cc434619a082215a74c9823904
|
4
|
+
data.tar.gz: 224d534f49202c588dc33d98284358dcdc249c99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fbbc8bee9fcfc819818edafe8dd8e6c1fc9aa33242e3e5137dcbd6e9f06d657fbfb9ee200fc102f1594882c714fb66a537c6b2b650b009fbee273611b170ee1
|
7
|
+
data.tar.gz: e186e7db807007b73033ad7b254b9961617f450aea119f754d77f505bc772425b75ff3d460722ed758dfc34262e3045aa2c5b92b57d63ef5c06b3c97970421ea
|
data/README.md
CHANGED
@@ -114,7 +114,7 @@ The following assertions are added for use in any integration test:
|
|
114
114
|
|
115
115
|
- `assert_assigns` asserts a given rails view_assigns object is present.
|
116
116
|
- `assert_assigns_errors` use after an intentionally invalid form submit to make sure your assigned rails object has errors, or a specific error.
|
117
|
-
- `assert_authorization` checks for a 403 Access Denied error. For this to work, please add `assign_test_bot_access_denied_exception(exception) if defined?(EffectiveTestBot)` to your ApplicationController's `rescue_from` block to generate more information.
|
117
|
+
- `assert_authorization` checks for a 403 Access Denied error. For this to work, please add `assign_test_bot_access_denied_exception(exception) if defined?(EffectiveTestBot)` to the bottom of your ApplicationController's `rescue_from` block, after the respond_to, to generate more information.
|
118
118
|
- `assert_no_assigns_errors` should be used after any form submit to make sure your assigned rails object has no errors. Prints out any errors if they exist.
|
119
119
|
- `assert_current_path(path)` asserts the current page path.
|
120
120
|
- `assert_email(action)` asserts an email with the given action name was sent. Also supports `assert_email(to: email)` type syntax with to, from, subject, body.
|
@@ -1,7 +1,18 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
+
require 'capybara'
|
4
|
+
require 'selenium-webdriver'
|
5
|
+
|
6
|
+
Capybara.register_driver :effective_headless do |app|
|
7
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
8
|
+
|
9
|
+
['headless', 'disable-gpu', 'window-size=1366x1366'].each { |arg| options.add_argument(arg) }
|
10
|
+
|
11
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
12
|
+
end
|
13
|
+
|
3
14
|
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
4
|
-
driven_by :
|
15
|
+
driven_by :effective_headless
|
5
16
|
|
6
17
|
include Warden::Test::Helpers if defined?(Devise)
|
7
18
|
include EffectiveTestBot::DSL
|
@@ -208,9 +208,9 @@ module EffectiveTestBotFormFiller
|
|
208
208
|
|
209
209
|
when 'input_file'
|
210
210
|
if field['class'].to_s.include?('asset-box-uploader-fileinput')
|
211
|
-
"#{File.dirname(__FILE__)}
|
211
|
+
"#{File.dirname(__FILE__).sub('test/support', 'test/fixtures')}/documents._test"
|
212
212
|
else
|
213
|
-
"#{File.dirname(__FILE__)}
|
213
|
+
"#{File.dirname(__FILE__).sub('test/support', 'test/fixtures')}/logo.png"
|
214
214
|
end
|
215
215
|
|
216
216
|
when 'input_number'
|
@@ -392,6 +392,10 @@ module EffectiveTestBotFormFiller
|
|
392
392
|
end
|
393
393
|
end
|
394
394
|
|
395
|
+
def clear_effective_select(field)
|
396
|
+
page.execute_script("try { $('select##{field['id']}').val('').trigger('change.select2'); } catch(e) {};")
|
397
|
+
end
|
398
|
+
|
395
399
|
def close_effective_date_time_picker(field)
|
396
400
|
page.execute_script("try { $('input##{field['id']}').data('DateTimePicker').hide(); } catch(e) {};")
|
397
401
|
end
|
@@ -46,11 +46,11 @@ module EffectiveTestBotFormHelper
|
|
46
46
|
def clear_form
|
47
47
|
all('input,select,textarea').each do |field|
|
48
48
|
if field.tag_name == 'select' && field['class'].to_s.include?('select2') # effective_select
|
49
|
-
|
49
|
+
clear_effective_select(field)
|
50
50
|
end
|
51
51
|
|
52
52
|
begin
|
53
|
-
field.set('')
|
53
|
+
field.set('')
|
54
54
|
close_effective_date_time_picker(field) if field['class'].to_s.include?('effective_date')
|
55
55
|
save_test_bot_screenshot if EffectiveTestBot.tour_mode_extreme?
|
56
56
|
rescue => e; end
|
@@ -63,7 +63,7 @@ module EffectiveTestBotFormHelper
|
|
63
63
|
# This kind of sucks, as we want to simulate mouse movements with the tour
|
64
64
|
# Instead we manually trigger submit buttons and use the data-disable-with to
|
65
65
|
# make the 'submit form' step look nice
|
66
|
-
def click_submit(label, last: false, debug: false)
|
66
|
+
def click_submit(label = nil, last: false, debug: false)
|
67
67
|
submit = find_submit(label, last: last)
|
68
68
|
|
69
69
|
if EffectiveTestBot.screenshots?
|
@@ -85,7 +85,7 @@ module EffectiveTestBotFormHelper
|
|
85
85
|
end
|
86
86
|
|
87
87
|
# Keys are :value, should be one of :count, :minimum, :maximum, :between, :text, :id, :class, :visible, :exact, :exact_text, :match, :wait, :filter_se
|
88
|
-
def find_submit(label, last: false)
|
88
|
+
def find_submit(label = nil, last: false)
|
89
89
|
submit = nil
|
90
90
|
|
91
91
|
if label.present?
|
@@ -80,18 +80,10 @@ module BaseTest
|
|
80
80
|
# Try to find a link_to_delete already on this page
|
81
81
|
# Otherwise create one
|
82
82
|
# Returns the link element
|
83
|
-
def
|
84
|
-
selector = "a[href='#{
|
85
|
-
link_to_delete = page.document.all(selector, visible: false).first # could be nil, but this is a non-blocking selector
|
86
|
-
|
87
|
-
if link_to_delete.present? # Take excessive efforts to ensure it's visible and clickable
|
88
|
-
page.execute_script("$('body').prepend($(\"#{selector}\").first().clone().show().removeProp('disabled').html('Delete'));")
|
89
|
-
else # Create our own link
|
90
|
-
page.execute_script("$('body').prepend($('<a>').attr({href: '#{resource_path(resource)}', 'data-method': 'delete', 'data-confirm': 'Are you sure?'}).html('Delete'));")
|
91
|
-
end
|
83
|
+
def create_rails_ujs_link_to_delete(resource)
|
84
|
+
selector = "a[href='#{destroy_resource_path(resource)}'][data-method='delete']"
|
92
85
|
|
93
|
-
#
|
94
|
-
# Otherwise we'd want to take a screenshot of it
|
86
|
+
page.execute_script("$('body').prepend($('<a>').attr({href: '#{destroy_resource_path(resource)}', 'data-method': 'delete'}).html('Delete'));")
|
95
87
|
|
96
88
|
(page.document.first(:css, selector) rescue nil)
|
97
89
|
end
|
@@ -115,4 +107,9 @@ module BaseTest
|
|
115
107
|
def edit_resource_path(resource) # edit
|
116
108
|
effective_resource.action_path(:edit, resource)
|
117
109
|
end
|
110
|
+
|
111
|
+
def destroy_resource_path(resource)
|
112
|
+
effective_resource.action_path(:destroy, resource)
|
113
|
+
end
|
114
|
+
|
118
115
|
end
|
@@ -67,7 +67,10 @@ module CrudTest
|
|
67
67
|
assert_assigns_errors(resource_name) unless test_bot_skip?(:assigns_errors)
|
68
68
|
|
69
69
|
assert_equal(before[:count], after[:count], "Expected #{resource_class}.count to be unchanged") if resource_class.respond_to?(:count)
|
70
|
-
|
70
|
+
|
71
|
+
if resources_path.present? && !test_bot_skip?(:path)
|
72
|
+
assert_equal(resources_path, page.current_path, "(path) Expected current_path to match resource #create path #{resources_path}")
|
73
|
+
end
|
71
74
|
|
72
75
|
assert_flash(:danger) unless test_bot_skip?(:flash)
|
73
76
|
end
|
@@ -150,13 +153,14 @@ module CrudTest
|
|
150
153
|
assert_assigns(resource_name) unless test_bot_skip?(:assigns)
|
151
154
|
assert_assigns_errors(resource_name) unless test_bot_skip?(:assigns_errors)
|
152
155
|
|
153
|
-
|
156
|
+
if effective_resource.action_path(:update, resource) && !test_bot_skip?(:path)
|
157
|
+
assert_equal(effective_resource.action_path(:update, resource), page.current_path, "(path) Expected current_path to match resource #update path") unless test_bot_skip?(:path)
|
158
|
+
end
|
154
159
|
|
155
160
|
assert_equal before[:count], after[:count], "Expected: #{resource_class}.count to be unchanged"
|
156
161
|
assert_equal(before[:updated_at], after[:updated_at], "(updated_at) Expected @#{resource_name}.updated_at to be unchanged") if (resource.respond_to?(:updated_at) && !test_bot_skip?(:updated_at))
|
157
162
|
|
158
163
|
assert_flash(:danger) unless test_bot_skip?(:flash)
|
159
|
-
|
160
164
|
end
|
161
165
|
|
162
166
|
def test_bot_update_valid_test
|
@@ -203,7 +207,7 @@ module CrudTest
|
|
203
207
|
visit(resources_path)
|
204
208
|
save_test_bot_screenshot
|
205
209
|
|
206
|
-
link_to_delete =
|
210
|
+
link_to_delete = create_rails_ujs_link_to_delete(resource)
|
207
211
|
|
208
212
|
if link_to_delete.present? && (link_to_delete.click() rescue false)
|
209
213
|
synchronize!
|
@@ -217,7 +221,7 @@ module CrudTest
|
|
217
221
|
# So we just assert the 200 status code, and page title present manually
|
218
222
|
# Javascript errors cannot be detected
|
219
223
|
|
220
|
-
visit_delete(
|
224
|
+
visit_delete(destroy_resource_path(resource), user)
|
221
225
|
assert_equal(200, @visit_delete_page.try(:status_code), '(page_status) Expected 200 HTTP status code') unless test_bot_skip?(:page_status)
|
222
226
|
assert((@visit_delete_page.find(:xpath, '//title', visible: false) rescue nil).present?, '(page_title) Expected page title to be present') unless test_bot_skip?(:page_title)
|
223
227
|
end
|
@@ -57,9 +57,10 @@ module DeviseTest
|
|
57
57
|
|
58
58
|
within_if('form#new_user', !test_bot_skip?(:form)) do
|
59
59
|
fill_form(email: email, password: 'not-correct-password')
|
60
|
-
|
60
|
+
submit_novalidate_form
|
61
61
|
end
|
62
62
|
|
63
|
+
assert_assigns_errors(:user)
|
63
64
|
assert_page_normal
|
64
65
|
|
65
66
|
assert_signed_out
|
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: 1.0.
|
4
|
+
version: 1.0.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: 2018-
|
11
|
+
date: 2018-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|