sapphire 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sapphire.rb +30 -0
- data/lib/sapphire/DSL/Browser/Browser.rb +13 -0
- data/lib/sapphire/DSL/Browser/Check.rb +12 -0
- data/lib/sapphire/DSL/Browser/Clear.rb +15 -0
- data/lib/sapphire/DSL/Browser/Click.rb +12 -0
- data/lib/sapphire/DSL/Browser/Close.rb +12 -0
- data/lib/sapphire/DSL/Browser/Complete.rb +15 -0
- data/lib/sapphire/DSL/Browser/CurrentUrl.rb +11 -0
- data/lib/sapphire/DSL/Browser/Error.rb +12 -0
- data/lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb +45 -0
- data/lib/sapphire/DSL/Browser/Exists.rb +22 -0
- data/lib/sapphire/DSL/Browser/For.rb +10 -0
- data/lib/sapphire/DSL/Browser/Hide.rb +10 -0
- data/lib/sapphire/DSL/Browser/IsHidden.rb +28 -0
- data/lib/sapphire/DSL/Browser/IsVisible.rb +25 -0
- data/lib/sapphire/DSL/Browser/MouseOver.rb +12 -0
- data/lib/sapphire/DSL/Browser/Navigate.rb +11 -0
- data/lib/sapphire/DSL/Browser/Reload.rb +11 -0
- data/lib/sapphire/DSL/Browser/Set.rb +12 -0
- data/lib/sapphire/DSL/Browser/Should.rb +10 -0
- data/lib/sapphire/DSL/Browser/Show.rb +26 -0
- data/lib/sapphire/DSL/Browser/Start.rb +16 -0
- data/lib/sapphire/DSL/Browser/To.rb +10 -0
- data/lib/sapphire/DSL/Browser/Tracker.rb +15 -0
- data/lib/sapphire/DSL/Browser/Transition.rb +10 -0
- data/lib/sapphire/DSL/Browser/Uncheck.rb +12 -0
- data/lib/sapphire/DSL/Browser/With.rb +10 -0
- data/lib/sapphire/DSL/Configuration/ConfiguredBrowser.rb +13 -0
- data/lib/sapphire/DSL/Configuration/ConfiguredUser.rb +11 -0
- data/lib/sapphire/DSL/Configuration/Use.rb +15 -0
- data/lib/sapphire/DSL/Data/Exist.rb +11 -0
- data/lib/sapphire/DSL/Data/Find.rb +10 -0
- data/lib/sapphire/DSL/Data/GetPageField.rb +17 -0
- data/lib/sapphire/DSL/Data/Underscore.rb +9 -0
- data/lib/sapphire/DSL/Data/Validate.rb +16 -0
- data/lib/sapphire/DSL/Data/Verify.rb +10 -0
- data/lib/sapphire/DSL/Scenarios/Is.rb +9 -0
- data/lib/sapphire/DSL/Scenarios/Pending.rb +29 -0
- data/lib/sapphire/DSL/Scenarios/and.rb +25 -0
- data/lib/sapphire/DSL/Scenarios/background.rb +23 -0
- data/lib/sapphire/DSL/Scenarios/dsl.rb +60 -0
- data/lib/sapphire/DSL/Scenarios/finally.rb +32 -0
- data/lib/sapphire/DSL/Scenarios/given.rb +57 -0
- data/lib/sapphire/DSL/Scenarios/runner.rb +30 -0
- data/lib/sapphire/DSL/Scenarios/scenario.rb +51 -0
- data/lib/sapphire/DSL/Scenarios/then.rb +34 -0
- data/lib/sapphire/DSL/Scenarios/when.rb +47 -0
- data/lib/sapphire/DataAbstractions/Database.rb +57 -0
- data/lib/sapphire/DataAbstractions/Query.rb +20 -0
- data/lib/sapphire/Testing/Executable.rb +30 -0
- data/lib/sapphire/Testing/RSpecRunner.rb +85 -0
- data/lib/sapphire/Testing/RakeTask.rb +109 -0
- data/lib/sapphire/Testing/ResultList.rb +19 -0
- data/lib/sapphire/Testing/ResultTree.rb +37 -0
- data/lib/sapphire/Testing/ScenarioResult.rb +31 -0
- data/lib/sapphire/Testing/TestResult.rb +24 -0
- data/lib/sapphire/Testing/TestRunnerAdapter.rb +62 -0
- data/lib/sapphire/WebAbstractions/Controls/Base/Control.rb +74 -0
- data/lib/sapphire/WebAbstractions/Controls/Base/Page.rb +47 -0
- data/lib/sapphire/WebAbstractions/Controls/Base/WebBrowser.rb +74 -0
- data/lib/sapphire/WebAbstractions/Controls/Button.rb +9 -0
- data/lib/sapphire/WebAbstractions/Controls/CheckBox.rb +28 -0
- data/lib/sapphire/WebAbstractions/Controls/Chrome.rb +21 -0
- data/lib/sapphire/WebAbstractions/Controls/DropDown.rb +25 -0
- data/lib/sapphire/WebAbstractions/Controls/FireFox.rb +22 -0
- data/lib/sapphire/WebAbstractions/Controls/Hyperlink.rb +8 -0
- data/lib/sapphire/WebAbstractions/Controls/Image.rb +9 -0
- data/lib/sapphire/WebAbstractions/Controls/InternetExplorer.rb +21 -0
- data/lib/sapphire/WebAbstractions/Controls/Label.rb +8 -0
- data/lib/sapphire/WebAbstractions/Controls/RadioButton.rb +18 -0
- data/lib/sapphire/WebAbstractions/Controls/TextBox.rb +31 -0
- data/lib/sapphire/WebAbstractions/Controls/Title.rb +12 -0
- data/lib/sapphire/version.rb +3 -0
- metadata +152 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
class Then
|
2
|
+
include Sapphire::Testing::Executable
|
3
|
+
|
4
|
+
attr_reader :value
|
5
|
+
attr_accessor :text
|
6
|
+
attr_reader :block
|
7
|
+
attr_reader :and
|
8
|
+
attr_reader :parent
|
9
|
+
attr_reader :results
|
10
|
+
|
11
|
+
def initialize(parent, pre, text, &block)
|
12
|
+
@block = block
|
13
|
+
@value = text
|
14
|
+
@text = pre + text.to_s
|
15
|
+
@and = []
|
16
|
+
@parent = parent
|
17
|
+
@results = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_and(pre, text, &block)
|
21
|
+
if(!self.value.instance_of? Pending)
|
22
|
+
x = Then.new(self, pre, text, &block)
|
23
|
+
self.and << x
|
24
|
+
else
|
25
|
+
self.and << Then.new(self, pre, Pending.new(pre + text), &block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def AddResult(result)
|
30
|
+
@results << result
|
31
|
+
self.parent.results.last.AddChild(result)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class When
|
2
|
+
include Sapphire::Testing::Executable
|
3
|
+
|
4
|
+
attr_reader :value
|
5
|
+
attr_accessor :text
|
6
|
+
attr_reader :block
|
7
|
+
attr_reader :then
|
8
|
+
attr_reader :and
|
9
|
+
attr_reader :parent
|
10
|
+
attr_reader :results
|
11
|
+
|
12
|
+
def initialize(parent, pre, text, &block)
|
13
|
+
@block = block
|
14
|
+
@value = text
|
15
|
+
@text = pre + text.to_s
|
16
|
+
@then = []
|
17
|
+
@and = []
|
18
|
+
@parent = parent
|
19
|
+
@results = []
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_then(pre, text, &block)
|
23
|
+
if(self.value.is_a? Pending)
|
24
|
+
@then << Then.new(self, pre, Pending.new(text), &block)
|
25
|
+
else
|
26
|
+
@then << Then.new(self, pre, text, &block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_and(pre, text, &block)
|
31
|
+
if(self.value.is_a? Pending)
|
32
|
+
self.and << And.new(self, Pending.new(pre + text), &block)
|
33
|
+
else
|
34
|
+
self.and << And.new(self, pre + text, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def last_then
|
39
|
+
@then.last
|
40
|
+
end
|
41
|
+
|
42
|
+
def AddResult(result)
|
43
|
+
@results << result
|
44
|
+
self.parent.results.last.AddChild(result)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Sapphire
|
4
|
+
module DataAbstractions
|
5
|
+
class Database
|
6
|
+
|
7
|
+
def Open(connection_string)
|
8
|
+
@connection = WIN32OLE.new('ADODB.Connection')
|
9
|
+
@connection.Open(connection_string)
|
10
|
+
end
|
11
|
+
|
12
|
+
def query(sql)
|
13
|
+
recordset = WIN32OLE.new('ADODB.Recordset')
|
14
|
+
recordset.Open(sql, @connection, 0 , 1)
|
15
|
+
|
16
|
+
fields = []
|
17
|
+
|
18
|
+
recordset.Fields.each do |field|
|
19
|
+
fields << field.Name
|
20
|
+
end
|
21
|
+
begin
|
22
|
+
recordset.MoveFirst
|
23
|
+
data = recordset.GetRows
|
24
|
+
rescue
|
25
|
+
data = []
|
26
|
+
end
|
27
|
+
|
28
|
+
if(recordset.State != 0)
|
29
|
+
recordset.Close
|
30
|
+
end
|
31
|
+
|
32
|
+
data = data.transpose
|
33
|
+
records = []
|
34
|
+
|
35
|
+
data.each do |row|
|
36
|
+
y = 0
|
37
|
+
record = Hash.new
|
38
|
+
row.each do |column|
|
39
|
+
if(column != nil)
|
40
|
+
record.store fields[y].underscore.intern, column.to_s
|
41
|
+
else
|
42
|
+
record.store fields[y].underscore.intern, column
|
43
|
+
end
|
44
|
+
y += 1
|
45
|
+
end
|
46
|
+
records << record
|
47
|
+
end
|
48
|
+
records
|
49
|
+
end
|
50
|
+
|
51
|
+
def close
|
52
|
+
@connection.Close
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sapphire
|
2
|
+
module DataAbstractions
|
3
|
+
module Query
|
4
|
+
def Execute(block)
|
5
|
+
x = self.Database.new
|
6
|
+
|
7
|
+
x.Open $config[x.Connection]
|
8
|
+
|
9
|
+
path = File.expand_path(self.Script, __FILE__)
|
10
|
+
file = File.open(path)
|
11
|
+
contents = file.read
|
12
|
+
self.Tokenize(contents)
|
13
|
+
|
14
|
+
results = x.query(contents)
|
15
|
+
block.call results
|
16
|
+
x.close
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Sapphire
|
2
|
+
module Testing
|
3
|
+
module Executable
|
4
|
+
def execute(id)
|
5
|
+
start = Time.now
|
6
|
+
begin
|
7
|
+
if(self.value.is_a? Pending)
|
8
|
+
self.AddResult(ResultTree.new(self.text, TestResult.new("pending", self.text, "Pending", "", Time.now - start, id)))
|
9
|
+
puts "(pending) " + self.text + " (" + (Time.now - start).to_s + "s)"
|
10
|
+
return
|
11
|
+
end
|
12
|
+
self.block.call
|
13
|
+
self.AddResult(ResultTree.new(self.text, TestResult.new("pass", self.text, "Success", "", Time.now - start, id)))
|
14
|
+
puts "(pass) " + self.text + " (" + (Time.now - start).to_s + "s)"
|
15
|
+
rescue => msg
|
16
|
+
|
17
|
+
stack = ""
|
18
|
+
msg.backtrace.each do |line|
|
19
|
+
stack += "\r\n" + line
|
20
|
+
end
|
21
|
+
|
22
|
+
self.AddResult(ResultTree.new(self.text, TestResult.new("fail", self.text, msg.message, stack, Time.now - start, id)))
|
23
|
+
puts "(fail) " + self.text + ": " + msg.message + " (" + (Time.now - start).to_s + "s)"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Sapphire
|
2
|
+
module Testing
|
3
|
+
module RSpecRunner
|
4
|
+
def execute(id)
|
5
|
+
@block.call
|
6
|
+
s = self
|
7
|
+
x = @givens
|
8
|
+
y = @backgrounds
|
9
|
+
background_pending = false
|
10
|
+
|
11
|
+
y.each do |background|
|
12
|
+
if(background.value.instance_of? Pending)
|
13
|
+
background_pending = true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
x.each do |g|
|
18
|
+
describe g.text do
|
19
|
+
|
20
|
+
before :all do
|
21
|
+
y.each do |b|
|
22
|
+
if(!b.value.instance_of? Pending and !s.value.instance_of? Pending)
|
23
|
+
b.block.call()
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
before :each do
|
29
|
+
if(!g.value.instance_of? Pending and !s.value.instance_of? Pending and !background_pending)
|
30
|
+
g.block.call()
|
31
|
+
g.and.each do |a|
|
32
|
+
a.block.call()
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
g.when.each do |w|
|
38
|
+
describe w.text do
|
39
|
+
before do
|
40
|
+
if(!w.value.instance_of? Pending and !s.value.instance_of? Pending and !background_pending)
|
41
|
+
w.block.call()
|
42
|
+
|
43
|
+
if (w.and.count > 0)
|
44
|
+
w.and.each do |a|
|
45
|
+
a.block.call()
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if (w.then.count > 0)
|
52
|
+
w.then.each do |t|
|
53
|
+
if(!t.value.instance_of? Pending and !w.value.instance_of? Pending and !g.value.instance_of? Pending and !s.value.instance_of? Pending and !background_pending)
|
54
|
+
it t.text do
|
55
|
+
t.block.call()
|
56
|
+
t.and.each do |a|
|
57
|
+
if(!a.value.instance_of? Pending)
|
58
|
+
a.block.call()
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
else
|
63
|
+
pending t.text
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
after :all do
|
71
|
+
if(g.finally and !g.finally.value.instance_of? Pending and !s.value.instance_of? Pending and !background_pending)
|
72
|
+
g.finally.block.call()
|
73
|
+
|
74
|
+
g.finally.and.each do |a|
|
75
|
+
a.block.call()
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Sapphire
|
5
|
+
module Testing
|
6
|
+
class RakeTask
|
7
|
+
attr_accessor :pattern
|
8
|
+
attr_accessor :verbose
|
9
|
+
attr_accessor :fail_on_error
|
10
|
+
attr_accessor :name
|
11
|
+
|
12
|
+
|
13
|
+
def test_outcome(result)
|
14
|
+
|
15
|
+
result.results.each do |r|
|
16
|
+
|
17
|
+
if(r.type == 'fail')
|
18
|
+
return 'fail'
|
19
|
+
end
|
20
|
+
|
21
|
+
if(r.type == 'pending')
|
22
|
+
return 'pending'
|
23
|
+
end
|
24
|
+
|
25
|
+
if(!r.results.empty?)
|
26
|
+
return test_outcome(r)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
return 'pass'
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(*args)
|
36
|
+
|
37
|
+
@name = args.shift || :spec
|
38
|
+
@pattern = nil
|
39
|
+
@verbose, @fail_on_error = true, true
|
40
|
+
|
41
|
+
yield self if block_given?
|
42
|
+
|
43
|
+
Rake::Task.define_task name do
|
44
|
+
RakeFileUtils.send(:verbose, verbose) do
|
45
|
+
files_to_run = FileList[ pattern ].map { |f|
|
46
|
+
y = nil
|
47
|
+
x = nil
|
48
|
+
x = f.gsub(/"/, '\"') if f != nil
|
49
|
+
y = x.gsub(/'/, "\\\\'") if x != nil
|
50
|
+
y
|
51
|
+
}
|
52
|
+
if files_to_run.empty?
|
53
|
+
puts "No examples matching #{pattern} could be found"
|
54
|
+
else
|
55
|
+
begin
|
56
|
+
|
57
|
+
files_to_run.each do |f|
|
58
|
+
next unless f != nil
|
59
|
+
require File.expand_path("../../" + f.to_s, __FILE__) unless File.directory? f
|
60
|
+
end
|
61
|
+
|
62
|
+
success_array = []
|
63
|
+
pending_array = []
|
64
|
+
failure_array = []
|
65
|
+
|
66
|
+
i = 3
|
67
|
+
|
68
|
+
Runner.instance.scenarios.each do |scenario|
|
69
|
+
i += 1
|
70
|
+
scenario.execute i
|
71
|
+
scenario.result.set_id i
|
72
|
+
scenario.result.set_type test_outcome(scenario.result)
|
73
|
+
|
74
|
+
success_array << scenario.result if scenario.result.type == "pass"
|
75
|
+
pending_array << scenario.result if scenario.result.type == "pending"
|
76
|
+
failure_array << scenario.result if scenario.result.type == "fail"
|
77
|
+
end
|
78
|
+
|
79
|
+
item_array = []
|
80
|
+
item_array << ResultsList.new("Passing", success_array, 1)
|
81
|
+
item_array << ResultsList.new("Pending", pending_array, 2)
|
82
|
+
item_array << ResultsList.new("Failing", failure_array, 3)
|
83
|
+
|
84
|
+
|
85
|
+
File.open(File.dirname(__FILE__) + "/../ReportGenerator/output.json", "w") do |file|
|
86
|
+
file.puts ActiveSupport::JSON.encode item_array
|
87
|
+
end
|
88
|
+
|
89
|
+
Runner.instance.scenarios.each do |scenario|
|
90
|
+
File.open(File.dirname(__FILE__) + "/../ReportGenerator/" + scenario.result.myId.to_s + ".json", "w") do |file|
|
91
|
+
file.puts ActiveSupport::JSON.encode scenario.result
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
rescue => e
|
96
|
+
stack = ""
|
97
|
+
e.backtrace.each do |line|
|
98
|
+
stack += "\r\n" + line
|
99
|
+
end
|
100
|
+
|
101
|
+
raise("Some tests have failed: " + e.message + " : " + stack) if fail_on_error
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sapphire
|
2
|
+
module Testing
|
3
|
+
class ResultsList
|
4
|
+
|
5
|
+
attr_reader :myId
|
6
|
+
attr_reader :text
|
7
|
+
attr_reader :children
|
8
|
+
|
9
|
+
def initialize(text, results, id)
|
10
|
+
@myId = id
|
11
|
+
@text = text
|
12
|
+
@children = results
|
13
|
+
@expanded = true
|
14
|
+
@count = results.length
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Sapphire
|
2
|
+
module Testing
|
3
|
+
class ResultTree
|
4
|
+
|
5
|
+
attr_accessor :results
|
6
|
+
attr_accessor :type
|
7
|
+
|
8
|
+
def initialize(text, result)
|
9
|
+
|
10
|
+
@type = 'pass'
|
11
|
+
@execution_time = 0
|
12
|
+
|
13
|
+
if(result != nil)
|
14
|
+
self.type = result.type
|
15
|
+
@iconCls = "accept" if result.type == "pass"
|
16
|
+
@iconCls = "delete" if result.type == "fail"
|
17
|
+
@iconCls = "error" if result.type == "pending"
|
18
|
+
@execution_time = result.execution_time
|
19
|
+
@expanded = true
|
20
|
+
@message = result.message
|
21
|
+
@stack = result.stack
|
22
|
+
end
|
23
|
+
@text = text
|
24
|
+
@results = []
|
25
|
+
@leaf = true
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def AddChild(node)
|
30
|
+
@results << node
|
31
|
+
@leaf = false
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|