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
@@ -1,8 +1,8 @@
1
- require File.expand_path(File.dirname(__FILE__) +'/UI/ProcessBuilder.rb', File.dirname(__FILE__)) if Platform::OS == :win32
2
- require File.expand_path(File.dirname(__FILE__) +'/UI/VirtualUI.rb', File.dirname(__FILE__)) if Platform::OS == :win32
3
-
4
- module Sapphire
5
- module UI
6
-
7
- end
1
+ require File.expand_path(File.dirname(__FILE__) +'/UI/ProcessBuilder.rb', File.dirname(__FILE__)) if Platform::OS == :win32
2
+ require File.expand_path(File.dirname(__FILE__) +'/UI/VirtualUI.rb', File.dirname(__FILE__)) if Platform::OS == :win32
3
+
4
+ module Sapphire
5
+ module UI
6
+
7
+ end
8
8
  end
@@ -1,3 +1,3 @@
1
- Dir[File.dirname(__FILE__) + '/WebAbstractions/Controls/Base/*.rb'].each {|file| require file }
2
- Dir[File.dirname(__FILE__) + '/WebAbstractions/Controls/*.rb'].each {|file| require file }
1
+ Dir[File.dirname(__FILE__) + '/WebAbstractions/Controls/Base/*.rb'].each {|file| require file }
2
+ Dir[File.dirname(__FILE__) + '/WebAbstractions/Controls/*.rb'].each {|file| require file }
3
3
  Dir[File.dirname(__FILE__) + '/WebAbstractions/Browsers/*.rb'].each {|file| require file }
@@ -1,21 +1,21 @@
1
- module Sapphire
2
- module WebAbstractions
3
- class AlertBox < Control
4
- def Accept
5
- $driver.AcceptAlert
6
- end
7
-
8
- def Set(text)
9
- $driver.SetAlert(text)
10
- end
11
-
12
- def Visible()
13
- Evaluation.new($driver.AlertShown(), true)
14
- end
15
-
16
- def Find(comparator = nil)
17
- return $driver.FindAlert
18
- end
19
- end
20
- end
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class AlertBox < Control
4
+ def Accept
5
+ $driver.AcceptAlert
6
+ end
7
+
8
+ def Set(text)
9
+ $driver.SetAlert(text)
10
+ end
11
+
12
+ def Visible()
13
+ Evaluation.new($driver.AlertShown(), true)
14
+ end
15
+
16
+ def Find(comparator = nil)
17
+ return $driver.FindAlert
18
+ end
19
+ end
20
+ end
21
21
  end
@@ -1,20 +1,47 @@
1
1
  module Sapphire
2
2
  module WebAbstractions
3
3
  class Control
4
- def initialize(hash)
4
+
5
+ attr_reader :found_by_type
6
+ attr_reader :found_by_value
7
+
8
+ def initialize(args)
9
+ return if args.nil?
10
+
11
+ hash = {}
12
+ hash = args if args.is_a? Hash
13
+
14
+ args.each do |item|
15
+ hash.merge! item if item.is_a? Hash
16
+ end if args.is_a? Array
17
+
5
18
  @hash = hash
19
+ @by = hash.keys.first
20
+ @value = hash[hash.keys.first]
21
+ @control = hash.fetch :instance if hash.has_key? :instance
22
+
23
+ @found_by_type = @by
24
+ @found_by_value = @value
6
25
  end
7
26
 
8
27
  def Find(comparator = nil)
9
- $driver.FindItemWithWait(@hash, comparator)
28
+ @control ||= $driver.FindItemWithWait(@by, @value, comparator)
29
+ @control
10
30
  end
11
31
 
12
32
  def FindAll
13
- $driver.FindAllItems(@hash)
33
+ items = $driver.FindAllItems(@by, @value)
34
+ list = []
35
+ items.each do |item|
36
+ hash = {@by => @value, :instance => item}
37
+ list << Control.new(hash)
38
+ end
39
+
40
+ list
14
41
  end
