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
@@ -6,17 +6,22 @@ require 'auto_test'
|
|
6
6
|
|
7
7
|
describe "Application" do
|
8
8
|
describe "error path reduction" do
|
9
|
+
# load fixtures
|
9
10
|
if AutoTest::Test.use_fixtures? then
|
10
11
|
fixtures(*AutoTest::Test.get_fixtures)
|
11
12
|
end
|
12
13
|
it "reduces the path to the error" do
|
14
|
+
# load test data
|
13
15
|
load "#{Rails.root}/db/test_seeds.rb"
|
16
|
+
# set db clean strategy to transcation
|
14
17
|
DatabaseCleaner.strategy = :transaction
|
18
|
+
# start the transaction
|
15
19
|
DatabaseCleaner.start
|
16
20
|
init_path
|
17
21
|
init_sessions
|
18
22
|
init_sessions_array
|
19
23
|
number_of_sessions = AutoTest::Test.get_number_of_sessions
|
24
|
+
# instantiate sessions
|
20
25
|
for i in 0..number_of_sessions-1 do
|
21
26
|
sess = Capybara::Session.new(:rack_test,Rails.application)
|
22
27
|
add_to_sessions_array sess
|
@@ -28,86 +33,97 @@ describe "Application" do
|
|
28
33
|
user = Array.new(number_of_sessions)
|
29
34
|
session_index = 0
|
30
35
|
begin
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
hash["#{get_sessions_array.index(session)}:#{session.current_path}"] = AutoTest::Authentication.get_login_button
|
47
|
-
if AutoTest::Authentication.use_db_users then
|
48
|
-
AutoTest::Authentication.get_login_attributes.each do |field|
|
49
|
-
session.fill_in field[1], :with => user[session_index].send(field[0].to_sym)
|
50
|
-
end
|
51
|
-
else
|
52
|
-
user_data = nil
|
53
|
-
index = AutoTest::Authentication.get_login_names.index(AutoTest::Authentication.get_unique_login_attribute_name)
|
54
|
-
user[session_index].class.find(:all).each do |u|
|
55
|
-
AutoTest::Authentication.get_login_data.each do |d|
|
56
|
-
if d[index] == u.send(AutoTest::Authentication.get_unique_login_attribute_name.to_sym) then
|
57
|
-
user_data = AutoTest::Authentication.get_login_data[index]
|
58
|
-
end
|
59
|
-
end
|
36
|
+
#read the path, parse it and check if the error is reproducable
|
37
|
+
while line = paths.gets do
|
38
|
+
lno = lno + 1
|
39
|
+
if !line.chop!.end_with? "ID" then
|
40
|
+
hash = Hash.new
|
41
|
+
a = line.gsub!(/[{}\"]/,'').split(/\=\>/)
|
42
|
+
session = get_sessions_array[a[0].split(":").first.to_i]
|
43
|
+
session_index = get_sessions_array.index(session)
|
44
|
+
# login
|
45
|
+
if a[0].split(":").second == AutoTest::Authentication.get_login_path then
|
46
|
+
begin
|
47
|
+
# necesarry if user data has changed
|
48
|
+
# might have to be rescued if the user doesn´t exist anymore.
|
49
|
+
user[session_index] = user[session_index].class.find(user[session_index].id)
|
50
|
+
rescue
|
60
51
|
end
|
61
|
-
AutoTest::Authentication.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
session.visit AutoTest::Authentication.get_logout_path
|
69
|
-
elsif a[1][0] == "[" then
|
70
|
-
texts = []
|
71
|
-
inputs = a[1][1,a[1].size-2].split(/,/)
|
72
|
-
i = 0
|
73
|
-
while i < inputs.size do
|
74
|
-
texts << inputs[i].strip
|
75
|
-
texts << inputs[i+1].strip
|
76
|
-
if inputs[i].strip.start_with? "radio___" then
|
77
|
-
session.choose inputs[i + 1].strip
|
78
|
-
elsif inputs[i].strip.start_with? "select___" then
|
79
|
-
session.select inputs[i + 1].strip, :from => inputs[i].gsub("select___",'').strip
|
80
|
-
elsif inputs[i].strip.start_with? "checkbox___" then
|
81
|
-
session.check inputs[i].gsub("checkbox___",'').strip
|
52
|
+
session.visit AutoTest::Authentication.get_login_path
|
53
|
+
hash["#{get_sessions_array.index(session)}:#{session.current_path}"] = AutoTest::Authentication.get_login_button
|
54
|
+
# depending on the kind the user is stored in the db, fill in the fields
|
55
|
+
if AutoTest::Authentication.use_db_users then
|
56
|
+
AutoTest::Authentication.get_login_attributes.each do |field|
|
57
|
+
session.fill_in field[1], :with => user[session_index].send(field[0].to_sym)
|
58
|
+
end
|
82
59
|
else
|
83
|
-
|
84
|
-
|
60
|
+
user_data = nil
|
61
|
+
index = AutoTest::Authentication.get_login_names.index(AutoTest::Authentication.get_unique_login_attribute_name)
|
62
|
+
user[session_index].class.find(:all).each do |u|
|
63
|
+
AutoTest::Authentication.get_login_data.each do |d|
|
64
|
+
if d[index] == u.send(AutoTest::Authentication.get_unique_login_attribute_name.to_sym) then
|
65
|
+
user_data = AutoTest::Authentication.get_login_data[index]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
AutoTest::Authentication.get_login_attributes.each_with_index do |field, i|
|
70
|
+
session.fill_in field[1], :with => user_data[i]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
session.click_button AutoTest::Authentication.get_login_button
|
74
|
+
# logout
|
75
|
+
elsif a[1] == AutoTest::Authentication.get_logout_path then
|
76
|
+
hash["#{get_sessions_array.index(session)}:#{session.current_path}"] = AutoTest::Authentication.get_logout_path
|
77
|
+
session.visit AutoTest::Authentication.get_logout_path
|
78
|
+
# fill in forms
|
79
|
+
elsif a[1][0] == "[" then
|
80
|
+
texts = []
|
81
|
+
inputs = a[1][1,a[1].size-2].split(/,/)
|
82
|
+
i = 0
|
83
|
+
while i < inputs.size do
|
84
|
+
texts << inputs[i].strip
|
85
|
+
texts << inputs[i+1].strip
|
86
|
+
if inputs[i].strip.start_with? "radio___" then
|
87
|
+
session.choose inputs[i + 1].strip
|
88
|
+
elsif inputs[i].strip.start_with? "select___" then
|
89
|
+
session.select inputs[i + 1].strip, :from => inputs[i].gsub("select___",'').strip
|
90
|
+
elsif inputs[i].strip.start_with? "checkbox___" then
|
91
|
+
session.check inputs[i].gsub("checkbox___",'').strip
|
92
|
+
else
|
93
|
+
input = session.all('input').find{ |inp| inp[:name] == inputs[i].strip}
|
94
|
+
input.set(inputs[i+1].strip)
|
95
|
+
end
|
96
|
+
i = i + 2
|
85
97
|
end
|
86
|
-
|
98
|
+
hash["#{get_sessions_array.index(session)}:#{session.current_path}"] = texts
|
99
|
+
session.all('input').find_all{ |i| i[:type] == "submit"}.first.click
|
100
|
+
else
|
101
|
+
# click link
|
102
|
+
link = a[1].split(/\+\+\+/)
|
103
|
+
href = link[0]
|
104
|
+
text = link[1]
|
105
|
+
link = session.all('a').find{ |l| l[:href] == href && l.text == text }
|
106
|
+
hash["#{get_sessions_array.index(session)}:#{session.current_path}"] = link[:href].to_s + "+++" + link.text.to_s
|
107
|
+
link.click
|
87
108
|
end
|
88
|
-
|
89
|
-
|
109
|
+
# save the parsed line as a hash
|
110
|
+
add_path(hash)
|
90
111
|
else
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
else
|
100
|
-
add_path(line)
|
101
|
-
line_parts = line.split(":")
|
102
|
-
session_index = line_parts[0].to_i
|
103
|
-
id = line_parts[1].to_i
|
104
|
-
# get the Constant from the String, to find the right class
|
105
|
-
user[session_index] = AutoTest::Authentication.user_class.find(id)
|
112
|
+
# save the parsed line as a String
|
113
|
+
add_path(line)
|
114
|
+
line_parts = line.split(":")
|
115
|
+
session_index = line_parts[0].to_i
|
116
|
+
id = line_parts[1].to_i
|
117
|
+
# find the right user
|
118
|
+
user[session_index] = AutoTest::Authentication.user_class.find(id)
|
119
|
+
end
|
106
120
|
end
|
107
|
-
|
121
|
+
# rescue from the exception
|
108
122
|
rescue => e
|
123
|
+
# check if the right exception occurred and reduce the path
|
109
124
|
if err_message == e.message.to_s.split(/:/,2).first then
|
110
125
|
add_path(hash)
|
126
|
+
# step 1: jump to last user
|
111
127
|
new_path = jump_to_last_user(path)
|
112
128
|
init_enlarging_counter
|
113
129
|
error_not_found = true
|
@@ -115,11 +131,14 @@ describe "Application" do
|
|
115
131
|
while error_not_found do
|
116
132
|
error_not_found = try_path(new_path)
|
117
133
|
if error_not_found then
|
134
|
+
# in case of no or the wrong error enlarge the path and try again
|
118
135
|
new_path = enlarge_path(path)
|
119
136
|
end
|
120
137
|
end
|
121
138
|
last_path = new_path
|
139
|
+
# step 2: replace the users that are equal and therefore have larger parts between users
|
122
140
|
replace_same_users!(last_path)
|
141
|
+
# count the ID lines in the path
|
123
142
|
user_count = user_count(last_path)
|
124
143
|
# test the path, getting divided
|
125
144
|
for i in 1..user_count do
|
@@ -127,9 +146,12 @@ describe "Application" do
|
|
127
146
|
index = nil
|
128
147
|
path_still_changing = true
|
129
148
|
last_index = nil
|
149
|
+
# as long as the error is found and the path still changes
|
130
150
|
while !error_not_found && path_still_changing do
|
151
|
+
# delete parts of the path
|
131
152
|
return_val = delete_links_half_way(last_path, index, i)
|
132
153
|
index = return_val[1]
|
154
|
+
# check if the path was changed
|
133
155
|
if index == last_index then
|
134
156
|
path_still_changing = false
|
135
157
|
else
|
@@ -137,7 +159,9 @@ describe "Application" do
|
|
137
159
|
path_still_changing = true
|
138
160
|
end
|
139
161
|
next_path = return_val[0]
|
162
|
+
# try the path
|
140
163
|
error_not_found = try_path(next_path)
|
164
|
+
# if the error isn´t found, add one action at a time and try again
|
141
165
|
while error_not_found do
|
142
166
|
return_val = delete_links_half_way(last_path, index, i)
|
143
167
|
index = return_val[1]
|
@@ -150,9 +174,13 @@ describe "Application" do
|
|
150
174
|
index = nil
|
151
175
|
end
|
152
176
|
end
|
177
|
+
# delete groups of links
|
153
178
|
last_path = delete_groups(last_path)
|
179
|
+
# delete single links
|
154
180
|
last_path = delete_single_links(last_path)
|
155
|
-
|
181
|
+
# delete unnecessary ids
|
182
|
+
delete_ids(last_path)
|
183
|
+
# save the reduced file
|
156
184
|
f = File.new("#{Rails.root}/log/new_path.log", "w")
|
157
185
|
f.puts last_path
|
158
186
|
f.close
|
@@ -162,224 +190,12 @@ describe "Application" do
|
|
162
190
|
end
|
163
191
|
end
|
164
192
|
|
165
|
-
|
166
|
-
next_path = []
|
167
|
-
no_inputs = true
|
168
|
-
tmp = []
|
169
|
-
got_one = false
|
170
|
-
done = false
|
171
|
-
new_path.each do |n|
|
172
|
-
done = false
|
173
|
-
# check if the line is an ID
|
174
|
-
if n.class == String then
|
175
|
-
# check if it´s the right session
|
176
|
-
if n.to_i == session then
|
177
|
-
# add the line to the path
|
178
|
-
next_path << n
|
179
|
-
# save, that the part before was processed
|
180
|
-
done = true
|
181
|
-
# save, that the right session id has been found
|
182
|
-
got_one = true
|
183
|
-
else
|
184
|
-
# for other session ids add the line to the tmp array
|
185
|
-
tmp << n
|
186
|
-
end
|
187
|
-
else
|
188
|
-
current_session = n.keys[0].split(":").first.to_i
|
189
|
-
# if the right session id hasn´t been found, add the line to the path
|
190
|
-
if current_session != session && !got_one then
|
191
|
-
next_path << n
|
192
|
-
# else add the line to the tmp array
|
193
|
-
else
|
194
|
-
tmp << n
|
195
|
-
# check for input data for forms
|
196
|
-
if n.values[0].class == Array && current_session == session then
|
197
|
-
no_inputs = false
|
198
|
-
end
|
199
|
-
# if the part of the session to be deleted is finished,
|
200
|
-
# has no inputs and is smaller or equal to the wanted number of links,
|
201
|
-
# delete the links of the session, other links get added to the path
|
202
|
-
if n.values[0] == AutoTest::Authentication.get_logout_path && no_inputs && current_session == session then
|
203
|
-
if tmp.select{|x| x.class != String && x.keys[0].split(":").first.to_i == session}.size == number_of_links then
|
204
|
-
tmp.delete_if{|x| x.class != String && x.keys[0].split(":").first.to_i == session}
|
205
|
-
next_path << tmp
|
206
|
-
tmp = []
|
207
|
-
done = true
|
208
|
-
got_one = false
|
209
|
-
else
|
210
|
-
next_path << tmp
|
211
|
-
tmp = []
|
212
|
-
done = true
|
213
|
-
got_one = false
|
214
|
-
end
|
215
|
-
elsif n.values[0] == AutoTest::Authentication.get_logout_path && current_session == session then
|
216
|
-
next_path << tmp
|
217
|
-
tmp = []
|
218
|
-
done = true
|
219
|
-
no_inputs = true
|
220
|
-
got_one = false
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
if !done then
|
226
|
-
next_path << tmp
|
227
|
-
end
|
228
|
-
return next_path.flatten
|
229
|
-
end
|
230
|
-
|
231
|
-
def delete_ids(new_path)
|
232
|
-
for i in 0..get_sessions_array.size - 1 do
|
233
|
-
found_session = false
|
234
|
-
index_to_delete = nil
|
235
|
-
new_path.each_with_index do |n, index|
|
236
|
-
if n.class == String && n.to_i == i then
|
237
|
-
index_to_delete = index
|
238
|
-
if !found_session && index_to_delete != index then
|
239
|
-
new_path.delete_at(index_to_delete)
|
240
|
-
end
|
241
|
-
found_session = false
|
242
|
-
else
|
243
|
-
if (n.class != String && n.keys[0].split(":").first.to_i == i) then
|
244
|
-
found_session = true
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
if !found_session then
|
249
|
-
new_path.delete_at(index_to_delete)
|
250
|
-
end
|
251
|
-
found_session = false
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
def delete_groups(new_path)
|
256
|
-
for i in 0..get_sessions_array.size - 1 do
|
257
|
-
no_of_group = 1
|
258
|
-
no_of_groups = 1
|
259
|
-
tmp = []
|
260
|
-
while no_of_group <= no_of_groups do
|
261
|
-
count = 0
|
262
|
-
no_of_groups = 0
|
263
|
-
next_path = []
|
264
|
-
new_path.each_with_index do |n,ind|
|
265
|
-
if n.class != String then
|
266
|
-
if n.keys[0].split(":").second == AutoTest::Authentication.get_login_path && n.keys[0].split(":").first.to_i == i then
|
267
|
-
count = count + 1
|
268
|
-
end
|
269
|
-
if !(n.keys[0].split(":").first.to_i == i && count == no_of_group) then
|
270
|
-
next_path << n
|
271
|
-
else
|
272
|
-
tmp << n
|
273
|
-
end
|
274
|
-
else
|
275
|
-
next_path << n
|
276
|
-
end
|
277
|
-
end
|
278
|
-
error_not_found = try_path(next_path)
|
279
|
-
if error_not_found && tmp != [] then
|
280
|
-
no_of_group = no_of_group + 1
|
281
|
-
else
|
282
|
-
new_path = next_path
|
283
|
-
end
|
284
|
-
new_path.each do |n|
|
285
|
-
if n.class != String && n.keys[0].split(":").first.to_i == i && n.values[0] == AutoTest::Authentication.get_logout_path then
|
286
|
-
no_of_groups = no_of_groups + 1
|
287
|
-
end
|
288
|
-
end
|
289
|
-
tmp = []
|
290
|
-
end
|
291
|
-
end
|
292
|
-
return new_path
|
293
|
-
puts new_path
|
294
|
-
end
|
295
|
-
|
296
|
-
def delete_single_links(new_path)
|
297
|
-
i = 0
|
298
|
-
while i < new_path.size do
|
299
|
-
if (new_path[i].class != String &&
|
300
|
-
!(new_path[i].values.include? AutoTest::Authentication.get_logout_path) &&
|
301
|
-
!(new_path[i].keys[0].include? AutoTest::Authentication.get_login_path)) then
|
302
|
-
next_path = new_path[0..i-1]+new_path[i+1..new_path.size]
|
303
|
-
error_not_found = try_path(next_path)
|
304
|
-
if !error_not_found then
|
305
|
-
new_path = next_path
|
306
|
-
else
|
307
|
-
i = i + 1
|
308
|
-
end
|
309
|
-
else
|
310
|
-
i = i + 1
|
311
|
-
end
|
312
|
-
end
|
313
|
-
return new_path
|
314
|
-
end
|
315
|
-
|
316
|
-
def delete_links_half_way(new_path, indx, user)
|
317
|
-
next_path = []
|
318
|
-
index = 0
|
319
|
-
id = 0
|
320
|
-
first_path = []
|
321
|
-
middle_path = []
|
322
|
-
while id <= user && index < new_path.size do
|
323
|
-
if new_path[index].class == String then
|
324
|
-
id = id + 1
|
325
|
-
if id < user || new_path[index + 1].class == String then
|
326
|
-
if new_path[index + 1].class == String then
|
327
|
-
id = id - 1
|
328
|
-
end
|
329
|
-
first_path << new_path[index]
|
330
|
-
index = index + 1
|
331
|
-
else
|
332
|
-
if id == user then
|
333
|
-
middle_path << new_path[index]
|
334
|
-
index = index + 1
|
335
|
-
end
|
336
|
-
end
|
337
|
-
elsif id < user then
|
338
|
-
first_path << new_path[index]
|
339
|
-
index = index + 1
|
340
|
-
else
|
341
|
-
middle_path << new_path[index]
|
342
|
-
index = index + 1
|
343
|
-
end
|
344
|
-
end
|
345
|
-
if indx == nil then
|
346
|
-
tmp = middle_path[0..middle_path.size/2]
|
347
|
-
else
|
348
|
-
tmp = middle_path[0..indx]
|
349
|
-
end
|
350
|
-
middle_path = tmp
|
351
|
-
last_path = []
|
352
|
-
for i in index..new_path.size-1 do
|
353
|
-
last_path << new_path[i]
|
354
|
-
end
|
355
|
-
next_path = first_path + middle_path + last_path
|
356
|
-
return [next_path, middle_path.size]
|
357
|
-
end
|
358
|
-
|
359
|
-
def replace_same_users!(new_path)
|
360
|
-
users = Array.new(get_sessions_array.size)
|
361
|
-
last_paths = Array.new(get_sessions_array.size)
|
362
|
-
i = 0
|
363
|
-
while i < new_path.size do
|
364
|
-
if new_path[i].class == String then
|
365
|
-
session = new_path[i].split(":").first.to_i
|
366
|
-
if users[session] == new_path[i] then
|
367
|
-
hash = Hash.new
|
368
|
-
hash[last_paths[new_path[i].split(":").first.to_i]] = AutoTest::Authentication.get_logout_path
|
369
|
-
new_path[i] = hash
|
370
|
-
else
|
371
|
-
users[session] = new_path[i]
|
372
|
-
end
|
373
|
-
else
|
374
|
-
last_paths[new_path[i].keys[0].split(":").first.to_i] = new_path[i]
|
375
|
-
end
|
376
|
-
i = i + 1
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
193
|
+
# try the reduced path
|
380
194
|
def try_path(path_to_try)
|
195
|
+
# clean db
|
381
196
|
clean_and_seed_db
|
382
197
|
lno = 0
|
198
|
+
# reinitialize all variables and sessions
|
383
199
|
init_sessions
|
384
200
|
init_sessions_array
|
385
201
|
number_of_sessions = AutoTest::Test.get_number_of_sessions
|
@@ -398,6 +214,7 @@ def try_path(path_to_try)
|
|
398
214
|
while lno < path_to_try.size do
|
399
215
|
hash = Hash.new
|
400
216
|
line = path_to_try[lno]
|
217
|
+
# parse the line from the path
|
401
218
|
if line.class == String then
|
402
219
|
session = get_sessions_array[line.split(":").first.to_i]
|
403
220
|
else
|
@@ -407,7 +224,8 @@ def try_path(path_to_try)
|
|
407
224
|
session_index = get_sessions_array.index(session)
|
408
225
|
lno = lno + 1
|
409
226
|
if line.class == Hash then
|
410
|
-
|
227
|
+
# login
|
228
|
+
if line.values[0] == AutoTest::Authentication.get_login_button then
|
411
229
|
session.visit AutoTest::Authentication.get_login_path
|
412
230
|
hash["#{session_index}:#{session.current_path}"] = AutoTest::Authentication.get_login_button
|
413
231
|
if AutoTest::Authentication.use_db_users then
|
@@ -428,9 +246,11 @@ def try_path(path_to_try)
|
|
428
246
|
end
|
429
247
|
end
|
430
248
|
session.click_button AutoTest::Authentication.get_login_button
|
249
|
+
# logout
|
431
250
|
elsif line.values[0] == AutoTest::Authentication.get_logout_path then
|
432
251
|
hash["#{session_index}:#{session.current_path}"] = AutoTest::Authentication.get_logout_path
|
433
252
|
session.visit AutoTest::Authentication.get_logout_path
|
253
|
+
# fill in forms
|
434
254
|
elsif line.values[0].class == Array then
|
435
255
|
inputs = line.values[0]
|
436
256
|
if !session.all('input').empty? then
|
@@ -457,6 +277,7 @@ def try_path(path_to_try)
|
|
457
277
|
if session.current_path.delete("1-9") != session_path.delete("1-9") then
|
458
278
|
session.visit session_path
|
459
279
|
end
|
280
|
+
# find the right link
|
460
281
|
link = line.values[0].split(/\+\+\+/)
|
461
282
|
href = link[0].to_s
|
462
283
|
text = link[1]
|
@@ -467,6 +288,9 @@ def try_path(path_to_try)
|
|
467
288
|
links = session.all('a').select{ |l| (l[:href].to_s.delete("0-9") == href.delete("0-9")) && l.text == text}
|
468
289
|
links_selected = links + []
|
469
290
|
j = 1
|
291
|
+
# compare the href of the link to the ones before, to find the right one
|
292
|
+
# if the id was equal to teh last id before, it also has to be equal in the new link
|
293
|
+
# if it was different, it has to be different now as well
|
470
294
|
compare_string = ""
|
471
295
|
new_split = session_paths[session_index].split("/")
|
472
296
|
old_split = old_session_paths[session_index].split("/")
|
@@ -500,6 +324,7 @@ def try_path(path_to_try)
|
|
500
324
|
end
|
501
325
|
end
|
502
326
|
end
|
327
|
+
# check if links were found
|
503
328
|
if links.size > 0 then
|
504
329
|
if links_selected.size > 0 then
|
505
330
|
link = links_selected[session_index % links_selected.size]
|
@@ -509,7 +334,9 @@ def try_path(path_to_try)
|
|
509
334
|
old_session_paths[session_index] = href
|
510
335
|
session_paths[session_index] = link[:href].to_s
|
511
336
|
hash["#{session_index}:#{path}"] = "#{link[:href]}+++#{link.text}"
|
337
|
+
# click the link
|
512
338
|
link.click
|
339
|
+
# if the link was still completely different from the original, visit the desired page
|
513
340
|
next_path = session.current_path.delete("0-9")
|
514
341
|
if next_path != root then
|
515
342
|
session.visit path
|
@@ -518,6 +345,7 @@ def try_path(path_to_try)
|
|
518
345
|
hash = path_to_try[lno - 1]
|
519
346
|
end
|
520
347
|
end
|
348
|
+
# update the line in the path
|
521
349
|
path_to_try[lno-1].replace(hash)
|
522
350
|
else
|
523
351
|
# if there´s no authorization, no Strings will be saved in the path
|
@@ -528,6 +356,8 @@ def try_path(path_to_try)
|
|
528
356
|
rescue
|
529
357
|
index = lno + 1
|
530
358
|
root_path = ""
|
359
|
+
# find the right user to continue
|
360
|
+
# the next path has to be correct, so login users and check the next path
|
531
361
|
while root_path == "" && index < path_to_try.size do
|
532
362
|
if path_to_try[index].class != String then
|
533
363
|
if path_to_try[index].keys[0].split(":").first.to_i == session_index then
|
@@ -553,21 +383,234 @@ def try_path(path_to_try)
|
|
553
383
|
end
|
554
384
|
end
|
555
385
|
rescue => e
|
386
|
+
# check for the right error message
|
556
387
|
if err_message == e.message.to_s.split(/:/,2).first then
|
557
|
-
#puts "Found Error again, go on..."
|
558
388
|
error_not_found = false
|
559
389
|
else
|
560
|
-
f = File.new("#{Rails.root}/log/debugging.log", "w")
|
561
|
-
f.puts path_to_try
|
562
|
-
f.close
|
563
390
|
error_not_found = true
|
564
391
|
end
|
565
392
|
return error_not_found
|
566
|
-
|
567
393
|
end
|
568
394
|
return error_not_found
|
569
395
|
end
|
570
396
|
|
397
|
+
|
398
|
+
# delete the ids that are redundant
|
399
|
+
def delete_ids(new_path)
|
400
|
+
for i in 0..get_sessions_array.size - 1 do
|
401
|
+
found_session = false
|
402
|
+
index_to_delete = nil
|
403
|
+
# check if session ids are used in any action
|
404
|
+
new_path.each_with_index do |n, index|
|
405
|
+
if n.class == String && n.to_i == i then
|
406
|
+
index_to_delete = index
|
407
|
+
if !found_session && index_to_delete != index then
|
408
|
+
new_path.delete_at(index_to_delete)
|
409
|
+
end
|
410
|
+
found_session = false
|
411
|
+
else
|
412
|
+
if (n.class != String && n.keys[0].split(":").first.to_i == i) then
|
413
|
+
found_session = true
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
417
|
+
if !found_session then
|
418
|
+
new_path.delete_at(index_to_delete)
|
419
|
+
end
|
420
|
+
found_session = false
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
# delete groups of actions from the path
|
425
|
+
def delete_groups(new_path)
|
426
|
+
for i in 0..get_sessions_array.size - 1 do
|
427
|
+
no_of_group = 1
|
428
|
+
no_of_groups = 1
|
429
|
+
tmp = []
|
430
|
+
while no_of_group <= no_of_groups do
|
431
|
+
count = 0
|
432
|
+
no_of_groups = 0
|
433
|
+
next_path = []
|
434
|
+
new_path.each_with_index do |n,ind|
|
435
|
+
# find the right group to be deleted
|
436
|
+
if n.class != String then
|
437
|
+
if n.keys[0].split(":").second == AutoTest::Authentication.get_login_path && n.keys[0].split(":").first.to_i == i then
|
438
|
+
count = count + 1
|
439
|
+
end
|
440
|
+
if !(n.keys[0].split(":").first.to_i == i && count == no_of_group) then
|
441
|
+
next_path << n
|
442
|
+
else
|
443
|
+
tmp << n
|
444
|
+
end
|
445
|
+
else
|
446
|
+
next_path << n
|
447
|
+
end
|
448
|
+
end
|
449
|
+
# try the reduced path
|
450
|
+
error_not_found = try_path(next_path)
|
451
|
+
# if error was found, continue with reduced path and the same group number, otherwise
|
452
|
+
# continue with same path and incremented group number
|
453
|
+
if error_not_found && tmp != [] then
|
454
|
+
no_of_group = no_of_group + 1
|
455
|
+
else
|
456
|
+
new_path = next_path
|
457
|
+
end
|
458
|
+
# recount no of groups
|
459
|
+
new_path.each do |n|
|
460
|
+
if n.class != String && n.keys[0].split(":").first.to_i == i && n.values[0] == AutoTest::Authentication.get_logout_path then
|
461
|
+
no_of_groups = no_of_groups + 1
|
462
|
+
end
|
463
|
+
end
|
464
|
+
tmp = []
|
465
|
+
end
|
466
|
+
end
|
467
|
+
return new_path
|
468
|
+
puts new_path
|
469
|
+
end
|
470
|
+
|
471
|
+
# delete single links
|
472
|
+
def delete_single_links(new_path)
|
473
|
+
i = 0
|
474
|
+
while i < new_path.size do
|
475
|
+
# just delete actions other than login, logout or User id
|
476
|
+
if (new_path[i].class != String &&
|
477
|
+
!(new_path[i].values.include? AutoTest::Authentication.get_logout_path) &&
|
478
|
+
!(new_path[i].keys[0].include? AutoTest::Authentication.get_login_path)) then
|
479
|
+
next_path = new_path[0..i-1]+new_path[i+1..new_path.size]
|
480
|
+
# try the new path
|
481
|
+
error_not_found = try_path(next_path)
|
482
|
+
# if error was found, continue with reduced path, otherwise, with the same path
|
483
|
+
if !error_not_found then
|
484
|
+
new_path = next_path
|
485
|
+
else
|
486
|
+
i = i + 1
|
487
|
+
end
|
488
|
+
else
|
489
|
+
i = i + 1
|
490
|
+
end
|
491
|
+
end
|
492
|
+
return new_path
|
493
|
+
end
|
494
|
+
|
495
|
+
# delete links half way between to User Ids or add one action
|
496
|
+
def delete_links_half_way(new_path, indx, user)
|
497
|
+
next_path = []
|
498
|
+
index = 0
|
499
|
+
id = 0
|
500
|
+
first_path = []
|
501
|
+
middle_path = []
|
502
|
+
# find the right part of the path to process
|
503
|
+
while id <= user && index < new_path.size do
|
504
|
+
if new_path[index].class == String then
|
505
|
+
id = id + 1
|
506
|
+
if id < user || new_path[index + 1].class == String then
|
507
|
+
if new_path[index + 1].class == String then
|
508
|
+
id = id - 1
|
509
|
+
end
|
510
|
+
# get the first part of the path, that has to stay the same
|
511
|
+
first_path << new_path[index]
|
512
|
+
index = index + 1
|
513
|
+
else
|
514
|
+
# get the path to be reduced or added an action to
|
515
|
+
if id == user then
|
516
|
+
middle_path << new_path[index]
|
517
|
+
index = index + 1
|
518
|
+
end
|
519
|
+
end
|
520
|
+
elsif id < user then
|
521
|
+
first_path << new_path[index]
|
522
|
+
index = index + 1
|
523
|
+
else
|
524
|
+
middle_path << new_path[index]
|
525
|
+
index = index + 1
|
526
|
+
end
|
527
|
+
end
|
528
|
+
# check, if the path should be reduced or an action should be concatenated
|
529
|
+
if indx == nil then
|
530
|
+
tmp = middle_path[0..middle_path.size/2]
|
531
|
+
else
|
532
|
+
tmp = middle_path[0..indx]
|
533
|
+
end
|
534
|
+
middle_path = tmp
|
535
|
+
last_path = []
|
536
|
+
# get the rest of the path
|
537
|
+
for i in index..new_path.size-1 do
|
538
|
+
last_path << new_path[i]
|
539
|
+
end
|
540
|
+
# conc the reduced path with the rest of the path, that hasn´t been reduced
|
541
|
+
next_path = first_path + middle_path + last_path
|
542
|
+
return [next_path, middle_path.size]
|
543
|
+
end
|
544
|
+
|
545
|
+
# replace the Strings in the path with a logout action, that are equal to the last User ID
|
546
|
+
def replace_same_users!(new_path)
|
547
|
+
users = Array.new(get_sessions_array.size)
|
548
|
+
last_paths = Array.new(get_sessions_array.size)
|
549
|
+
i = 0
|
550
|
+
while i < new_path.size do
|
551
|
+
if new_path[i].class == String then
|
552
|
+
session = new_path[i].split(":").first.to_i
|
553
|
+
if users[session] == new_path[i] then
|
554
|
+
hash = Hash.new
|
555
|
+
hash[last_paths[new_path[i].split(":").first.to_i]] = AutoTest::Authentication.get_logout_path
|
556
|
+
new_path[i] = hash
|
557
|
+
else
|
558
|
+
users[session] = new_path[i]
|
559
|
+
end
|
560
|
+
else
|
561
|
+
last_paths[new_path[i].keys[0].split(":").first.to_i] = new_path[i]
|
562
|
+
end
|
563
|
+
i = i + 1
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
# create a new path that starts with the last user of the old path that produced
|
568
|
+
# the error
|
569
|
+
def jump_to_last_user(old_path)
|
570
|
+
# session of the last link that leads to the error
|
571
|
+
last_session = old_path[old_path.size-1].keys[0].split(":").first.to_i
|
572
|
+
new_path = []
|
573
|
+
tmp = []
|
574
|
+
old_path.each do |e|
|
575
|
+
# search the last user of the last session
|
576
|
+
if (e.class == String) && (e.end_with? "ID") && (e.to_i == last_session) then
|
577
|
+
tmp = []
|
578
|
+
tmp << e
|
579
|
+
end
|
580
|
+
if (e.class != String) then
|
581
|
+
tmp << e
|
582
|
+
end
|
583
|
+
end
|
584
|
+
new_path = tmp
|
585
|
+
return new_path
|
586
|
+
end
|
587
|
+
|
588
|
+
# depending on enlarging_counter add another part to the path
|
589
|
+
def enlarge_path(path_to_enlarge)
|
590
|
+
if enlarging_counter < max_enlarging_counter(path_to_enlarge)-1 then
|
591
|
+
inc_enlarging_counter
|
592
|
+
else
|
593
|
+
return path_to_enlarge
|
594
|
+
end
|
595
|
+
last_path = jump_to_last_user(path_to_enlarge)
|
596
|
+
additional_path = []
|
597
|
+
id_count = 0
|
598
|
+
index = 0
|
599
|
+
# add line by line until the next user is found
|
600
|
+
while id_count < enlarging_counter do
|
601
|
+
additional_path << path_to_enlarge[index]
|
602
|
+
index = index + 1
|
603
|
+
if path_to_enlarge[index].class == String && (path_to_enlarge[index].end_with? "ID") then
|
604
|
+
id_count = id_count + 1
|
605
|
+
end
|
606
|
+
end
|
607
|
+
return additional_path + last_path
|
608
|
+
end
|
609
|
+
|
610
|
+
###########################################
|
611
|
+
## helpers
|
612
|
+
|
613
|
+
# find the next path for the specified session
|
571
614
|
def find_next_path(session, path_to_try, lno)
|
572
615
|
root = ""
|
573
616
|
stop = false
|
@@ -584,6 +627,7 @@ def find_next_path(session, path_to_try, lno)
|
|
584
627
|
return root
|
585
628
|
end
|
586
629
|
|
630
|
+
# find next user, that fits the path
|
587
631
|
def find_next_user(root_path, session)
|
588
632
|
index = 0
|
589
633
|
u = 0
|
@@ -591,11 +635,13 @@ def find_next_user(root_path, session)
|
|
591
635
|
while u < user_size do
|
592
636
|
user = AutoTest::Authentication.user_class.find(:first, :conditions => "id > #{index}")
|
593
637
|
index = user.id
|
638
|
+
# login the user
|
594
639
|
session.visit AutoTest::Authentication.get_login_path
|
595
640
|
AutoTest::Authentication.get_login_attributes.each do |la|
|
596
641
|
session.fill_in la[1], :with => user.send(la[0].to_sym)
|
597
642
|
end
|
598
643
|
session.click_button AutoTest::Authentication.get_login_button
|
644
|
+
# check if the path is the right one
|
599
645
|
if session.current_path == root_path then
|
600
646
|
return user
|
601
647
|
end
|
@@ -604,18 +650,17 @@ def find_next_user(root_path, session)
|
|
604
650
|
return false
|
605
651
|
end
|
606
652
|
|
653
|
+
# get the counter
|
607
654
|
def enlarging_counter
|
608
655
|
@counter
|
609
656
|
end
|
610
657
|
|
658
|
+
# increment the counter
|
611
659
|
def inc_enlarging_counter
|
612
660
|
@counter = @counter + 1
|
613
661
|
end
|
614
662
|
|
615
|
-
|
616
|
-
@counter = 0
|
617
|
-
end
|
618
|
-
|
663
|
+
# get the number of users
|
619
664
|
def max_enlarging_counter(whole_path)
|
620
665
|
count = 0
|
621
666
|
whole_path.each do |e|
|
@@ -626,50 +671,7 @@ def max_enlarging_counter(whole_path)
|
|
626
671
|
return count
|
627
672
|
end
|
628
673
|
|
629
|
-
#
|
630
|
-
# depending on enlarging_counter add another part to the path
|
631
|
-
def enlarge_path(path_to_enlarge)
|
632
|
-
if enlarging_counter < max_enlarging_counter(path_to_enlarge)-1 then
|
633
|
-
inc_enlarging_counter
|
634
|
-
else
|
635
|
-
return path_to_enlarge
|
636
|
-
end
|
637
|
-
last_path = jump_to_last_user(path_to_enlarge)
|
638
|
-
additional_path = []
|
639
|
-
id_count = 0
|
640
|
-
index = 0
|
641
|
-
while id_count < enlarging_counter do
|
642
|
-
additional_path << path_to_enlarge[index]
|
643
|
-
index = index + 1
|
644
|
-
if path_to_enlarge[index].class == String && (path_to_enlarge[index].end_with? "ID") then
|
645
|
-
id_count = id_count + 1
|
646
|
-
end
|
647
|
-
end
|
648
|
-
return additional_path + last_path
|
649
|
-
end
|
650
|
-
|
651
|
-
# create a new path that starts with the last user of the old path that produced
|
652
|
-
# the error
|
653
|
-
|
654
|
-
def jump_to_last_user(old_path)
|
655
|
-
# session of the last link that leads to the error
|
656
|
-
last_session = old_path[old_path.size-1].keys[0].split(":").first.to_i
|
657
|
-
new_path = []
|
658
|
-
tmp = []
|
659
|
-
old_path.each do |e|
|
660
|
-
# search the last user of the last session
|
661
|
-
if (e.class == String) && (e.end_with? "ID") && (e.to_i == last_session) then
|
662
|
-
tmp = []
|
663
|
-
tmp << e
|
664
|
-
end
|
665
|
-
if (e.class != String) then
|
666
|
-
tmp << e
|
667
|
-
end
|
668
|
-
end
|
669
|
-
new_path = tmp
|
670
|
-
return new_path
|
671
|
-
end
|
672
|
-
|
674
|
+
# count the user ids in the path
|
673
675
|
def user_count(path_to_count)
|
674
676
|
count = 0
|
675
677
|
path_to_count.each do |e|
|
@@ -680,59 +682,72 @@ def user_count(path_to_count)
|
|
680
682
|
return count
|
681
683
|
end
|
682
684
|
|
683
|
-
|
684
|
-
@sessions = Hash.new
|
685
|
-
end
|
686
|
-
|
687
|
-
def init_hash_sessions(key, value)
|
688
|
-
@sessions["#{key}"] = value
|
689
|
-
end
|
690
|
-
|
685
|
+
# set a session variable
|
691
686
|
def sessions(index, key, value)
|
692
687
|
@sessions["#{index}"]["#{key}"] = value
|
693
688
|
end
|
694
689
|
|
690
|
+
# get session
|
695
691
|
def get_sessions(i, key)
|
696
692
|
@sessions["#{i}"]["#{key}"]
|
697
693
|
end
|
698
694
|
|
695
|
+
# get the sessions array
|
699
696
|
def get_sessions_array
|
700
697
|
@sessions_array
|
701
698
|
end
|
702
699
|
|
703
|
-
|
704
|
-
@sessions_array = []
|
705
|
-
end
|
706
|
-
|
700
|
+
# add a sesion
|
707
701
|
def add_to_sessions_array(session)
|
708
702
|
@sessions_array << session
|
709
703
|
end
|
710
704
|
|
705
|
+
# clean the db
|
711
706
|
def clean_and_seed_db
|
712
707
|
DatabaseCleaner.clean
|
713
708
|
DatabaseCleaner.start
|
714
|
-
#load "#{Rails.root}/db/test_seeds.rb"
|
715
709
|
end
|
716
710
|
|
711
|
+
# get the error message
|
712
|
+
def err_message
|
713
|
+
@err_message
|
714
|
+
end
|
715
|
+
|
716
|
+
# get the path
|
717
|
+
def path
|
718
|
+
@path
|
719
|
+
end
|
720
|
+
|
721
|
+
# add a value to the path
|
722
|
+
def add_path(value)
|
723
|
+
@path << value
|
724
|
+
end
|
725
|
+
|
726
|
+
########################################
|
727
|
+
## initializers
|
728
|
+
|
717
729
|
def init_err_file
|
718
730
|
err_file = File.new("#{Rails.root}/log/errors.log", "r")
|
719
731
|
err_file.gets
|
720
732
|
@err_message = err_file.gets.split(/:/,2).first
|
721
733
|
end
|
722
734
|
|
723
|
-
def
|
724
|
-
@
|
735
|
+
def init_sessions
|
736
|
+
@sessions = Hash.new
|
725
737
|
end
|
726
738
|
|
727
|
-
def
|
728
|
-
@
|
739
|
+
def init_hash_sessions(key, value)
|
740
|
+
@sessions["#{key}"] = value
|
741
|
+
end
|
742
|
+
|
743
|
+
def init_sessions_array
|
744
|
+
@sessions_array = []
|
729
745
|
end
|
730
746
|
|
731
747
|
def init_path
|
732
748
|
@path = []
|
733
749
|
end
|
734
750
|
|
735
|
-
def
|
736
|
-
@
|
751
|
+
def init_enlarging_counter
|
752
|
+
@counter = 0
|
737
753
|
end
|
738
|
-
|