sapphire 0.7.26 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/lib/sapphire.rb +51 -40
  2. data/lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb +24 -68
  3. data/lib/sapphire/DSL.rb +18 -16
  4. data/lib/sapphire/DSL/Browser/Create.rb +10 -10
  5. data/lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb +20 -20
  6. data/lib/sapphire/DSL/Browser/Fluff/By.rb +10 -10
  7. data/lib/sapphire/DSL/Browser/Fluff/To.rb +10 -10
  8. data/lib/sapphire/DSL/Browser/Fluff/With.rb +10 -10
  9. data/lib/sapphire/DSL/Browser/Nouns/Browser.rb +17 -17
  10. data/lib/sapphire/DSL/Browser/Nouns/Enter.rb +10 -10
  11. data/lib/sapphire/DSL/Browser/Tracker.rb +15 -15
  12. data/lib/sapphire/DSL/Browser/Verbs/Accept.rb +8 -8
  13. data/lib/sapphire/DSL/Browser/Verbs/Check.rb +10 -10
  14. data/lib/sapphire/DSL/Browser/Verbs/Clear.rb +8 -8
  15. data/lib/sapphire/DSL/Browser/Verbs/Click.rb +10 -10
  16. data/lib/sapphire/DSL/Browser/Verbs/Compare.rb +18 -18
  17. data/lib/sapphire/DSL/Browser/Verbs/Complete.rb +13 -13
  18. data/lib/sapphire/DSL/Browser/Verbs/Exists.rb +16 -16
  19. data/lib/sapphire/DSL/Browser/Verbs/Exit.rb +11 -11
  20. data/lib/sapphire/DSL/Browser/Verbs/MouseOver.rb +10 -10
  21. data/lib/sapphire/DSL/Browser/Verbs/Navigate.rb +10 -10
  22. data/lib/sapphire/DSL/Browser/Verbs/Press.rb +8 -8
  23. data/lib/sapphire/DSL/Browser/Verbs/Reload.rb +11 -11
  24. data/lib/sapphire/DSL/Browser/Verbs/Set.rb +10 -10
  25. data/lib/sapphire/DSL/Browser/Verbs/Uncheck.rb +10 -10
  26. data/lib/sapphire/DSL/Comparisons/CheckedComparison.rb +17 -17
  27. data/lib/sapphire/DSL/Comparisons/Comparison.rb +50 -50
  28. data/lib/sapphire/DSL/Comparisons/ContainsComparison.rb +17 -17
  29. data/lib/sapphire/DSL/Comparisons/DifferComparison.rb +17 -17
  30. data/lib/sapphire/DSL/Comparisons/EqualsComparison.rb +16 -16
  31. data/lib/sapphire/DSL/Comparisons/NotComparison.rb +20 -20
  32. data/lib/sapphire/DSL/Comparisons/SelectedComparison.rb +17 -17
  33. data/lib/sapphire/DSL/Comparisons/StartsWithComparison.rb +17 -17
  34. data/lib/sapphire/DSL/Comparisons/VisibleComparison.rb +17 -17
  35. data/lib/sapphire/DSL/Configuration/ConfiguredBrowser.rb +12 -12
  36. data/lib/sapphire/DSL/Configuration/ConfiguredUser.rb +10 -10
  37. data/lib/sapphire/DSL/Configuration/Use.rb +18 -18
  38. data/lib/sapphire/DSL/Data/Find.rb +10 -10
  39. data/lib/sapphire/DSL/Data/GetPageField.rb +13 -13
  40. data/lib/sapphire/DSL/Data/Verify.rb +10 -10
  41. data/lib/sapphire/DSL/Evaluations/ControlEvaluation.rb +13 -0
  42. data/lib/sapphire/DSL/Evaluations/Evaluation.rb +55 -45
  43. data/lib/sapphire/DSL/Evaluations/FieldNotDefinedEvaluation.rb +20 -20
  44. data/lib/sapphire/DSL/Evaluations/FieldNotFoundEvaluation.rb +22 -22
  45. data/lib/sapphire/DSL/Evaluators/Contain.rb +10 -10
  46. data/lib/sapphire/DSL/Evaluators/Count.rb +8 -8
  47. data/lib/sapphire/DSL/Evaluators/Differ.rb +10 -10
  48. data/lib/sapphire/DSL/Evaluators/Exist.rb +9 -9
  49. data/lib/sapphire/DSL/Evaluators/In.rb +10 -10
  50. data/lib/sapphire/DSL/Evaluators/Selected.rb +10 -10
  51. data/lib/sapphire/DSL/Evaluators/Show.rb +10 -10
  52. data/lib/sapphire/DSL/Evaluators/Transition.rb +10 -10
  53. data/lib/sapphire/DSL/Evaluators/Validate.rb +8 -8
  54. data/lib/sapphire/DSL/Events/Data.rb +12 -0
  55. data/lib/sapphire/DSL/Events/DataSegment.rb +18 -0
  56. data/lib/sapphire/DSL/Events/Event.rb +11 -3
  57. data/lib/sapphire/DSL/Events/Expect.rb +3 -11
  58. data/lib/sapphire/DSL/Events/Expectation.rb +14 -0
  59. data/lib/sapphire/DSL/Events/For.rb +11 -0
  60. data/lib/sapphire/DSL/Events/From.rb +9 -0
  61. data/lib/sapphire/DSL/Events/Where.rb +11 -0
  62. data/lib/sapphire/DSL/Profiles/Profile.rb +26 -0
  63. data/lib/sapphire/DSL/Profiles/Table.rb +9 -0
  64. data/lib/sapphire/DSL/Scenarios/Is.rb +9 -9
  65. data/lib/sapphire/DSL/Scenarios/Pending.rb +28 -28
  66. data/lib/sapphire/DSL/Scenarios/and.rb +25 -25
  67. data/lib/sapphire/DSL/Scenarios/dsl.rb +59 -59
  68. data/lib/sapphire/DSL/Scenarios/runner.rb +40 -40
  69. data/lib/sapphire/Data.rb +1 -1
  70. data/lib/sapphire/DataAbstractions/Database.rb +57 -57
  71. data/lib/sapphire/DataAbstractions/Query.rb +20 -20
  72. data/lib/sapphire/Extensions/Class.rb +2 -2
  73. data/lib/sapphire/Extensions/Hash.rb +112 -112
  74. data/lib/sapphire/Extensions/Module.rb +11 -0
  75. data/lib/sapphire/Extensions/Numeric.rb +6 -6
  76. data/lib/sapphire/Extensions/Object.rb +4 -0
  77. data/lib/sapphire/Extensions/String.rb +30 -23
  78. data/lib/sapphire/Extensions/Symbol.rb +1 -1
  79. data/lib/sapphire/JobAbstractions/Job.rb +32 -32
  80. data/lib/sapphire/Observable.rb +87 -0
  81. data/lib/sapphire/Observers.rb +2 -0
  82. data/lib/sapphire/Observers/FailedControlHighlighter.rb +41 -0
  83. data/lib/sapphire/Observers/Highlighter.rb +40 -0
  84. data/lib/sapphire/Observers/Observer.rb +23 -0
  85. data/lib/sapphire/Observers/ObserverRepository.rb +37 -0
  86. data/lib/sapphire/Observers/PassedControlHighlighter.rb +42 -0
  87. data/lib/sapphire/Observers/VerboseObserver.rb +36 -0
  88. data/lib/sapphire/TeamCity.rb +10 -10
  89. data/lib/sapphire/Testing.rb +3 -3
  90. data/lib/sapphire/Testing/RakeTask.rb +108 -108
  91. data/lib/sapphire/Testing/ResultList.rb +18 -18
  92. data/lib/sapphire/Testing/ScenarioResult.rb +36 -36
  93. data/lib/sapphire/Testing/TestResult.rb +21 -21
  94. data/lib/sapphire/Testing/TestRunnerAdapter.rb +85 -85
  95. data/lib/sapphire/UI/ProcessBuilder.rb +173 -173
  96. data/lib/sapphire/Virtualization.rb +7 -7
  97. data/lib/sapphire/Web.rb +2 -2
  98. data/lib/sapphire/WebAbstractions/Controls/AlertBox.rb +20 -20
  99. data/lib/sapphire/WebAbstractions/Controls/Base/Control.rb +43 -26
  100. data/lib/sapphire/WebAbstractions/Controls/Button.rb +7 -7
  101. data/lib/sapphire/WebAbstractions/Controls/CheckBox.rb +3 -3
  102. data/lib/sapphire/WebAbstractions/Controls/Date.rb +11 -11
  103. data/lib/sapphire/WebAbstractions/Controls/DropDown.rb +6 -8
  104. data/lib/sapphire/WebAbstractions/Controls/Hyperlink.rb +8 -8
  105. data/lib/sapphire/WebAbstractions/Controls/Image.rb +19 -19
  106. data/lib/sapphire/WebAbstractions/Controls/Label.rb +8 -8
  107. data/lib/sapphire/WebAbstractions/Controls/List.rb +16 -16
  108. data/lib/sapphire/WebAbstractions/Controls/RadioButton.rb +2 -2
  109. data/lib/sapphire/WebAbstractions/Controls/Title.rb +12 -12
  110. data/lib/sapphire/version.rb +1 -1
  111. metadata +26 -8