15
42
 
16
43
  def FindWithoutWait(comparator = nil)
17
- $driver.FindItemWithoutWait(@hash, comparator)
44
+ $driver.FindItemWithoutWait(@by, @value, comparator)
18
45
  end
19
46
 
20
47
  def Text
@@ -28,22 +55,12 @@ module Sapphire
28
55
  end
29
56
 
30
57
  def MouseOver
31
- if @hash.is_a? Hash
32
- if(@hash.has_key?(:id))
33
- $driver.ExecuteScript("document.getElementById('"+ @hash.fetch(:id) +"').style.visibility = 'visible'; ")
34
- elsif (@hash.has_key?(:name))
35
- $driver.ExecuteScript("document.getElementByName('"+ @hash.fetch(:name) +"').style.visibility = 'visible'; ")
36
- elsif (@hash.has_key?(:xpath))
37
- $driver.ExecuteScript("document.evaluate( '" + @hash.fetch(:xpath) + "', document, null, XPathResult.ANY_TYPE, null ).iterateNext().style.visibility = 'visible'; ")
38
- end
39
- elsif @hash.is_a? Array
40
- if(@hash[0].has_key?(:id))
41
- $driver.ExecuteScript("document.getElementById('"+ @hash[0].fetch(:id) +"').style.visibility = 'visible'; ")
42
- elsif (@hash[0].has_key?(:name))
43
- $driver.ExecuteScript("document.getElementByName('"+ @hash[0].fetch(:name) +"').style.visibility = 'visible'; ")
44
- elsif (@hash[0].has_key?(:xpath))
45
- $driver.ExecuteScript("document.evaluate( '" + @hash[0].fetch(:xpath) + "', document, null, XPathResult.ANY_TYPE, null ).iterateNext().style.visibility = 'visible'; ")
46
- end
58
+ if(@by == :id)
59
+ $driver.ExecuteScript("document.getElementById('"+ @value +"').style.visibility = 'visible'; ")
60
+ elsif (@by == :name)
61
+ $driver.ExecuteScript("document.getElementByName('"+ @value +"').style.visibility = 'visible'; ")
62
+ elsif (@by == :xpath)
63
+ $driver.ExecuteScript("document.evaluate( '" + @value + "', document, null, XPathResult.ANY_TYPE, null ).iterateNext().style.visibility = 'visible'; ")
47
64
  end
48
65
 
49
66
  sleep(1)
@@ -52,28 +69,28 @@ module Sapphire
52
69
  def Visible(shouldWait = true)
53
70
  control = self.Find if shouldWait
54
71
  control = self.FindWithoutWait if !shouldWait
55
- Evaluation.new(control.displayed?, true)
72
+ ControlEvaluation.new(control.displayed?, true, self)
56
73
  end
57
74
 
58
75
  def Equals(value, comparator)
59
- evaluation = Evaluation.new(self.Text, value)
76
+ evaluation = ControlEvaluation.new(self.Text, value, self)
60
77
  EqualsComparison.new(evaluation)
61
78
  end
62
79
 
63
80
  def Contain(value)
64
- return ContainsComparison.new(Evaluation.new(value, self.Text))
81
+ return ContainsComparison.new(ControlEvaluation.new(value, self.Text, self))
65
82
  end
66
83
 
67
84
  def In(values, comparator)
68
85
  text = self.Text
69
86
  values.each do |value|
70
87
  if comparator.Compare(text, value)
71
- return Evaluation.new(text, value)
88
+ return ControlEvaluation.new(text, value, self)
72
89
  end
73
90
  end
74
91
 
75
92
  #error land
76
- return Evaluation.new(text, values)
93
+ return ControlEvaluation.new(text, values, self)
77
94
  end
78
95
 
79
96
  def Evaluate(key, arg, comparator, block)
@@ -96,7 +113,7 @@ module Sapphire
96
113
 
97
114
  return result
