coba-testrunner 0.0.5 → 0.0.6

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/coba +91 -58
  3. data/lib/coba-testrunner.rb +19 -12
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec92c9d4f0c5810ce0e37c55a4bfd69a1768385e
4
- data.tar.gz: e6e1532fad6a7d4a3139ee0d654180da7bffcad9
3
+ metadata.gz: 78dd2ec1b34ab6104b72010d6f09124b95889fc1
4
+ data.tar.gz: e71a2cb25c431cf6d56a5c4cc6ae81465ebc721e
5
5
  SHA512:
6
- metadata.gz: 993b13e0968fe120778f45c9ef58a07bbb9e587643f2d198bd67bca712eaf0956898f499af44913873b571f0a4b1c4d8d476079b764bb862c533e17c6e44e605
7
- data.tar.gz: 1d1f0310a19f23755676ba1a14f016bc826045d3df4aa1056d07b922e1dd417cbca1fc01b7625c7e0a966ed7b5f1cf8e6569acb03098afacffa474003292bdd6
6
+ metadata.gz: d95cb3e9715587e1d190ae71343814b00084099af0123eb5f3fd2423742f1310fc3c1dbc665bc74262cd472a00e0b92f03398e0f53b245c342037d482e085ec0
7
+ data.tar.gz: 0fa5433ac74d7150226a4a9482dd978aecdf8b1465868b6996205b9eff66fb24150ad193aefaeb193a4e9b8c01b335a24f1c071811e5df31314691cffb36609f
data/bin/coba CHANGED
@@ -4,6 +4,9 @@ require "thor"
4
4
  require "json"
5
5
  require "fileutils"
6
6
  require "coba-testrunner"
7
+ require "selenium-webdriver"
8
+ require "thread"
9
+ # $DEBUG = true
7
10
 
8
11
  class Coba < Thor
9
12
  desc "test configFile [browser]", "Testing based on configFile and/or specific Browser"
@@ -18,6 +21,7 @@ class Coba < Thor
18
21
  > $./coba test configFile.json firefox
19
22
  LONGDESC
20
23
  def test(configFile, browser=nil)
24
+ Thread.abort_on_exception=true
21
25
  puts "Testing based on #{configFile}"
22
26
 
23
27
  # 1. read configFile
@@ -43,6 +47,8 @@ class Coba < Thor
43
47
  end
44
48
 
45
49
  testCases = JSON.parse(testFile)
50
+ # testCases = [0,1,2,3]
51
+
46
52
 
47
53
  # 3. get browser
48
54
  # isArray? isString?
@@ -53,7 +59,6 @@ class Coba < Thor
53
59
  if browser === nil
54
60
  browser = config['browsers']
55
61
  end
56
-
57
62
  if browser.instance_of? String
58
63
  arrayOfBrowser << browser
59
64
  else
@@ -65,59 +70,85 @@ class Coba < Thor
65
70
  singleBrowserConfig = config;
66
71
  singleBrowserConfig["browsers"] = browser
67
72
 