@@ -0,0 +1,2 @@
1
+ require File.expand_path(File.dirname(__FILE__) +'/Observers/Observer.rb', __FILE__)
2
+ Dir[File.dirname(__FILE__) + '/Observers/*.rb'].each {|file| require file }
@@ -0,0 +1,41 @@
1
+ module Sapphire
2
+ module Observers
3
+
4
+ class FailedControlHighlighter < Observer
5
+
6
+ def initialize
7
+
8
+ observes :class => DSL::ControlEvaluation,
9
+ :method => :Failed
10
+
11
+ end
12
+
13
+ def Before(instance, method, args)
14
+ return if ENV["highlighter"] != "true"
15
+
16
+ control = args[0]
17
+ discriminator = control.found_by_type
18
+ selector = control.found_by_value
19
+
20
+ begin
21
+ if(discriminator == :id)
22
+ $driver.ExecuteScript("document.getElementById('#{selector}').style.border = '1px solid #FF0000'; ")
23
+ elsif (discriminator == :name )
24
+ $driver.ExecuteScript("document.getElementByName('#{selector}').style.border = '1px solid #FF0000'; ")
25
+ elsif (discriminator == :xpath)
26
+ $driver.ExecuteScript("document.evaluate( '#{selector}', document, null, XPathResult.ANY_TYPE, null ).iterateNext().style.border = '1px solid #FF0000'; ")
27
+ end
28
+
29
+ rescue
30
+ end
31
+
32
+ end
33
+
34
+ def self.IsObserver()
35
+ true
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ module Sapphire
2
+ module Observers
3
+
4
+ class Highlighter < Observer
5
+
6
+ def initialize
7
+
8
+ observes :class => WebAbstractions::RubySeleniumWebDriver,
9
+ :method => :FindElement
10
+
11
+ end
12
+
13
+ def Before(instance, method, args)
14
+ return if ENV["highlighter"] != "true"
15
+
16
+ discriminator = args[0]
17
+ selector = args[1]
18
+
19
+ begin
20
+ if(discriminator == :id)
21
+ instance.ExecuteScript("document.getElementById('#{selector}').style.backgroundColor = '#FFF467'; ")
22
+ elsif (discriminator == :name )
23
+ instance.ExecuteScript("document.getElementByName('#{selector}').style.backgroundColor = '#FFF467'; ")
24
+ elsif (discriminator == :xpath)
25
+ instance.ExecuteScript("document.evaluate( '#{selector}', document, null, XPathResult.ANY_TYPE, null ).iterateNext().style.backgroundColor = '#FFF467'; ")
26
+ end
27
+
28
+ rescue
29
+ end
30
+
31
+ end
32
+
33
+ def self.IsObserver()
34
+ true
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ module Sapphire
2
+ module Observers
3
+
4
+ class Observer
5
+
6
+ attr_reader :object
7
+ attr_reader :method
8
+ attr_reader :on_match
9
+
10
+ def observes(hash)
11
+ @object = hash[:class]
12
+ @method = hash[:method]
13
+ @on_match = hash[:on_match]
14
+ end
15
+
16
+ def self.observe()
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ module Sapphire
2
+ module Observers
3
+
4
+ class ObserverRepository
5
+
6
+ def self.create
7
+ @@instance ||= ObserverRepository.new
8
+ end
9
+
10
+ def self.instance
11
+ @@instance ||= self.create
12
+ end
13
+
14
+ def initialize
15
+ @observers = []
16
+ @observer_types = []
17
+ end
18
+
19
+
20
+ def Add(observer)
21
+ return if(@observer_types.include? observer.class)
22
+
23
+ @observer_types << observer.class
24
+ @observers << observer if !@observers.include? observer
25
+ end
26
+
27
+ def Find(method, object)
28
+ @observers.select {|o| ((o.object == object or o.object == :all or object < o.object) and (o.method == method or o.method == :all)) }
29
+ end
30
+
31
+ def self.observe()
32
+
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,42 @@
1
+ module Sapphire
2
+ module Observers
3
+
4
+ class PassedControlHighlighter < Observer
5
+
6
+ def initialize
7
+
8
+ observes :class => DSL::ControlEvaluation,
9
+ :method => :Passed
10
+
11
+ end
12
+
13
+ def Before(instance, method, args)
14
+ return if ENV["highlighter"] != "true"
15
+
16
+ control = args[0]
17
+
18
+ discriminator = control.found_by_type
19
+ selector = control.found_by_value
20
+
21
+ begin
22
+ if(discriminator == :id)
23
+ $driver.ExecuteScript("document.getElementById('#{selector}').style.border = '1px solid #00FF00'; ")
24
+ elsif (discriminator == :name )
25
+ $driver.ExecuteScript("document.getElementByName('#{selector}').style.border = '1px solid #00FF00'; ")
26
+ elsif (discriminator == :xpath)
27
+ $driver.ExecuteScript("document.evaluate( '#{selector}', document, null, XPathResult.ANY_TYPE, null ).iterateNext().style.border = '1px solid #00FF00'; ")
28
+ end
29
+
30
+ rescue
31
+ end
32
+
33
+ end
34
+
35
+ def self.IsObserver()
36
+ true
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,36 @@
1
+ module Sapphire
2
+ module Observers
3
+
4
+ class VerboseObserver < Observer
5
+
6
+ def initialize
7
+
8
+ observes :class => :all,
9
+ :method => :all
10
+
11
+ end
12
+
13
+ def Before(instance, method, args)
14
+ puts "before #{method} on #{instance}" if ENV["verbose"] == "true"
15
+ end
16
+
17
+ def After(instance, method, args)
18
+ puts "after" if ENV["verbose"] == "true"
19
+ end
20
+
21
+ def OnSuccess(instance, method, args)
22
+ puts "success" if ENV["verbose"] == "true"
23
+ end
24
+
25
+ def OnFailure(instance, method, exception, args)
26
+ puts "failure" if ENV["verbose"] == "true"
27
+ end
28
+
29
+ #def self.IsObserver()
30
+ # true
31
+ #end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -1,11 +1,11 @@
1
- module Sapphire
2
- module Testing
3
- module TeamCity
4
- class TeamCityReporter < Reporter
5
-
6
- end
7
- end
8
- end
9
- end
10
-
1
+ module Sapphire
2
+ module Testing
3
+ module TeamCity
4
+ class TeamCityReporter < Reporter
5
+
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
11
  Dir[File.dirname(__FILE__) + '/TeamCity/*.rb'].each {|file| require file } if ENV["TeamCity"] == "1"
@@ -1,3 +1,3 @@
1
- require File.expand_path(File.dirname(__FILE__) +'/Testing/Reporter.rb', __FILE__)
2
- Dir[File.dirname(__FILE__) + '/Testing/*.rb'].each {|file| require file }
3
- Dir[File.dirname(__FILE__) + '/Testing/Coverage/*.rb'].each {|file| require file }
1
+ require File.expand_path(File.dirname(__FILE__) +'/Testing/Reporter.rb', __FILE__)
2
+ Dir[File.dirname(__FILE__) + '/Testing/*.rb'].each {|file| require file }
3
+ Dir[File.dirname(__FILE__) + '/Testing/Coverage/*.rb'].each {|file| require file }
@@ -1,109 +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
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
109
  end