98
115
  rescue
99
- return Evaluation.new(evaluation.left, evaluation.right)
116
+ return ControlEvaluation.new(evaluation.left, evaluation.right, self)
100
117
  end
101
118
  end
102
119
 
@@ -1,7 +1,7 @@
1
- module Sapphire
2
- module WebAbstractions
3
- class Button < Control
4
- end
5
- end
6
- end
7
-
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class Button < Control
4
+ end
5
+ end
6
+ end
7
+
@@ -5,11 +5,11 @@ module Sapphire
5
5
  checked = self.Checked().Evaluate()
6
6
 
7
7
  if value && checked
8
- return;
8
+ return
9
9
  end
10
10
 
11
11
  if !value && !checked
12
- return;
12
+ return
13
13
  end
14
14
 
15
15
  self.Click
@@ -17,7 +17,7 @@ module Sapphire
17
17
 
18
18
  def Checked
19
19
  radio = self.Find
20
- Evaluation.new(radio.attribute("checked") != nil, true)
20
+ ControlEvaluation.new(radio.attribute("checked") != nil, true, self)
21
21
  end
22
22
 
23
23
  def Clear
@@ -1,12 +1,12 @@
1
- module Sapphire
2
- module WebAbstractions
3
- class Date < Control
4
-
5
- def Text
6
- control = self.Find
7
- return DateTime.strptime(control.text, "%m/%d/%Y %H:%M:%S %p").to_date
8
- end
9
-
10
- end
11
- end
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class Date < Control
4
+
5
+ def Text
6
+ control = self.Find
7
+ return DateTime.strptime(control.text, "%m/%d/%Y %H:%M:%S %p").to_date
8
+ end
9
+
10
+ end
11
+ end
12
12
  end
@@ -31,25 +31,23 @@ module Sapphire
31
31
  items = ddl.find_elements(:tag_name, "option")
32
32
  items.each do |item|
33
33
  if item.text == value
34
- return Evaluation.new(item.text, value)
34
+ return ControlEvaluation.new(item.text, value, self)
35
35
  end
36
36
  end
37
37
 
38
- return Evaluation.new("Value not found in list", value)
38
+ return ControlEvaluation.new("Value not found in list", value, self)
39
39
  end
40
40
 
41
41
  def Count(value)
42
42
  ddl = self.Find
43
43
  items = ddl.find_elements(:tag_name, "option")
44
- return Evaluation.new(items.count, value)
44
+ return ControlEvaluation.new(items.count, value, self)
45
45
  end
46
46
 
47
47
  def Clear
48
- @hash.each do |item|
49
- if item.has_key? :default
50
- self.Set(item[:default])
51
- return
52
- end
48
+ if @hash.has_key? :default
49
+ self.Set(@hash[:default])
50
+ return
53
51
  end
54
52
 
55
53
  raise "no :default set for DropDown"
@@ -1,8 +1,8 @@
1
- module Sapphire
2
- module WebAbstractions
3
- class Hyperlink < Control
4
-
5
- end
6
- end
7
- end
8
-
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class Hyperlink < Control
4
+
5
+ end
6
+ end
7
+ end
8
+
@@ -1,19 +1,19 @@
1
- module Sapphire
2
- module WebAbstractions
3
- class Image < Control
4
- def Source(value, comparator)
5
- image = self.Find
6
- evaluation = Evaluation.new(image.attribute("src"), value)
7
- EqualsComparison.new(evaluation)
8
- end
9
-
10
- def AltText(value, comparator)
11
- image = self.Find
12
- evaluation = Evaluation.new(image.attribute("alt"), value)
13
- EqualsComparison.new(evaluation)
14
- end
15
- end
16
- end
17
- end
18
-
19
-
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class Image < Control
4
+ def Source(value, comparator)
5
+ image = self.Find
6
+ evaluation = ControlEvaluation.new(image.attribute("src"), value, self)
7
+ EqualsComparison.new(evaluation)
8
+ end
9
+
10
+ def AltText(value, comparator)
11
+ image = self.Find
12
+ evaluation = ControlEvaluation.new(image.attribute("alt"), value, self)
13
+ EqualsComparison.new(evaluation)
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+
@@ -1,8 +1,8 @@
1
- module Sapphire
2
- module WebAbstractions
3
- class Label < Control
4
-
5
- end
6
- end
7
- end
8
-
1
+ module Sapphire
2
+ module WebAbstractions
3
+ class Label < Control
4
+
5
+ end
6
+ end
7
+ end
8
+
@@ -3,33 +3,33 @@ module Sapphire
3
3
  class List < Control