68
- # variable untuk menyimpan hasil
69
- logs = Array.new
70
-
71
- # 5. Loop Test Cases hasil generate
72
- testCases.each_with_index do |testCase,testIndex|
73
- # 5. Create object Test
74
- singleBrowserConfig['keyIndex'] = testIndex
75
- test = TestRunner.new(singleBrowserConfig)
76
-
77
- # - init
78
- statusTest = 0
79
- memoryUsage = Array.new
80
- test.init()
81
- # driver init
82
- # screenshot after init (if config set to true)
83
- # RAM Calculation
84
- # Create Thread, combine, and count average
85
- t = Thread.new{
73
+ threadLimit = 1
74
+ if(!config['threadLimit'].nil? || config['threadLimit'].to_i > 0 )
75
+ threadLimit = config['threadLimit']
76
+ end
77
+
78
+ logs = Hash.new
79
+ logs['data'] = Array.new
80
+ logs['time'] = Array.new
81
+ logTime = Hash.new
82
+ th = Array.new
83
+
84
+ workQueue = Queue.new
85
+ testCases.each{|x| workQueue.push x }
86
+
87
+ logTime['start'] = Time.new
88
+
89
+ memoryUsage = Array.new
90
+
91
+ statusTest = 0
92
+
93
+ thMemory = Thread.new{
94
+ accumulator = 0
95
+ while statusTest != 1 do
96
+ output = `tasklist /FO CSV | grep #{singleBrowserConfig['browsers']}.exe`
97
+ puts output
98
+ puts "========"
99
+ csvData = CSV.parse(output)
100
+ csvData.each do |data|
101
+ accumulator = accumulator + data.last.sub(",","").sub("K","").to_i
102
+ end
103
+ if accumulator > 0
104
+ memoryUsage << accumulator
86
105
  accumulator = 0
87
- while statusTest != 1 do
88
- output = `tasklist /FO CSV | grep #{singleBrowserConfig}.exe`
89
- puts output
90
- puts "========"
91
- csvData = CSV.parse(output)
92
- csvData.each do |data|
93
- accumulator = accumulator + data.last.sub(",","").sub("K","").to_i
94
- end
95
- memoryUsage << accumulator
96
- accumulator = 0
97
- end
98
- }
99
- # - start
100
- test.start(testCase)
101
- # - before Hook (if available)
102
- # Log Time
103
- # screenshot before and after test (if config set to true)
104
- # - Execution
105
- # Log Time
106
- # screenshot before and after test (if config set to true)
107
- # - after Hook (if available)
108
- # Log Time
109
- # screenshot before and after test (if config set to true)
110
- # - stop
111
- statusTest = 1;
112
- t.join
113
- result = test.stop()
114
- result['memory'] = memoryUsage
115
- # driver quit
116
-
117
- # compose result
118
- logs.push(result)
106
+ end
107
+ end
108
+ }
109
+
110
+ worker = (0..(threadLimit-1)).map do
111
+ Thread.new(){
112
+ until workQueue.empty?
113
+ singleBrowserConfig['keyIndex'] = testCases.length - workQueue.length
114
+ inputsTestCases = workQueue.pop(true)
115
+
116
+ test = TestRunner.new(singleBrowserConfig)
117
+
118
+ # - init
119
+ test.init()
120
+ # driver init
121
+ # screenshot after init (if config set to true)
122
+
123
+ # - start
124
+ test.start(inputsTestCases)
125
+ # - before Hook (if available)
126
+ # Log Time
127
+ # screenshot before and after test (if config set to true)
128
+ # - Execution
129
+ # Log Time
130
+ # screenshot before and after test (if config set to true)
131
+ # - after Hook (if available)
132
+ # Log Time
133
+ # screenshot before and after test (if config set to true)
134
+ # - stop
135
+ result = test.stop()
136
+ logs['data'] << result
137
+ end
138
+ }
119
139
  end
120
140
 
141
+ worker.each{|t|
142
+ if(!t.nil?)
143
+ t.join
144
+ end
145
+ }
146
+
147
+ statusTest = 1
148
+ thMemory.join
149
+
150
+ logTime['end'] = Time.new
151
+ logTime['time'] = logTime['end'] - logTime['start']
121
152
  # 6. Ketika selesai atau throw error save log (JSON) ke dalam sebuah file dengan alamat cwd()+log+browserName
122
153
  # tapi sebelumnya harus di ambil dulu isi file sebelumnya
123
154
  logPath = "#{Dir.pwd}/log/#{browser}"
@@ -125,23 +156,25 @@ class Coba < Thor
125
156
  FileUtils::mkdir_p "#{logPath}/"
126
157
  end
127
158
 
128
- preloadedData = Array.new
159
+ preloadedData = Hash.new
160
+ preloadedData['data'] = Array.new
161
+ preloadedData['time'] = Array.new
162
+ preloadedData['memory'] = Array.new
129
163
  if File.exist?("#{logPath}/#{browser}.json")
130
164
  logFile = File.read("#{logPath}/#{browser}.json")
131
165
  preloadedData = JSON.parse(logFile)
132
166
  end
133
167
 
134
168
  # puts preloadedData
135
- preloadedData.concat(logs)
169
+ preloadedData['data'].concat(logs['data'])
170
+ preloadedData['time'] << logTime
171
+ preloadedData['memory'] << memoryUsage
136
172
 
