auto_test 0.0.9.5.2 → 0.0.9.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/auto_test/version.rb +1 -1
- data/lib/simulation.rb +1 -1
- data/lib/spec/requests/simulation_spec.rb +171 -3
- metadata +1 -1
data/lib/auto_test/version.rb
CHANGED
data/lib/simulation.rb
CHANGED
@@ -1,10 +1,178 @@
|
|
1
|
+
require "watir-webdriver"
|
2
|
+
|
1
3
|
describe "Application" do
|
2
4
|
describe "auto_test" do
|
3
5
|
it "simulates the error" do
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
|
7
|
+
load "#{Rails.root}/db/test_seeds.rb"
|
8
|
+
init_path
|
9
|
+
init_sessions_array
|
10
|
+
init_user_inputs
|
11
|
+
puts "Firefox is getting started..."
|
12
|
+
paths = File.new("#{Rails.root}/log/new_path.log", "r")
|
13
|
+
home = "localhost:3002"
|
14
|
+
sessions = search_sessions
|
15
|
+
number_of_sessions = sessions.size
|
16
|
+
user = Array.new(user_inputs("get_number_of_sessions").to_i)
|
17
|
+
for i in 0..number_of_sessions-1 do
|
18
|
+
browser = Watir::Browser.new :ff
|
19
|
+
add_to_sessions_array(sessions[i], browser)
|
20
|
+
end
|
21
|
+
while line = paths.gets do
|
22
|
+
if !line.chop!.end_with? "ID" then
|
23
|
+
hash = Hash.new
|
24
|
+
a = line.gsub!(/[{}\"]/,'').split(/\=\>/)
|
25
|
+
session = get_sessions_array[a[0].split(":").first.to_i]
|
26
|
+
session_index = get_sessions_array.index(session)
|
27
|
+
session.windows.first.use
|
28
|
+
if a[0].split(":").second == user_inputs("get_login_path") then
|
29
|
+
session.goto home + user_inputs("get_login_path")
|
30
|
+
hash["#{a[0]}"] = a[1]
|
31
|
+
login(user_inputs("get_login_attributes"), session, user[session_index].class.find(user[session_index].id))
|
32
|
+
elsif a[1] == user_inputs("get_logout_path") then
|
33
|
+
hash["#{a[0]}"] = user_inputs("get_logout_path")
|
34
|
+
session.goto home + user_inputs("get_logout_path")
|
35
|
+
elsif a[1][0] == "[" then
|
36
|
+
texts = []
|
37
|
+
inputs = a[1][1,a[1].size-2].split(/,/)
|
38
|
+
i = 0
|
39
|
+
while i < inputs.size do
|
40
|
+
texts << inputs[i].strip
|
41
|
+
texts << inputs[i+1].strip
|
42
|
+
if inputs[i].strip.start_with? "radio___" then
|
43
|
+
session.radio(:name => inputs[i].gsub("radio___",'').strip,:value=> inputs[i + 1].strip).set
|
44
|
+
elsif inputs[i].strip.start_with? "select___" then
|
45
|
+
session.select_list(:id => inputs[i].gsub("select___",'').strip).select(inputs[i + 1].strip)
|
46
|
+
elsif inputs[i].strip.start_with? "checkbox___" then
|
47
|
+
session.checkbox(:name => inputs[i].gsub("checkbox___",'').strip, :value => inputs[i + 1].strip).set
|
48
|
+
else
|
49
|
+
session.text_field(:name => inputs[i].strip).flash
|
50
|
+
session.text_field(:name => inputs[i].strip).set inputs[i+1].strip
|
51
|
+
end
|
52
|
+
i = i + 2
|
53
|
+
end
|
54
|
+
hash["#{a[0]}"] = texts
|
55
|
+
session.button(:type => "submit").click
|
56
|
+
else
|
57
|
+
link = a[1].split(/\+\+\+/)
|
58
|
+
href = link[0]
|
59
|
+
text = link[1]
|
60
|
+
session.a(:href => href, :text => text).flash
|
61
|
+
session.a(:href => href, :text => text).click
|
62
|
+
begin
|
63
|
+
session.driver.switch_to.alert.accept
|
64
|
+
rescue
|
65
|
+
end
|
66
|
+
hash["#{a[0]}"] = a[1]
|
67
|
+
end
|
68
|
+
add_path(hash)
|
69
|
+
sleep 2
|
70
|
+
else
|
71
|
+
add_path(line)
|
72
|
+
line_parts = line.split(":")
|
73
|
+
session_index = line_parts[0].to_i
|
74
|
+
id = line_parts[1].to_i
|
75
|
+
# get the Constant from the String, to find the right class
|
76
|
+
user[session_index] = Kernel.const_get(user_inputs("user_class")).find(id)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def login(login_attributes, browser, user)
|
84
|
+
if user_inputs("use_db_users") then
|
85
|
+
user_inputs("get_login_attributes").each do |field|
|
86
|
+
browser.text_field(:label => field[1]).set user.send(field[0].to_sym)
|
87
|
+
end
|
88
|
+
sleep 1
|
89
|
+
else
|
90
|
+
index = user_inputs("get_login_names").index(user_inputs("get_unique_login_attribute_name"))
|
91
|
+
user.class.find(:all).each do |u|
|
92
|
+
user_inputs("get_login_data").each do |d|
|
93
|
+
if d[index] == u.send(user_inputs("get_unique_login_attribute_name").to_sym) then
|
94
|
+
user_data = user_inputs("get_login_data")[index]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
user_inputs("get_login_attributes").each_with_index do |field, i|
|
99
|
+
browser.text_field(:label => field[1]).set user_data[i]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
sleep 2
|
103
|
+
browser.button(:type => 'submit').click
|
104
|
+
end
|
105
|
+
|
106
|
+
def init_user_inputs
|
107
|
+
@user_inputs = Hash.new
|
108
|
+
file = File.new("log/user_input.log", "r")
|
109
|
+
while line = file.gets do
|
110
|
+
b = line.split(/:/,2)
|
111
|
+
@user_inputs["#{b[0].strip}"] = b[1].chop
|
112
|
+
end
|
113
|
+
@user_inputs.each do |k,v|
|
114
|
+
if v.start_with? "[" then
|
115
|
+
x = v.split("],[")
|
116
|
+
result = []
|
117
|
+
x.each do |i|
|
118
|
+
result << i.delete("[]\"").split(",")
|
119
|
+
end
|
120
|
+
result.each do |r|
|
121
|
+
if r.class == String then
|
122
|
+
r.strip!
|
123
|
+
else
|
124
|
+
r.each do |s|
|
125
|
+
s.strip!
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
@user_inputs[k] = result
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def user_inputs(key)
|
135
|
+
@user_inputs[key]
|
136
|
+
end
|
137
|
+
|
138
|
+
def get_sessions_array
|
139
|
+
@sessions_array
|
140
|
+
end
|
141
|
+
|
142
|
+
def init_sessions_array
|
143
|
+
@sessions_array = []
|
144
|
+
end
|
145
|
+
|
146
|
+
def add_to_sessions_array(i,session)
|
147
|
+
@sessions_array[i] = session
|
148
|
+
end
|
149
|
+
|
150
|
+
def path
|
151
|
+
@path
|
152
|
+
end
|
153
|
+
|
154
|
+
def init_path
|
155
|
+
@path = []
|
156
|
+
end
|
157
|
+
|
158
|
+
def add_path(value)
|
159
|
+
@path << value
|
160
|
+
end
|
161
|
+
|
162
|
+
def search_sessions
|
163
|
+
path_to_search = File.new("#{gem_path}/../../log/new_path.log")
|
164
|
+
sessions = Array.new
|
165
|
+
while line = path_to_search.gets do
|
166
|
+
line.gsub!(/[{}\"]/,'')
|
167
|
+
if line.class == String then
|
168
|
+
session = line.split(":").first.to_i
|
169
|
+
else
|
170
|
+
session = line.gsub!(/[{}\"]/,'').split(":").first.to_i
|
171
|
+
end
|
172
|
+
if !(sessions.include? session) then
|
173
|
+
sessions << session
|
7
174
|
end
|
8
175
|
end
|
176
|
+
return sessions
|
9
177
|
end
|
10
178
|
|