coba-testrunner 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/bin/coba +24 -6
- data/lib/coba-testrunner.rb +20 -14
- data/lib/template/after-ruby.rb +25 -0
- data/lib/template/before-ruby.rb +25 -0
- data/lib/template/test-ruby.rb +25 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c4aa82115f358ddc65469f8b8ac6c7c9cb54a59
|
|
4
|
+
data.tar.gz: ff4c27d85026a2b854cb7ad0dd042c1f5a394495
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0a6254b2de54e6192486d7989d36fec5fd881aac9200cbd1b4053f67c3e2d2fe5d986b1d3c667bf5300497cff4d9a5968bd91b498682c1a5cd3bfaef1ea054cd
|
|
7
|
+
data.tar.gz: aff50eb58d36ee71a4962bcb4e5c9354c6add9b48fec319bbde66a45d6147896ad236d76a096faf21568b7ab13753eb77571b68a9f29df06de8ee2ae3ae70ebd
|
data/bin/coba
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "thor"
|
|
4
4
|
require "json"
|
|
5
|
+
require "fileutils"
|
|
5
6
|
require "coba-testrunner"
|
|
6
7
|
|
|
7
8
|
class Coba < Thor
|
|
@@ -23,8 +24,8 @@ class Coba < Thor
|
|
|
23
24
|
# error when not found
|
|
24
25
|
# error when json not valid
|
|
25
26
|
|
|
26
|
-
if File.exist?
|
|
27
|
-
file = File.read(configFile)
|
|
27
|
+
if File.exist? "#{Dir.pwd}/#{configFile}"
|
|
28
|
+
file = File.read("#{Dir.pwd}/#{configFile}")
|
|
28
29
|
else
|
|
29
30
|
raise "File #{configFile} doesn't exist"
|
|
30
31
|
end
|
|
@@ -48,10 +49,15 @@ class Coba < Thor
|
|
|
48
49
|
# String push ke array
|
|
49
50
|
# Array loop
|
|
50
51
|
arrayOfBrowser = Array.new
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
|
|
53
|
+
if browser.empty?
|
|
54
|
+
browser = config['browsers']
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
if browser.instance_of? String
|
|
58
|
+
arrayOfBrowser << browser
|
|
53
59
|
else
|
|
54
|
-
arrayOfBrowser =
|
|
60
|
+
arrayOfBrowser = browser
|
|
55
61
|
end
|
|
56
62
|
|
|
57
63
|
arrayOfBrowser.each_with_index do |browser,index|
|
|
@@ -93,7 +99,7 @@ class Coba < Thor
|
|
|
93
99
|
end
|
|
94
100
|
|
|
95
101
|
# 6. Ketika selesai atau throw error save log (JSON) ke dalam sebuah file dengan alamat cwd()+log+browserName
|
|
96
|
-
logPath = "#{Dir.pwd}/#{browser}"
|
|
102
|
+
logPath = "#{Dir.pwd}/log/#{browser}"
|
|
97
103
|
if !Dir.exist? "#{logPath}/"
|
|
98
104
|
FileUtils::mkdir_p "#{logPath}/"
|
|
99
105
|
end
|
|
@@ -118,6 +124,18 @@ class Coba < Thor
|
|
|
118
124
|
def generate(type)
|
|
119
125
|
puts "Generate on #{type} data"
|
|
120
126
|
end
|
|
127
|
+
|
|
128
|
+
desc "init", "Prepare boilerplate file for testing "
|
|
129
|
+
long_desc <<-LONGDESC
|
|
130
|
+
coba init will generate skeleton file for your testing purpose
|
|
131
|
+
|
|
132
|
+
ex :\n
|
|
133
|
+
> $./coba init
|
|
134
|
+
LONGDESC
|
|
135
|
+
def init
|
|
136
|
+
dir = File.dirname(File.expand_path(__FILE__))
|
|
137
|
+
FileUtils.copy_entry dir+"/../lib/template/", Dir.pwd+"/"
|
|
138
|
+
end
|
|
121
139
|
end
|
|
122
140
|
|
|
123
141
|
Coba.start(ARGV)
|
data/lib/coba-testrunner.rb
CHANGED
|
@@ -8,6 +8,8 @@ class TestRunner
|
|
|
8
8
|
@time = Hash.new
|
|
9
9
|
@index = config['keyIndex']
|
|
10
10
|
@testCase = ""
|
|
11
|
+
# @screenshotPath = "#{Dir.pwd}/log/#{@config['browsers']}/#{@config['screenshotPath']}/#{@index+1}"
|
|
12
|
+
@screenshotPath = "#{Dir.pwd}/log/#{@config['browsers']}/screenshot/#{@index+1}"
|
|
11
13
|
end
|
|
12
14
|
def init()
|
|
13
15
|
start = Time.new
|
|
@@ -47,6 +49,7 @@ class TestRunner
|
|
|
47
49
|
def stop
|
|
48
50
|
@driver.quit
|
|
49
51
|
@testCase['time'] = @time
|
|
52
|
+
puts "======================"
|
|
50
53
|
return @testCase
|
|
51
54
|
end
|
|
52
55
|
def config
|
|
@@ -61,7 +64,8 @@ class TestRunner
|
|
|
61
64
|
@time[index]['time'] = finish - start
|
|
62
65
|
end
|
|
63
66
|
def loadUrl(url)
|
|
64
|
-
|
|
67
|
+
puts "- Load Url"
|
|
68
|
+
takeScreenshot(@screenshotPath,'loadUrl','start')
|
|
65
69
|
|
|
66
70
|
start = Time.new
|
|
67
71
|
|
|
@@ -73,15 +77,16 @@ class TestRunner
|
|
|
73
77
|
|
|
74
78
|
logTime "load", start, finish
|
|
75
79
|
|
|
76
|
-
takeScreenshot(
|
|
80
|
+
takeScreenshot(@screenshotPath,'loadUrl','finish')
|
|
77
81
|
end
|
|
78
82
|
def mainTest(testCase)
|
|
79
|
-
|
|
83
|
+
puts "- Executing Main Test"
|
|
84
|
+
takeScreenshot(@screenshotPath,'MainExecution','start')
|
|
80
85
|
|
|
81
86
|
start = Time.new
|
|
82
87
|
|
|
83
88
|
if @config['scenario'] and File.exist?(@config['scenario'])
|
|
84
|
-
load @config['scenario'] #work LOL
|
|
89
|
+
load "#{Dir.pwd}/#{@config['scenario']}" #work LOL
|
|
85
90
|
test = Test.new(testCase,@driver).run
|
|
86
91
|
@testCase['assertion'] = test
|
|
87
92
|
end
|
|
@@ -90,46 +95,47 @@ class TestRunner
|
|
|
90
95
|
|
|
91
96
|
logTime "main", start, finish
|
|
92
97
|
|
|
93
|
-
takeScreenshot(
|
|
98
|
+
takeScreenshot(@screenshotPath,'MainExecution','finish')
|
|
94
99
|
end
|
|
95
100
|
def beforeExecution
|
|
96
|
-
|
|
101
|
+
puts "- Executing Pre Script"
|
|
102
|
+
takeScreenshot(@screenshotPath,'PreExecution','load')
|
|
97
103
|
|
|
98
104
|
start = Time.new
|
|
99
105
|
|
|
100
106
|
if @config['before'] and File.exist?(@config['before'])
|
|
101
|
-
load @config['
|
|
102
|
-
test = BeforeTest.new(@driver).run
|
|
107
|
+
load "#{Dir.pwd}/#{@config['before']}" #work LOL
|
|
108
|
+
test = BeforeTest.new(@testCase,@driver).run
|
|
103
109
|
end
|
|
104
110
|
|
|
105
111
|
finish = Time.new
|
|
106
112
|
|
|
107
113
|
logTime "before", start, finish
|
|
108
114
|
|
|
109
|
-
takeScreenshot(
|
|
115
|
+
takeScreenshot(@screenshotPath,'PreExecution','finish')
|
|
110
116
|
end
|
|
111
117
|
def afterExecution
|
|
112
|
-
|
|
118
|
+
puts "- Executing After Execution Script"
|
|
119
|
+
takeScreenshot(@screenshotPath,'AfterExecution','load')
|
|
113
120
|
|
|
114
121
|
start = Time.new
|
|
115
122
|
|
|
116
123
|
if @config['after'] and File.exist?(@config['after'])
|
|
117
|
-
load @config['
|
|
118
|
-
test = AfterTest.new(@driver).run
|
|
124
|
+
load "#{Dir.pwd}/#{@config['after']}"
|
|
125
|
+
test = AfterTest.new(@testCase,@driver).run
|
|
119
126
|
end
|
|
120
127
|
|
|
121
128
|
finish = Time.new
|
|
122
129
|
|
|
123
130
|
logTime "after", start, finish
|
|
124
131
|
|
|
125
|
-
takeScreenshot(
|
|
132
|
+
takeScreenshot(@screenshotPath,'AfterExecution','finish')
|
|
126
133
|
end
|
|
127
134
|
def takeScreenshot(folderPath,prefix=nil,sufix=nil)
|
|
128
135
|
if @config['screenshot']
|
|
129
136
|
if !Dir.exist? "#{folderPath}/"
|
|
130
137
|
FileUtils::mkdir_p "#{folderPath}/"
|
|
131
138
|
end
|
|
132
|
-
puts "#{folderPath}/#{prefix}.png"
|
|
133
139
|
@driver.save_screenshot("#{folderPath}/#{prefix}-#{sufix}.png")
|
|
134
140
|
end
|
|
135
141
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "selenium-webdriver"
|
|
2
|
+
|
|
3
|
+
class AfterTest
|
|
4
|
+
def initialize(testCase,driver)
|
|
5
|
+
@testCase = testCase
|
|
6
|
+
@driver = driver
|
|
7
|
+
end
|
|
8
|
+
def run
|
|
9
|
+
# Here some example
|
|
10
|
+
|
|
11
|
+
inputs = @testCase['testCases']
|
|
12
|
+
inputs.each do |key,input|
|
|
13
|
+
element = @driver.find_element :css => key
|
|
14
|
+
element.send_keys input
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
buttonSubmit = @driver.find_element :css => ".uk-button-primary"
|
|
18
|
+
buttonSubmit.click
|
|
19
|
+
#
|
|
20
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
|
|
21
|
+
wait.until { @driver.find_element :css => ".uk-alert" }
|
|
22
|
+
#
|
|
23
|
+
# puts "Page title is #{@driver.title}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "selenium-webdriver"
|
|
2
|
+
|
|
3
|
+
class BeforeTest
|
|
4
|
+
def initialize(testCase,driver)
|
|
5
|
+
@testCase = testCase
|
|
6
|
+
@driver = driver
|
|
7
|
+
end
|
|
8
|
+
def run
|
|
9
|
+
# Here some example
|
|
10
|
+
|
|
11
|
+
inputs = @testCase['testCases']
|
|
12
|
+
inputs.each do |key,input|
|
|
13
|
+
element = @driver.find_element :css => key
|
|
14
|
+
element.send_keys input
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
buttonSubmit = @driver.find_element :css => ".uk-button-primary"
|
|
18
|
+
buttonSubmit.click
|
|
19
|
+
#
|
|
20
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
|
|
21
|
+
wait.until { @driver.find_element :css => ".uk-alert" }
|
|
22
|
+
#
|
|
23
|
+
# puts "Page title is #{@driver.title}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "selenium-webdriver"
|
|
2
|
+
|
|
3
|
+
class Test
|
|
4
|
+
def initialize(testCase,driver)
|
|
5
|
+
@testCase = testCase
|
|
6
|
+
@driver = driver
|
|
7
|
+
end
|
|
8
|
+
def run
|
|
9
|
+
# Here some example
|
|
10
|
+
|
|
11
|
+
inputs = @testCase['testCases']
|
|
12
|
+
inputs.each do |key,input|
|
|
13
|
+
element = @driver.find_element :css => key
|
|
14
|
+
element.send_keys input
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
buttonSubmit = @driver.find_element :css => ".uk-button-primary"
|
|
18
|
+
buttonSubmit.click
|
|
19
|
+
#
|
|
20
|
+
wait = Selenium::WebDriver::Wait.new(:timeout => 30)
|
|
21
|
+
wait.until { @driver.find_element :css => ".uk-alert" }
|
|
22
|
+
#
|
|
23
|
+
# puts "Page title is #{@driver.title}"
|
|
24
|
+
end
|
|
25
|
+
end
|
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.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sunu Pinasthika Fajar
|
|
@@ -19,6 +19,9 @@ extra_rdoc_files: []
|
|
|
19
19
|
files:
|
|
20
20
|
- bin/coba
|
|
21
21
|
- lib/coba-testrunner.rb
|
|
22
|
+
- lib/template/after-ruby.rb
|
|
23
|
+
- lib/template/before-ruby.rb
|
|
24
|
+
- lib/template/test-ruby.rb
|
|
22
25
|
homepage: ''
|
|
23
26
|
licenses:
|
|
24
27
|
- MIT
|