selenium-framework 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/copyfiles/Gemfile +10 -10
- data/bin/copyfiles/include.rb +12 -12
- data/bin/copyfiles/project_file.rb +24 -24
- data/bin/framework +297 -297
- data/lib/modules/login/login.rb +13 -13
- data/lib/selenium-framework.rb +10 -10
- data/lib/userextension/user_extension.rb +239 -239
- metadata +42 -21
data/bin/copyfiles/Gemfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
source 'http://gemcutter.org'
|
2
|
-
source 'http://gems.rubyforge.org'
|
3
|
-
source 'http://rubygems.org'
|
4
|
-
gem 'selenium-webdriver'
|
5
|
-
gem 'mail'
|
6
|
-
gem 'faker'
|
7
|
-
gem 'nokogiri'
|
8
|
-
gem 'selenium-client'
|
9
|
-
gem 'headless'
|
10
|
-
|
1
|
+
source 'http://gemcutter.org'
|
2
|
+
source 'http://gems.rubyforge.org'
|
3
|
+
source 'http://rubygems.org'
|
4
|
+
gem 'selenium-webdriver'
|
5
|
+
gem 'mail'
|
6
|
+
gem 'faker'
|
7
|
+
gem 'nokogiri'
|
8
|
+
gem 'selenium-client'
|
9
|
+
gem 'headless'
|
10
|
+
|
data/bin/copyfiles/include.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'selenium-framework'
|
2
|
-
require 'selenium-webdriver'
|
3
|
-
require 'test/unit'
|
4
|
-
require 'date'
|
5
|
-
require 'csv'
|
6
|
-
require 'faker'
|
7
|
-
require 'mail'
|
8
|
-
require 'open-uri'
|
9
|
-
require 'nokogiri'
|
10
|
-
require 'uri'
|
11
|
-
require 'headless'
|
12
|
-
|
1
|
+
require 'selenium-framework'
|
2
|
+
require 'selenium-webdriver'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'date'
|
5
|
+
require 'csv'
|
6
|
+
require 'faker'
|
7
|
+
require 'mail'
|
8
|
+
require 'open-uri'
|
9
|
+
require 'nokogiri'
|
10
|
+
require 'uri'
|
11
|
+
require 'headless'
|
12
|
+
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require './include.rb'
|
2
|
-
|
3
|
-
class Project < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
client = Selenium::WebDriver::Remote::Http::Default.new
|
7
|
-
client.timeout = 120 # seconds
|
8
|
-
$driver = Selenium::WebDriver.for(:remote, :http_client => client, :url => 'http://<IP ADDRESS>:<PORT NUMBER>/wd/hub', :desired_capabilities => ':firefox')
|
9
|
-
$base_url = 'http://<WEBSITE URL>'
|
10
|
-
$driver.manage.timeouts.implicit_wait = 180
|
11
|
-
@verification_errors = []
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
$driver.quit
|
16
|
-
assert_equal [],@verification_errors
|
17
|
-
end
|
18
|
-
|
19
|
-
def verify(&blk)
|
20
|
-
yield
|
21
|
-
rescue Test::Unit::AssertionFailedError => ex
|
22
|
-
@verification_errors << ex
|
23
|
-
end
|
24
|
-
|
1
|
+
require './include.rb'
|
2
|
+
|
3
|
+
class Project < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
client = Selenium::WebDriver::Remote::Http::Default.new
|
7
|
+
client.timeout = 120 # seconds
|
8
|
+
$driver = Selenium::WebDriver.for(:remote, :http_client => client, :url => 'http://<IP ADDRESS>:<PORT NUMBER>/wd/hub', :desired_capabilities => ':firefox')
|
9
|
+
$base_url = 'http://<WEBSITE URL>'
|
10
|
+
$driver.manage.timeouts.implicit_wait = 180
|
11
|
+
@verification_errors = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
$driver.quit
|
16
|
+
assert_equal [],@verification_errors
|
17
|
+
end
|
18
|
+
|
19
|
+
def verify(&blk)
|
20
|
+
yield
|
21
|
+
rescue Test::Unit::AssertionFailedError => ex
|
22
|
+
@verification_errors << ex
|
23
|
+
end
|
24
|
+
|
25
25
|
end
|
data/bin/framework
CHANGED
@@ -1,297 +1,297 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'fileutils'
|
3
|
-
require 'readline'
|
4
|
-
|
5
|
-
|
6
|
-
def print_path(filename, filepath, project_directory_path)
|
7
|
-
path = filepath +"/"+ filename
|
8
|
-
path = path.to_s
|
9
|
-
puts "create " + path.split(project_directory_path.to_s)[1].to_s
|
10
|
-
end
|
11
|
-
|
12
|
-
def create_dir(dirname, directory_path, project_directory_path)
|
13
|
-
Dir.chdir(directory_path)
|
14
|
-
unless (File.exists?(dirname))
|
15
|
-
Dir.mkdir(dirname)
|
16
|
-
print_path(dirname, directory_path, project_directory_path)
|
17
|
-
end
|
18
|
-
Dir.chdir(directory_path + "/" + dirname)
|
19
|
-
unless (File.exists?(".gitignore"))
|
20
|
-
FileUtils.touch ".gitignore"
|
21
|
-
print_path(".gitignore", directory_path + "/" + dirname, project_directory_path)
|
22
|
-
end
|
23
|
-
Dir.chdir(directory_path)
|
24
|
-
end
|
25
|
-
|
26
|
-
def help_text
|
27
|
-
puts "Usage: \n\tframework new <PROJECT_PATH> [options] \n\tframework update <PROJECT_PATH>
|
28
|
-
exit
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
if ARGV[0] == nil || ARGV[1] == nil || (ARGV[0] !='new' && ARGV[0] !='update' ) || ARGV[0] == '-h' || ARGV[0] == '--help'
|
33
|
-
help_text
|
34
|
-
end
|
35
|
-
force_flag = 0
|
36
|
-
if ARGV.length == 3
|
37
|
-
if ARGV[2] == '-f' || ARGV[2] == '--force'
|
38
|
-
exist_flag = 1
|
39
|
-
force_flag = 1
|
40
|
-
else
|
41
|
-
help_text
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
update_flag = 0
|
46
|
-
if ARGV[0] == 'update'
|
47
|
-
if ARGV.length == 2 && ARGV[1] != nil
|
48
|
-
update_flag = 1
|
49
|
-
else
|
50
|
-
help_text
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
project_name = ARGV[1]
|
57
|
-
project_directory_path = Dir.pwd
|
58
|
-
puts "\n"
|
59
|
-
|
60
|
-
exist_flag = 1
|
61
|
-
if ("true".casecmp(File.directory?(project_directory_path +"/"+ project_name).to_s)) == 0 && exist_flag == 1 && force_flag == 0 && update_flag == 0
|
62
|
-
puts "Project exist !!! What do you want to do? \n1. Overwrite the project\n2. Take backup and create new project\n3. Create project in existing directory\n4. Exit :\n\n"
|
63
|
-
exist_flag = Readline.readline(":", true)
|
64
|
-
exist_flag = exist_flag.to_i
|
65
|
-
else
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
if exist_flag == 1 && update_flag == 0
|
71
|
-
if File.exists?(project_name)
|
72
|
-
FileUtils.rm_r(project_name)
|
73
|
-
puts "Deleted the previous project...\n\n"
|
74
|
-
end
|
75
|
-
puts "Creating new project as #{project_name}..."
|
76
|
-
create_dir(project_name, project_directory_path, project_directory_path)
|
77
|
-
Dir.chdir(project_directory_path + "/" + project_name)
|
78
|
-
|
79
|
-
project_main_file = project_name + ".rb"
|
80
|
-
FileUtils.touch project_main_file
|
81
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/project_file.rb"
|
82
|
-
destination = project_directory_path + "/" + project_name + "/" + project_main_file
|
83
|
-
FileUtils.copy_file(source,destination)
|
84
|
-
outdata = File.read(destination).gsub("Project", project_name.capitalize)
|
85
|
-
File.open(destination, 'w') do |out|
|
86
|
-
out << outdata
|
87
|
-
end
|
88
|
-
print_path(project_main_file, project_directory_path + "/" + project_name, project_directory_path)
|
89
|
-
|
90
|
-
FileUtils.touch "include.rb"
|
91
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/include.rb"
|
92
|
-
destination = project_directory_path + "/" + project_name + "/include.rb"
|
93
|
-
FileUtils.copy_file(source,destination)
|
94
|
-
print_path("include.rb", project_directory_path + "/" + project_name, project_directory_path)
|
95
|
-
|
96
|
-
FileUtils.touch "Gemfile"
|
97
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/Gemfile"
|
98
|
-
destination = project_directory_path + "/" + project_name + "/Gemfile"
|
99
|
-
FileUtils.copy_file(source,destination)
|
100
|
-
print_path("Gemfile", project_directory_path + "/" + project_name, project_directory_path)
|
101
|
-
|
102
|
-
Dir.chdir(project_directory_path)
|
103
|
-
# internal_dir -- array for storing framework directory names
|
104
|
-
internal_dir = ["libraries", "testcases", "logs", "reports", "screenshots"]
|
105
|
-
directory_path = project_directory_path + "/" + project_name
|
106
|
-
# dir_counter -- iterator for the loop
|
107
|
-
for dir_counter in 0..internal_dir.length-1
|
108
|
-
create_dir(internal_dir[dir_counter], directory_path, project_directory_path)
|
109
|
-
end
|
110
|
-
puts "\nFramework for #{project_name} is created..."
|
111
|
-
puts "\nbundle install"
|
112
|
-
Dir.chdir(project_directory_path + "/" + project_name)
|
113
|
-
system("bundle install")
|
114
|
-
Dir.chdir(project_directory_path)
|
115
|
-
end
|
116
|
-
|
117
|
-
if exist_flag == 2
|
118
|
-
timestamp = Time.now
|
119
|
-
timestamp = timestamp.strftime("%d-%m-%Y-%H-%M-%S")
|
120
|
-
timestamp = timestamp.to_s
|
121
|
-
old_prject_name = project_name
|
122
|
-
new_project_name = project_name+'_'+timestamp
|
123
|
-
File.rename(old_prject_name, new_project_name)
|
124
|
-
puts "\n#{old_prject_name} HAS BEEN MOVED TO #{new_project_name} \n\n"
|
125
|
-
puts "Creating new project as #{project_name}..."
|
126
|
-
create_dir(project_name, project_directory_path, project_directory_path)
|
127
|
-
Dir.chdir(project_directory_path + "/" + project_name)
|
128
|
-
|
129
|
-
project_main_file = project_name + ".rb"
|
130
|
-
FileUtils.touch project_main_file
|
131
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/project_file.rb"
|
132
|
-
destination = project_directory_path + "/" + project_name + "/" + project_main_file
|
133
|
-
FileUtils.copy_file(source,destination)
|
134
|
-
outdata = File.read(destination).gsub("Project", project_name.capitalize)
|
135
|
-
File.open(destination, 'w') do |out|
|
136
|
-
out << outdata
|
137
|
-
end
|
138
|
-
print_path(project_main_file, project_directory_path + "/" + project_name, project_directory_path)
|
139
|
-
|
140
|
-
FileUtils.touch "include.rb"
|
141
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/include.rb"
|
142
|
-
destination = project_directory_path + "/" + project_name + "/include.rb"
|
143
|
-
FileUtils.copy_file(source,destination)
|
144
|
-
print_path("include.rb", project_directory_path + "/" + project_name, project_directory_path)
|
145
|
-
|
146
|
-
FileUtils.touch "Gemfile"
|
147
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/Gemfile"
|
148
|
-
destination = project_directory_path + "/" + project_name + "/Gemfile"
|
149
|
-
FileUtils.copy_file(source,destination)
|
150
|
-
print_path("Gemfile", project_directory_path + "/" + project_name, project_directory_path)
|
151
|
-
|
152
|
-
Dir.chdir(project_directory_path)
|
153
|
-
# internal_dir -- array for storing framework directory names
|
154
|
-
internal_dir = ["libraries", "testcases", "logs", "reports", "screenshots"]
|
155
|
-
directory_path = project_directory_path + "/" + project_name
|
156
|
-
# dir_counter -- iterator for the loop
|
157
|
-
for dir_counter in 0..internal_dir.length-1
|
158
|
-
create_dir(internal_dir[dir_counter], directory_path, project_directory_path)
|
159
|
-
end
|
160
|
-
puts "\nFramework for #{project_name} is created..."
|
161
|
-
puts "\nbundle install"
|
162
|
-
Dir.chdir(project_directory_path + "/" + project_name)
|
163
|
-
system("bundle install")
|
164
|
-
Dir.chdir(project_directory_path)
|
165
|
-
end
|
166
|
-
|
167
|
-
if exist_flag == 3
|
168
|
-
puts "\nThe framework will be created in existing directory. Do you want to continue? Enter y/yes to continue."
|
169
|
-
confirm_flag = Readline.readline(":", true)
|
170
|
-
confirm_flag = confirm_flag.to_s.upcase
|
171
|
-
if ("Y".casecmp confirm_flag) == 0 || ("YES".casecmp confirm_flag) == 0
|
172
|
-
Dir.chdir(project_directory_path + "/" + project_name)
|
173
|
-
project_main_file = project_name + ".rb"
|
174
|
-
unless (File.exists?(project_main_file))
|
175
|
-
FileUtils.touch project_main_file
|
176
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/project_file.rb"
|
177
|
-
destination = project_directory_path + "/" + project_name + "/" + project_main_file
|
178
|
-
FileUtils.copy_file(source,destination)
|
179
|
-
outdata = File.read(destination).gsub("Project", project_name.capitalize)
|
180
|
-
File.open(destination, 'w') do |out|
|
181
|
-
out << outdata
|
182
|
-
end
|
183
|
-
print_path(project_main_file, project_directory_path + "/" + project_name, project_directory_path)
|
184
|
-
end
|
185
|
-
unless (File.exists?("include.rb"))
|
186
|
-
FileUtils.touch "include.rb"
|
187
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/include.rb"
|
188
|
-
destination = project_directory_path + "/" + project_name + "/include.rb"
|
189
|
-
FileUtils.copy_file(source,destination)
|
190
|
-
print_path("include.rb", project_directory_path + "/" + project_name, project_directory_path)
|
191
|
-
end
|
192
|
-
unless (File.exists?("Gemfile"))
|
193
|
-
FileUtils.touch "Gemfile"
|
194
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/Gemfile"
|
195
|
-
destination = project_directory_path + "/" + project_name + "/Gemfile"
|
196
|
-
FileUtils.copy_file(source,destination)
|
197
|
-
print_path("Gemfile", project_directory_path + "/" + project_name, project_directory_path)
|
198
|
-
end
|
199
|
-
|
200
|
-
Dir.chdir(project_directory_path)
|
201
|
-
# internal_dir -- array for storing framework directory names
|
202
|
-
internal_dir = ["libraries", "testcases", "logs", "reports", "screenshots"]
|
203
|
-
directory_path = project_directory_path + "/" + project_name
|
204
|
-
# dir_counter -- iterator for the loop
|
205
|
-
for dir_counter in 0..internal_dir.length-1
|
206
|
-
create_dir(internal_dir[dir_counter], directory_path, project_directory_path)
|
207
|
-
end
|
208
|
-
puts "\nFramework for #{project_name} is created..."
|
209
|
-
puts "\nbundle install"
|
210
|
-
Dir.chdir(project_directory_path + "/" + project_name)
|
211
|
-
system("bundle install")
|
212
|
-
Dir.chdir(project_directory_path)
|
213
|
-
else
|
214
|
-
puts "Not continuing. Exiting creation of framework..."
|
215
|
-
exit
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
if exist_flag == 4
|
220
|
-
puts "Project exist !!! So exiting..."
|
221
|
-
exit
|
222
|
-
end
|
223
|
-
|
224
|
-
if update_flag ==1
|
225
|
-
unless File.exists?(project_name)
|
226
|
-
puts "\n#{project_name} does not exist in current location...\nSo exiting ..."
|
227
|
-
exit
|
228
|
-
end
|
229
|
-
Dir.chdir(project_directory_path + "/" + project_name)
|
230
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/include.rb"
|
231
|
-
destination = "include.rb"
|
232
|
-
compare_result_1 = FileUtils.compare_file(source, destination).to_s
|
233
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/Gemfile"
|
234
|
-
destination = "Gemfile"
|
235
|
-
compare_result_2 = FileUtils.compare_file(source, destination).to_s
|
236
|
-
|
237
|
-
if ("true".casecmp compare_result_1) == 0 && ("true".casecmp compare_result_2) == 0
|
238
|
-
puts "\nFramework for #{project_name} is already updated..."
|
239
|
-
puts "\nbundle install"
|
240
|
-
Dir.chdir(project_directory_path + "/" + project_name)
|
241
|
-
system("bundle install")
|
242
|
-
Dir.chdir(project_directory_path)
|
243
|
-
exit
|
244
|
-
else
|
245
|
-
puts "\nFramework for #{project_name} needs to be updated..."
|
246
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/include.rb"
|
247
|
-
destination = "include.rb"
|
248
|
-
source_data = Array.new
|
249
|
-
source_data = IO.readlines(source)
|
250
|
-
destination_data = Array.new
|
251
|
-
destination_data = IO.readlines(destination)
|
252
|
-
source_data.each do |thing|
|
253
|
-
present_flag = destination_data.include? thing
|
254
|
-
present_flag = present_flag.to_s
|
255
|
-
if ("false".casecmp present_flag) == 0
|
256
|
-
#File.open(destination, 'a+') { |file| file.write(thing.to_s) }
|
257
|
-
f = File.open(destination, "r+")
|
258
|
-
lines = f.readlines
|
259
|
-
f.close
|
260
|
-
lines = [thing] + lines
|
261
|
-
output = File.new(destination, "w")
|
262
|
-
lines.each { |line| output.write line }
|
263
|
-
output.close
|
264
|
-
end
|
265
|
-
end
|
266
|
-
print_path("include.rb", project_directory_path + "/" + project_name, project_directory_path)
|
267
|
-
|
268
|
-
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/Gemfile"
|
269
|
-
destination = "Gemfile"
|
270
|
-
source_data = Array.new
|
271
|
-
source_data = IO.readlines(source)
|
272
|
-
destination_data = Array.new
|
273
|
-
destination_data = IO.readlines(destination)
|
274
|
-
source_data.each do |thing|
|
275
|
-
present_flag = destination_data.include? thing
|
276
|
-
present_flag = present_flag.to_s
|
277
|
-
if ("false".casecmp present_flag) == 0
|
278
|
-
#File.open(destination, 'a+') { |file| file.write(thing.to_s) }
|
279
|
-
f = File.open(destination, "r+")
|
280
|
-
lines = f.readlines
|
281
|
-
f.close
|
282
|
-
lines = [thing] + lines
|
283
|
-
output = File.new(destination, "w")
|
284
|
-
lines.each { |line| output.write line }
|
285
|
-
output.close
|
286
|
-
end
|
287
|
-
end
|
288
|
-
print_path("Gemfile", project_directory_path + "/" + project_name, project_directory_path)
|
289
|
-
|
290
|
-
puts "\nFramework for #{project_name} is updated..."
|
291
|
-
puts "\nbundle install"
|
292
|
-
Dir.chdir(project_directory_path + "/" + project_name)
|
293
|
-
system("bundle install")
|
294
|
-
Dir.chdir(project_directory_path)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
require 'readline'
|
4
|
+
|
5
|
+
|
6
|
+
def print_path(filename, filepath, project_directory_path)
|
7
|
+
path = filepath +"/"+ filename
|
8
|
+
path = path.to_s
|
9
|
+
puts "create " + path.split(project_directory_path.to_s)[1].to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_dir(dirname, directory_path, project_directory_path)
|
13
|
+
Dir.chdir(directory_path)
|
14
|
+
unless (File.exists?(dirname))
|
15
|
+
Dir.mkdir(dirname)
|
16
|
+
print_path(dirname, directory_path, project_directory_path)
|
17
|
+
end
|
18
|
+
Dir.chdir(directory_path + "/" + dirname)
|
19
|
+
unless (File.exists?(".gitignore"))
|
20
|
+
FileUtils.touch ".gitignore"
|
21
|
+
print_path(".gitignore", directory_path + "/" + dirname, project_directory_path)
|
22
|
+
end
|
23
|
+
Dir.chdir(directory_path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def help_text
|
27
|
+
puts "Usage: \n\tframework new <PROJECT_PATH> [options] \n\tframework update <PROJECT_PATH> \n\nFramework options: \n\t-h, [--help]\t# Show this help message and quit\n\nRuntime options: \n\t-f, [--force]\t# Overwrite files that already exist"
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
if ARGV[0] == nil || ARGV[1] == nil || (ARGV[0] !='new' && ARGV[0] !='update' ) || ARGV[0] == '-h' || ARGV[0] == '--help'
|
33
|
+
help_text
|
34
|
+
end
|
35
|
+
force_flag = 0
|
36
|
+
if ARGV.length == 3
|
37
|
+
if ARGV[2] == '-f' || ARGV[2] == '--force'
|
38
|
+
exist_flag = 1
|
39
|
+
force_flag = 1
|
40
|
+
else
|
41
|
+
help_text
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
update_flag = 0
|
46
|
+
if ARGV[0] == 'update'
|
47
|
+
if ARGV.length == 2 && ARGV[1] != nil
|
48
|
+
update_flag = 1
|
49
|
+
else
|
50
|
+
help_text
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
project_name = ARGV[1]
|
57
|
+
project_directory_path = Dir.pwd
|
58
|
+
puts "\n"
|
59
|
+
|
60
|
+
exist_flag = 1
|
61
|
+
if ("true".casecmp(File.directory?(project_directory_path +"/"+ project_name).to_s)) == 0 && exist_flag == 1 && force_flag == 0 && update_flag == 0
|
62
|
+
puts "Project exist !!! What do you want to do? \n1. Overwrite the project\n2. Take backup and create new project\n3. Create project in existing directory\n4. Exit :\n\n"
|
63
|
+
exist_flag = Readline.readline(":", true)
|
64
|
+
exist_flag = exist_flag.to_i
|
65
|
+
else
|
66
|
+
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
if exist_flag == 1 && update_flag == 0
|
71
|
+
if File.exists?(project_name)
|
72
|
+
FileUtils.rm_r(project_name)
|
73
|
+
puts "Deleted the previous project...\n\n"
|
74
|
+
end
|
75
|
+
puts "Creating new project as #{project_name}..."
|
76
|
+
create_dir(project_name, project_directory_path, project_directory_path)
|
77
|
+
Dir.chdir(project_directory_path + "/" + project_name)
|
78
|
+
|
79
|
+
project_main_file = project_name + ".rb"
|
80
|
+
FileUtils.touch project_main_file
|
81
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/project_file.rb"
|
82
|
+
destination = project_directory_path + "/" + project_name + "/" + project_main_file
|
83
|
+
FileUtils.copy_file(source,destination)
|
84
|
+
outdata = File.read(destination).gsub("Project", project_name.capitalize)
|
85
|
+
File.open(destination, 'w') do |out|
|
86
|
+
out << outdata
|
87
|
+
end
|
88
|
+
print_path(project_main_file, project_directory_path + "/" + project_name, project_directory_path)
|
89
|
+
|
90
|
+
FileUtils.touch "include.rb"
|
91
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/include.rb"
|
92
|
+
destination = project_directory_path + "/" + project_name + "/include.rb"
|
93
|
+
FileUtils.copy_file(source,destination)
|
94
|
+
print_path("include.rb", project_directory_path + "/" + project_name, project_directory_path)
|
95
|
+
|
96
|
+
FileUtils.touch "Gemfile"
|
97
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/Gemfile"
|
98
|
+
destination = project_directory_path + "/" + project_name + "/Gemfile"
|
99
|
+
FileUtils.copy_file(source,destination)
|
100
|
+
print_path("Gemfile", project_directory_path + "/" + project_name, project_directory_path)
|
101
|
+
|
102
|
+
Dir.chdir(project_directory_path)
|
103
|
+
# internal_dir -- array for storing framework directory names
|
104
|
+
internal_dir = ["libraries", "testcases", "logs", "reports", "screenshots"]
|
105
|
+
directory_path = project_directory_path + "/" + project_name
|
106
|
+
# dir_counter -- iterator for the loop
|
107
|
+
for dir_counter in 0..internal_dir.length-1
|
108
|
+
create_dir(internal_dir[dir_counter], directory_path, project_directory_path)
|
109
|
+
end
|
110
|
+
puts "\nFramework for #{project_name} is created..."
|
111
|
+
puts "\nbundle install"
|
112
|
+
Dir.chdir(project_directory_path + "/" + project_name)
|
113
|
+
system("bundle install")
|
114
|
+
Dir.chdir(project_directory_path)
|
115
|
+
end
|
116
|
+
|
117
|
+
if exist_flag == 2
|
118
|
+
timestamp = Time.now
|
119
|
+
timestamp = timestamp.strftime("%d-%m-%Y-%H-%M-%S")
|
120
|
+
timestamp = timestamp.to_s
|
121
|
+
old_prject_name = project_name
|
122
|
+
new_project_name = project_name+'_'+timestamp
|
123
|
+
File.rename(old_prject_name, new_project_name)
|
124
|
+
puts "\n#{old_prject_name} HAS BEEN MOVED TO #{new_project_name} \n\n"
|
125
|
+
puts "Creating new project as #{project_name}..."
|
126
|
+
create_dir(project_name, project_directory_path, project_directory_path)
|
127
|
+
Dir.chdir(project_directory_path + "/" + project_name)
|
128
|
+
|
129
|
+
project_main_file = project_name + ".rb"
|
130
|
+
FileUtils.touch project_main_file
|
131
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/project_file.rb"
|
132
|
+
destination = project_directory_path + "/" + project_name + "/" + project_main_file
|
133
|
+
FileUtils.copy_file(source,destination)
|
134
|
+
outdata = File.read(destination).gsub("Project", project_name.capitalize)
|
135
|
+
File.open(destination, 'w') do |out|
|
136
|
+
out << outdata
|
137
|
+
end
|
138
|
+
print_path(project_main_file, project_directory_path + "/" + project_name, project_directory_path)
|
139
|
+
|
140
|
+
FileUtils.touch "include.rb"
|
141
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/include.rb"
|
142
|
+
destination = project_directory_path + "/" + project_name + "/include.rb"
|
143
|
+
FileUtils.copy_file(source,destination)
|
144
|
+
print_path("include.rb", project_directory_path + "/" + project_name, project_directory_path)
|
145
|
+
|
146
|
+
FileUtils.touch "Gemfile"
|
147
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/Gemfile"
|
148
|
+
destination = project_directory_path + "/" + project_name + "/Gemfile"
|
149
|
+
FileUtils.copy_file(source,destination)
|
150
|
+
print_path("Gemfile", project_directory_path + "/" + project_name, project_directory_path)
|
151
|
+
|
152
|
+
Dir.chdir(project_directory_path)
|
153
|
+
# internal_dir -- array for storing framework directory names
|
154
|
+
internal_dir = ["libraries", "testcases", "logs", "reports", "screenshots"]
|
155
|
+
directory_path = project_directory_path + "/" + project_name
|
156
|
+
# dir_counter -- iterator for the loop
|
157
|
+
for dir_counter in 0..internal_dir.length-1
|
158
|
+
create_dir(internal_dir[dir_counter], directory_path, project_directory_path)
|
159
|
+
end
|
160
|
+
puts "\nFramework for #{project_name} is created..."
|
161
|
+
puts "\nbundle install"
|
162
|
+
Dir.chdir(project_directory_path + "/" + project_name)
|
163
|
+
system("bundle install")
|
164
|
+
Dir.chdir(project_directory_path)
|
165
|
+
end
|
166
|
+
|
167
|
+
if exist_flag == 3
|
168
|
+
puts "\nThe framework will be created in existing directory. Do you want to continue? Enter y/yes to continue."
|
169
|
+
confirm_flag = Readline.readline(":", true)
|
170
|
+
confirm_flag = confirm_flag.to_s.upcase
|
171
|
+
if ("Y".casecmp confirm_flag) == 0 || ("YES".casecmp confirm_flag) == 0
|
172
|
+
Dir.chdir(project_directory_path + "/" + project_name)
|
173
|
+
project_main_file = project_name + ".rb"
|
174
|
+
unless (File.exists?(project_main_file))
|
175
|
+
FileUtils.touch project_main_file
|
176
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/project_file.rb"
|
177
|
+
destination = project_directory_path + "/" + project_name + "/" + project_main_file
|
178
|
+
FileUtils.copy_file(source,destination)
|
179
|
+
outdata = File.read(destination).gsub("Project", project_name.capitalize)
|
180
|
+
File.open(destination, 'w') do |out|
|
181
|
+
out << outdata
|
182
|
+
end
|
183
|
+
print_path(project_main_file, project_directory_path + "/" + project_name, project_directory_path)
|
184
|
+
end
|
185
|
+
unless (File.exists?("include.rb"))
|
186
|
+
FileUtils.touch "include.rb"
|
187
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/include.rb"
|
188
|
+
destination = project_directory_path + "/" + project_name + "/include.rb"
|
189
|
+
FileUtils.copy_file(source,destination)
|
190
|
+
print_path("include.rb", project_directory_path + "/" + project_name, project_directory_path)
|
191
|
+
end
|
192
|
+
unless (File.exists?("Gemfile"))
|
193
|
+
FileUtils.touch "Gemfile"
|
194
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/Gemfile"
|
195
|
+
destination = project_directory_path + "/" + project_name + "/Gemfile"
|
196
|
+
FileUtils.copy_file(source,destination)
|
197
|
+
print_path("Gemfile", project_directory_path + "/" + project_name, project_directory_path)
|
198
|
+
end
|
199
|
+
|
200
|
+
Dir.chdir(project_directory_path)
|
201
|
+
# internal_dir -- array for storing framework directory names
|
202
|
+
internal_dir = ["libraries", "testcases", "logs", "reports", "screenshots"]
|
203
|
+
directory_path = project_directory_path + "/" + project_name
|
204
|
+
# dir_counter -- iterator for the loop
|
205
|
+
for dir_counter in 0..internal_dir.length-1
|
206
|
+
create_dir(internal_dir[dir_counter], directory_path, project_directory_path)
|
207
|
+
end
|
208
|
+
puts "\nFramework for #{project_name} is created..."
|
209
|
+
puts "\nbundle install"
|
210
|
+
Dir.chdir(project_directory_path + "/" + project_name)
|
211
|
+
system("bundle install")
|
212
|
+
Dir.chdir(project_directory_path)
|
213
|
+
else
|
214
|
+
puts "Not continuing. Exiting creation of framework..."
|
215
|
+
exit
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
if exist_flag == 4
|
220
|
+
puts "Project exist !!! So exiting..."
|
221
|
+
exit
|
222
|
+
end
|
223
|
+
|
224
|
+
if update_flag ==1
|
225
|
+
unless File.exists?(project_name)
|
226
|
+
puts "\n#{project_name} does not exist in current location...\nSo exiting ..."
|
227
|
+
exit
|
228
|
+
end
|
229
|
+
Dir.chdir(project_directory_path + "/" + project_name)
|
230
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/include.rb"
|
231
|
+
destination = "include.rb"
|
232
|
+
compare_result_1 = FileUtils.compare_file(source, destination).to_s
|
233
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/Gemfile"
|
234
|
+
destination = "Gemfile"
|
235
|
+
compare_result_2 = FileUtils.compare_file(source, destination).to_s
|
236
|
+
|
237
|
+
if ("true".casecmp compare_result_1) == 0 && ("true".casecmp compare_result_2) == 0
|
238
|
+
puts "\nFramework for #{project_name} is already updated..."
|
239
|
+
puts "\nbundle install"
|
240
|
+
Dir.chdir(project_directory_path + "/" + project_name)
|
241
|
+
system("bundle install")
|
242
|
+
Dir.chdir(project_directory_path)
|
243
|
+
exit
|
244
|
+
else
|
245
|
+
puts "\nFramework for #{project_name} needs to be updated..."
|
246
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/include.rb"
|
247
|
+
destination = "include.rb"
|
248
|
+
source_data = Array.new
|
249
|
+
source_data = IO.readlines(source)
|
250
|
+
destination_data = Array.new
|
251
|
+
destination_data = IO.readlines(destination)
|
252
|
+
source_data.each do |thing|
|
253
|
+
present_flag = destination_data.include? thing
|
254
|
+
present_flag = present_flag.to_s
|
255
|
+
if ("false".casecmp present_flag) == 0
|
256
|
+
#File.open(destination, 'a+') { |file| file.write(thing.to_s) }
|
257
|
+
f = File.open(destination, "r+")
|
258
|
+
lines = f.readlines
|
259
|
+
f.close
|
260
|
+
lines = [thing] + lines
|
261
|
+
output = File.new(destination, "w")
|
262
|
+
lines.each { |line| output.write line }
|
263
|
+
output.close
|
264
|
+
end
|
265
|
+
end
|
266
|
+
print_path("include.rb", project_directory_path + "/" + project_name, project_directory_path)
|
267
|
+
|
268
|
+
source = File.expand_path File.dirname(__FILE__).to_s + "/copyfiles/Gemfile"
|
269
|
+
destination = "Gemfile"
|
270
|
+
source_data = Array.new
|
271
|
+
source_data = IO.readlines(source)
|
272
|
+
destination_data = Array.new
|
273
|
+
destination_data = IO.readlines(destination)
|
274
|
+
source_data.each do |thing|
|
275
|
+
present_flag = destination_data.include? thing
|
276
|
+
present_flag = present_flag.to_s
|
277
|
+
if ("false".casecmp present_flag) == 0
|
278
|
+
#File.open(destination, 'a+') { |file| file.write(thing.to_s) }
|
279
|
+
f = File.open(destination, "r+")
|
280
|
+
lines = f.readlines
|
281
|
+
f.close
|
282
|
+
lines = [thing] + lines
|
283
|
+
output = File.new(destination, "w")
|
284
|
+
lines.each { |line| output.write line }
|
285
|
+
output.close
|
286
|
+
end
|
287
|
+
end
|
288
|
+
print_path("Gemfile", project_directory_path + "/" + project_name, project_directory_path)
|
289
|
+
|
290
|
+
puts "\nFramework for #{project_name} is updated..."
|
291
|
+
puts "\nbundle install"
|
292
|
+
Dir.chdir(project_directory_path + "/" + project_name)
|
293
|
+
system("bundle install")
|
294
|
+
Dir.chdir(project_directory_path)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|