4
4
 
5
5
  def initialize(hash)
6
- @hash = hash
7
6
  @retryAttempts = 0
7
+ super hash
8
8
  end
9
9
 
10
10
  def Equals(value, comparator)
11
11
  x = self.FindAll
12
12
  x.each do |item|
13
- if comparator.Compare(item.text, value)
14
- return EqualsComparison.new(Evaluation.new(item.text, value))
13
+ if comparator.Compare(item.Text, value)
14
+ return EqualsComparison.new(ControlEvaluation.new(item.Text, value, item))
15
15
  end
16
16
  end
17
17
 
18
18
  #if here then it couldnt make a match, build up the list of values
19
19
  alltext = []
20
20
  x.each do |item|
21
- alltext << item.text
21
+ alltext << item.Text
22
22
  end
23
23
 
24
- return EqualsComparison.new(Evaluation.new(alltext, value))
24
+ return EqualsComparison.new(ControlEvaluation.new(alltext, value, self))
25
25
  end
26
26
 
27
27
  def In(values, comparator)
28
28
  x = self.FindAll
29
29
  x.each do |item|
30
30
  values.each do |value|
31
- if comparator.Compare(item.text, value)
32
- return Evaluation.new(item.text, value)
31
+ if comparator.Compare(item.Text, value)
32
+ return ControlEvaluation.new(item.Text, value, item)
33
33
  end
34
34
  end
35
35
  end
@@ -37,21 +37,21 @@ module Sapphire
37
37
  #if here then it couldnt make a match, build up the list of values
38
38
  alltext = []
39
39
  x.each do |item|
40
- alltext << item.text
40
+ alltext << item.Text
41
41
  end
42
42
 
43
- return Evaluation.new(values, alltext)
43
+ return ControlEvaluation.new(values, alltext, self)
44
44
  end
45
45
 
46
46
  def Contain(value)
47
47
  x = self.FindAll
48
48
  x.each do |item|
49
- if item.text.include? value
50
- return ContainsComparison.new(Evaluation.new(value, item.text))
49
+ if item.Text.include? value
50
+ return ContainsComparison.new(ControlEvaluation.new(value, item.Text, item))
51
51
  end
52
52
  end
53
53
 
54
- return Evaluation.new("Value not found in list", value)
54
+ return ControlEvaluation.new("Value not found in list", value, self)
55
55
  end
56
56
 
57
57
  def Click
@@ -59,8 +59,8 @@ module Sapphire
59
59
  begin
60
60
  clicked = wait.until { items = self.FindAll
61
61
  if items.empty? == false
62
- if items.first.displayed? == true
63
- items.first.click
62
+ if items.first.Visible == true
63
+ items.first.Click
64
64
  return true
65
65
  end
66
66
  end
@@ -80,14 +80,14 @@ module Sapphire
80
80
 
81
81
  def Count(value)
82
82
  items = self.FindAll
83
- return Evaluation.new(items.count, value)
83
+ return ControlEvaluation.new(items.count, value, self)
84
84
  end
85
85
 
86
86
  def Text
87
87
  values = []
88
88
  x = self.FindAll
89
89
  x.each do |item|
90
- values << item.text
90
+ values << item.Text
91
91
  end
92
92
 
93
93
  return values