137
173
  File.open("#{logPath}/#{browser}.json","w") do |f|
138
174
  f.write(JSON.pretty_generate preloadedData)
139
175
  end
140
- end
141
-
142
-
143
- end
144
-
176
+ end #end of each with index
177
+ end #end of def
145
178
 
146
179
  desc "generate type", "[IN PROGRESS] Generate data for testing purpose"
147
180
  long_desc <<-LONGDESC
@@ -17,7 +17,20 @@ class TestRunner
17
17
 
18
18
  case @config['browsers']
19
19
  when "firefox"
20
- @driver = Selenium::WebDriver.for :firefox, :profile => "Driver"
20
+ options = Selenium::WebDriver::Firefox::Options.new
21
+ options.profile = "Driver"
22
+ @driver = Selenium::WebDriver.for :firefox, options: options
23
+ when "phantomjs"
24
+ @driver = Selenium::WebDriver.for :phantomjs
25
+ when "chrome"
26
+ @driver = Selenium::WebDriver.for :chrome
27
+ when "iexplore"
28
+ caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer(
29
+ 'ie.ensureCleanSession' => true,
30
+ 'ie.forceCreateProcessApi' => true,
31
+ 'ie.browserCommandLineSwitches' => '-private'
32
+ )
33
+ @driver = Selenium::WebDriver.for(:internet_explorer, :desired_capabilities => caps)
21
34
  when "safari"
22
35
  # opts = Selenium::WebDriver::Safari::Options.new
23
36
  # opts.add_extension "#{Dir.pwd}/../selenium/SafariDriver.safariextz"
@@ -25,12 +38,7 @@ class TestRunner
25
38
  when "opera"
26
39
  Selenium::WebDriver::Chrome.driver_path = "#{Dir.pwd}/../selenium/operadriver.exe"
27
40
  @driver = Selenium::WebDriver.for :chrome
28
- when "chrome"
29
- @driver = Selenium::WebDriver.for :chrome
30
- when "iexplore"
31
- @driver = Selenium::WebDriver.for :ie
32
- when "phantomjs"
33
- @driver = Selenium::WebDriver.for :phantomjs
41
+ # @driver = Selenium::WebDriver.for :ie
34
42
  else
35
43
  puts "Browser you specified not supported yet"
36
44
  end
@@ -76,7 +84,7 @@ class TestRunner
76
84
  @time[index]['time'] = finish - start
77
85
  end
78
86
  def loadUrl(url)
79
- puts "- Load Url"
87
+ puts "- Load Url - #{@index+1}"
80
88
  takeScreenshot(@screenshotPath,'loadUrl','start')
81
89
 
82
90
  start = Time.new
@@ -94,7 +102,7 @@ class TestRunner
94
102
  takeScreenshot(@screenshotPath,'loadUrl','finish')
95
103
  end
96
104
  def mainTest(testCase)
97
- puts "- Executing Main Test"
105
+ puts "- Executing Main Test - #{@index+1}"
98
106
  takeScreenshot(@screenshotPath,'MainExecution','start')
99
107
 
100
108
  start = Time.new
@@ -112,13 +120,12 @@ class TestRunner
112
120
  takeScreenshot(@screenshotPath,'MainExecution','finish')
113
121
  end
114
122
  def beforeExecution
115
- puts "- Executing Pre Script"
123
+ puts "- Executing Pre Script - #{@index+1}"
116
124
  takeScreenshot(@screenshotPath,'PreExecution','load')
117
125
  start = Time.new
118
126
 
119
127
  if @config['before'] and File.exist?(@config['before'])
120
128
  load "#{Dir.pwd}/#{@config['before']}" #work LOL
121
- @dri
122
129
  test = BeforeTest.new(@testCase,@driver).run
123
130
  end
124
131
 
@@ -129,7 +136,7 @@ class TestRunner
129
136
  takeScreenshot(@screenshotPath,'PreExecution','finish')
130
137
  end
131
138
  def afterExecution
132
- puts "- Executing After Execution Script"
139
+ puts "- Executing After Execution Script - #{@index+1}"
133
140
  takeScreenshot(@screenshotPath,'AfterExecution','load')
134
141
 
135
142
  start = Time.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coba-testrunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunu Pinasthika Fajar