auto_test 0.1.9.8.7 → 1.0
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.
- data/README.md +5 -4
- data/lib/authentication.rb +32 -14
- data/lib/auto_test.rb +3 -4
- data/lib/auto_test/railtie.rb +1 -0
- data/lib/auto_test/version.rb +1 -1
- data/lib/dsl.rb +10 -1
- data/lib/error.rb +9 -1
- data/lib/page.rb +17 -2
- data/lib/spec/requests/auto_spec.rb +3 -0
- data/lib/spec/requests/error_reduction_spec.rb +376 -361
- data/lib/spec/requests/simulation_spec.rb +20 -1
- data/lib/tasks/auto_test.rb +3 -3
- data/lib/test.rb +92 -39
- data/lib/test_starter.rb +8 -0
- metadata +2 -2
@@ -5,14 +5,16 @@ require 'auto_test'
|
|
5
5
|
|
6
6
|
describe "Application" do
|
7
7
|
describe "auto_test" do
|
8
|
-
|
8
|
+
# load the fixtures
|
9
9
|
if AutoTest::Test.use_fixtures? then
|
10
10
|
fixtures(*AutoTest::Test.get_fixtures)
|
11
11
|
end
|
12
12
|
it "simulates the error" do
|
13
|
+
# load test data
|
13
14
|
load "#{Rails.root}/db/test_seeds.rb"
|
14
15
|
sessions_array = []
|
15
16
|
puts "Firefox is getting started..."
|
17
|
+
# get the path to simulate
|
16
18
|
begin
|
17
19
|
paths = File.new("#{Rails.root}/log/new_path.log", "r")
|
18
20
|
rescue
|
@@ -22,24 +24,30 @@ describe "Application" do
|
|
22
24
|
sessions = search_sessions
|
23
25
|
number_of_sessions = sessions.size
|
24
26
|
user = Array.new(AutoTest::Test.get_number_of_sessions.to_i)
|
27
|
+
# start right number of firefox browsers
|
25
28
|
for i in 0..number_of_sessions-1 do
|
26
29
|
browser = Watir::Browser.new :ff
|
27
30
|
sessions_array[sessions[i]] = browser
|
28
31
|
end
|
32
|
+
|
29
33
|
while line = paths.gets do
|
34
|
+
# parse the path
|
30
35
|
if !line.chop!.end_with? "ID" then
|
31
36
|
hash = Hash.new
|
32
37
|
a = line.gsub!(/[{}\"]/,'').split(/\=\>/)
|
33
38
|
session = sessions_array[a[0].split(":").first.to_i]
|
34
39
|
session_index = sessions_array.index(session)
|
35
40
|
session.windows.first.use
|
41
|
+
# login
|
36
42
|
if a[0].split(":").second == AutoTest::Authentication.get_login_path then
|
37
43
|
session.goto home + AutoTest::Authentication.get_login_path
|
38
44
|
hash["#{a[0]}"] = a[1]
|
39
45
|
login(session, user[session_index].class.find(user[session_index].id))
|
46
|
+
# logout
|
40
47
|
elsif a[1] == AutoTest::Authentication.get_logout_path then
|
41
48
|
hash["#{a[0]}"] = AutoTest::Authentication.get_logout_path
|
42
49
|
session.goto home + AutoTest::Authentication.get_logout_path
|
50
|
+
# fill in form
|
43
51
|
elsif a[1][0] == "[" then
|
44
52
|
texts = []
|
45
53
|
inputs = a[1][1,a[1].size-2].split(/,/)
|
@@ -58,23 +66,30 @@ describe "Application" do
|
|
58
66
|
session.text_field(:name => inputs[i].strip).set inputs[i+1].strip
|
59
67
|
end
|
60
68
|
i = i + 2
|
69
|
+
# wait 2 seconds, so the user can follow the simulation
|
70
|
+
sleep 2
|
61
71
|
end
|
62
72
|
hash["#{a[0]}"] = texts
|
73
|
+
# click submit button
|
63
74
|
session.button(:type => "submit").click
|
64
75
|
else
|
76
|
+
# find and click link
|
65
77
|
link = a[1].split(/\+\+\+/)
|
66
78
|
href = link[0]
|
67
79
|
text = link[1]
|
68
80
|
session.a(:href => href, :text => text).flash
|
69
81
|
session.a(:href => href, :text => text).click
|
70
82
|
begin
|
83
|
+
# if a javascript alert pops up, accept it
|
71
84
|
session.driver.switch_to.alert.accept
|
72
85
|
rescue
|
73
86
|
end
|
74
87
|
hash["#{a[0]}"] = a[1]
|
75
88
|
end
|
89
|
+
# wait 2 seconds, so the user can follow the simulation
|
76
90
|
sleep 2
|
77
91
|
else
|
92
|
+
# get the right user
|
78
93
|
line_parts = line.split(":")
|
79
94
|
session_index = line_parts[0].to_i
|
80
95
|
id = line_parts[1].to_i
|
@@ -90,13 +105,16 @@ describe "Application" do
|
|
90
105
|
end
|
91
106
|
end
|
92
107
|
|
108
|
+
# login a user in a certain browser
|
93
109
|
def login(browser, user)
|
94
110
|
if AutoTest::Authentication.use_db_users then
|
111
|
+
# if data read from db, fill in forms
|
95
112
|
AutoTest::Authentication.get_login_attributes.each do |field|
|
96
113
|
browser.text_field(:id => field[1]).set user.send(field[0].to_sym)
|
97
114
|
end
|
98
115
|
sleep 1
|
99
116
|
else
|
117
|
+
# if data given by tester, fill these in
|
100
118
|
index = AutoTest::Authentication.get_login_names.index(AutoTest::Authentication.get_unique_login_attribute_name)
|
101
119
|
user_data = nil
|
102
120
|
user.class.find(:all).each do |u|
|
@@ -114,6 +132,7 @@ def login(browser, user)
|
|
114
132
|
browser.button(:type => 'submit').click
|
115
133
|
end
|
116
134
|
|
135
|
+
# get the session ids from the path
|
117
136
|
def search_sessions
|
118
137
|
begin
|
119
138
|
path_to_search = File.new("#{Rails.root}/log/new_path.log", "r")
|
data/lib/tasks/auto_test.rb
CHANGED
@@ -4,7 +4,7 @@ path = %x(gem which auto_test)
|
|
4
4
|
path = path[0..path.size-15]
|
5
5
|
|
6
6
|
namespace :auto_test do
|
7
|
-
desc "
|
7
|
+
desc "Starting the test"
|
8
8
|
task :test do
|
9
9
|
puts "Running auto_test..."
|
10
10
|
sh "rspec '#{path}/spec/requests/auto_spec.rb' -o '#{path}/../log/rspec.txt'"
|
@@ -15,7 +15,7 @@ namespace :auto_test do
|
|
15
15
|
Rake::Task["auto_test:error_calc"].invoke
|
16
16
|
end
|
17
17
|
|
18
|
-
desc "
|
18
|
+
desc "Calculating the errors"
|
19
19
|
task :error_calc do
|
20
20
|
err = File.read("#{Rails.root}/log/errors.log")
|
21
21
|
if err.to_i > 0 then
|
@@ -51,7 +51,7 @@ namespace :auto_test do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
|
54
|
-
desc '
|
54
|
+
desc 'Stopping rails server'
|
55
55
|
task :stop do
|
56
56
|
begin
|
57
57
|
pid_file = 'tmp/pids/server.pid'
|
data/lib/test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module AutoTest
|
2
2
|
module Test
|
3
3
|
module_function
|
4
|
+
|
4
5
|
# initialize all variables
|
5
6
|
def initialize_test
|
6
7
|
Error.init_error
|
@@ -20,6 +21,9 @@ module AutoTest
|
|
20
21
|
init_number_of_test_runs
|
21
22
|
end
|
22
23
|
|
24
|
+
###############################################################
|
25
|
+
### initializers
|
26
|
+
|
23
27
|
def init_links
|
24
28
|
@@links = []
|
25
29
|
end
|
@@ -27,22 +31,6 @@ module AutoTest
|
|
27
31
|
def init_fixtures
|
28
32
|
@@use_fixtures = false
|
29
33
|
end
|
30
|
-
|
31
|
-
def use_fixtures?
|
32
|
-
@@use_fixtures
|
33
|
-
end
|
34
|
-
|
35
|
-
def fixtures(*fixtures)
|
36
|
-
@@fixtures = fixtures
|
37
|
-
end
|
38
|
-
|
39
|
-
def get_fixtures
|
40
|
-
@@fixtures
|
41
|
-
end
|
42
|
-
|
43
|
-
def use_fixtures(bool)
|
44
|
-
@@use_fixtures = bool
|
45
|
-
end
|
46
34
|
|
47
35
|
def init_number_of_test_runs
|
48
36
|
@@runs = 1
|
@@ -85,9 +73,49 @@ module AutoTest
|
|
85
73
|
def init_inputs
|
86
74
|
@@inputs = Hash.new
|
87
75
|
end
|
88
|
-
|
89
76
|
|
77
|
+
def init_sessions
|
78
|
+
@sessions = Hash.new
|
79
|
+
end
|
80
|
+
|
81
|
+
def init_hash_sessions(key, value)
|
82
|
+
@sessions["#{key}"] = value
|
83
|
+
end
|
84
|
+
|
85
|
+
def init_sessions_array
|
86
|
+
@sessions_array = []
|
87
|
+
end
|
88
|
+
|
89
|
+
def init_ready
|
90
|
+
@ready = Array.new(Test.get_number_of_sessions)
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
###############################################################
|
95
|
+
|
96
|
+
# getter for use fixtures
|
97
|
+
def use_fixtures?
|
98
|
+
@@use_fixtures
|
99
|
+
end
|
100
|
+
|
101
|
+
# set the fixtures to be used
|
102
|
+
def fixtures(*fixtures)
|
103
|
+
@@fixtures = fixtures
|
104
|
+
end
|
105
|
+
|
106
|
+
# get the fixtures
|
107
|
+
def get_fixtures
|
108
|
+
@@fixtures
|
109
|
+
end
|
110
|
+
|
111
|
+
# determine if fixtures should be used
|
112
|
+
def use_fixtures(bool)
|
113
|
+
@@use_fixtures = bool
|
114
|
+
end
|
115
|
+
|
116
|
+
# check the invariants
|
90
117
|
def check_invariants
|
118
|
+
# check always present invariant
|
91
119
|
get_always_present.each do |present|
|
92
120
|
if present[0].find(:first, :conditions => "#{present[1]} = '#{present[2]}'") == nil then
|
93
121
|
if stop_at_first_error? then stop! end
|
@@ -99,6 +127,7 @@ module AutoTest
|
|
99
127
|
Error.inc_error(message)
|
100
128
|
end
|
101
129
|
end
|
130
|
+
# check object dependency invariant
|
102
131
|
get_object_dependencies.each do |dependency|
|
103
132
|
children = dependency[0].find(:all)
|
104
133
|
children.each do |child|
|
@@ -117,26 +146,32 @@ module AutoTest
|
|
117
146
|
end
|
118
147
|
end
|
119
148
|
|
149
|
+
# user function to set number of test runs
|
120
150
|
def set_number_of_test_runs(number)
|
121
151
|
@@runs = number
|
122
152
|
end
|
123
153
|
|
154
|
+
# get number of test runs
|
124
155
|
def get_number_of_test_runs
|
125
156
|
@@runs
|
126
157
|
end
|
127
|
-
|
158
|
+
|
159
|
+
# user function ti stop at first error
|
128
160
|
def stop_at_first_error(stop_at_first_error)
|
129
161
|
@@stop_at_first_error = stop_at_first_error
|
130
162
|
end
|
131
163
|
|
164
|
+
# get stop at first error
|
132
165
|
def stop_at_first_error?
|
133
166
|
@@stop_at_first_error
|
134
167
|
end
|
135
168
|
|
169
|
+
# has the test to be stopped?
|
136
170
|
def stop?
|
137
171
|
@@stop
|
138
172
|
end
|
139
173
|
|
174
|
+
# stop the test
|
140
175
|
def stop!
|
141
176
|
@@stop = true
|
142
177
|
end
|
@@ -146,24 +181,27 @@ module AutoTest
|
|
146
181
|
@@depth = @@depth + 1
|
147
182
|
end
|
148
183
|
|
184
|
+
# get depth
|
149
185
|
def get_depth
|
150
186
|
@@depth
|
151
187
|
end
|
152
|
-
|
188
|
+
|
189
|
+
# user function to set the maximum depth
|
153
190
|
def set_max_depth(value)
|
154
191
|
@@max_depth = value
|
155
192
|
end
|
156
193
|
|
194
|
+
# get max depth
|
157
195
|
def get_max_depth
|
158
196
|
@@max_depth
|
159
197
|
end
|
160
198
|
|
161
|
-
|
162
199
|
# get object dependencies
|
163
200
|
def get_object_dependencies
|
164
201
|
@@dependencies
|
165
202
|
end
|
166
203
|
|
204
|
+
# user function to set invariant for object dependency
|
167
205
|
# for all objects of class child, there has to be one object of class parent
|
168
206
|
# attribute_name is the column that joins the two tables
|
169
207
|
def set_object_dependency(child, parent, attribute_name)
|
@@ -176,95 +214,113 @@ module AutoTest
|
|
176
214
|
@@inputs.store(input, values)
|
177
215
|
end
|
178
216
|
|
217
|
+
# get inputs
|
179
218
|
def get_inputs
|
180
219
|
@@inputs
|
181
220
|
end
|
182
221
|
|
222
|
+
# user function to set the number of sessions used to test the app
|
183
223
|
def set_number_of_sessions(number)
|
184
224
|
@@number_of_sessions = number
|
185
225
|
end
|
186
226
|
|
227
|
+
# get number of sessions
|
187
228
|
def get_number_of_sessions
|
188
229
|
@@number_of_sessions
|
189
230
|
end
|
190
|
-
|
231
|
+
|
232
|
+
# user function to set the invariant 'always present'
|
191
233
|
# add an array of the classname, key and value of the object to be checked every cycle
|
192
234
|
def always_present(class_name, key, value)
|
193
235
|
@@always_present << [class_name, key, value]
|
194
236
|
end
|
195
237
|
|
238
|
+
# get invariant always present
|
196
239
|
def get_always_present
|
197
240
|
@@always_present
|
198
241
|
end
|
199
242
|
|
243
|
+
# get the links to exclude from the test
|
200
244
|
def get_links_to_exclude
|
201
245
|
@@links
|
202
246
|
end
|
203
247
|
|
204
|
-
# list of links that will not be clicked during the test
|
248
|
+
# user function to set the list of links that will not be clicked during the test
|
205
249
|
def links_to_exclude(*links)
|
206
250
|
@@links = links
|
207
251
|
end
|
208
252
|
|
253
|
+
# setter for paths
|
209
254
|
def paths=(value)
|
210
255
|
@paths = value
|
211
256
|
end
|
212
257
|
|
258
|
+
# getter for paths
|
213
259
|
def paths
|
214
260
|
@paths
|
215
261
|
end
|
216
262
|
|
263
|
+
# getter for iterations
|
217
264
|
def iterations
|
218
265
|
@iterations
|
219
266
|
end
|
220
267
|
|
268
|
+
# setter for iterations
|
221
269
|
def iterations=(value)
|
222
270
|
@iterations = value
|
223
271
|
end
|
224
272
|
|
273
|
+
# getter for link counter
|
225
274
|
def link_counter
|
226
275
|
@link_counter
|
227
276
|
end
|
277
|
+
|
278
|
+
# setter for link counter
|
228
279
|
def link_counter=(value)
|
229
280
|
@link_counter = value
|
230
281
|
end
|
231
282
|
|
283
|
+
# setter for run
|
232
284
|
def run=(value)
|
233
285
|
@run = value
|
234
286
|
end
|
235
287
|
|
288
|
+
# getter for run
|
236
289
|
def run
|
237
290
|
@run
|
238
291
|
end
|
239
292
|
|
293
|
+
# getter for action path
|
240
294
|
def action_path
|
241
295
|
@@action_paths
|
242
296
|
end
|
243
297
|
|
298
|
+
# getter for no authentication
|
244
299
|
def no_auth
|
245
300
|
@@no_auth
|
246
301
|
end
|
247
302
|
|
303
|
+
# user function to determine that the application has no authentification
|
248
304
|
def set_no_auth
|
249
305
|
@@no_auth = true
|
250
306
|
end
|
251
|
-
|
307
|
+
|
308
|
+
# method to add an element to the action path
|
252
309
|
def add_to_action_path(hash)
|
253
310
|
@@action_paths << hash
|
254
311
|
end
|
255
312
|
|
313
|
+
# getter for number of users logged in during the test
|
256
314
|
def users_logged_in
|
257
315
|
@users_logged_in
|
258
316
|
end
|
259
317
|
|
260
|
-
|
261
|
-
@ready = Array.new(Test.get_number_of_sessions)
|
262
|
-
end
|
263
|
-
|
318
|
+
# set one session to be finished in this round of the test
|
264
319
|
def ready(i)
|
265
320
|
@ready[i-1] = true
|
266
321
|
end
|
267
322
|
|
323
|
+
# see if all sessions are ready
|
268
324
|
def ready?
|
269
325
|
count = 0
|
270
326
|
for i in 0..@ready.size-1 do
|
@@ -279,42 +335,39 @@ module AutoTest
|
|
279
335
|
end
|
280
336
|
end
|
281
337
|
|
282
|
-
|
283
|
-
@sessions = Hash.new
|
284
|
-
end
|
285
|
-
|
286
|
-
def init_hash_sessions(key, value)
|
287
|
-
@sessions["#{key}"] = value
|
288
|
-
end
|
289
|
-
|
338
|
+
# set variables for a session
|
290
339
|
def sessions(index, key, value)
|
291
340
|
@sessions["#{index}"]["#{key}"] = value
|
292
341
|
end
|
293
342
|
|
343
|
+
# get variables for a session
|
294
344
|
def get_sessions(i, key)
|
295
345
|
@sessions["#{i}"]["#{key}"]
|
296
346
|
end
|
297
347
|
|
348
|
+
# getter for sessions array
|
298
349
|
def get_sessions_array
|
299
350
|
@sessions_array
|
300
351
|
end
|
301
352
|
|
302
|
-
|
303
|
-
|
304
|
-
end
|
305
|
-
|
353
|
+
|
354
|
+
# method to add a session
|
306
355
|
def add_to_sessions_array(session)
|
307
356
|
@sessions_array << session
|
308
357
|
end
|
309
358
|
|
359
|
+
# setter for users logged in
|
310
360
|
def users_logged_in=(value)
|
311
361
|
@users_logged_in = value
|
312
362
|
end
|
313
363
|
|
364
|
+
# user function to set the maximum number of links a session may click before the
|
365
|
+
# next session continues
|
314
366
|
def set_max_number_of_session_links(no)
|
315
367
|
@@no_session_links = no
|
316
368
|
end
|
317
369
|
|
370
|
+
# getter fo maximum number of session links
|
318
371
|
def get_max_number_of_session_links
|
319
372
|
@@no_session_links
|
320
373
|
end
|