sapphire 0.6.7 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/lib/sapphire.rb +3 -2
  2. data/lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb +43 -27
  3. data/lib/sapphire/Configuration/AppConfig.rb +1 -1
  4. data/lib/sapphire/DSL.rb +6 -1
  5. data/lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb +6 -20
  6. data/lib/sapphire/DSL/Browser/Fluff/Be.rb +10 -0
  7. data/lib/sapphire/DSL/Browser/Fluff/By.rb +2 -2
  8. data/lib/sapphire/DSL/Browser/Fluff/Have.rb +10 -0
  9. data/lib/sapphire/DSL/Browser/Fluff/To.rb +2 -2
  10. data/lib/sapphire/DSL/Browser/For.rb +9 -10
  11. data/lib/sapphire/DSL/Browser/Nouns/Browser.rb +2 -2
  12. data/lib/sapphire/DSL/Browser/Nouns/Day.rb +42 -24
  13. data/lib/sapphire/DSL/Browser/Nouns/Enter.rb +1 -1
  14. data/lib/sapphire/DSL/Browser/Nouns/Month.rb +42 -24
  15. data/lib/sapphire/DSL/Browser/Nouns/Popup.rb +2 -2
  16. data/lib/sapphire/DSL/Browser/Nouns/Second.rb +42 -0
  17. data/lib/sapphire/DSL/Browser/Should.rb +1 -46
  18. data/lib/sapphire/DSL/Browser/Verbs/Accept.rb +1 -2
  19. data/lib/sapphire/DSL/Browser/Verbs/Check.rb +0 -1
  20. data/lib/sapphire/DSL/Browser/Verbs/Click.rb +0 -1
  21. data/lib/sapphire/DSL/Browser/Verbs/Compare.rb +5 -5
  22. data/lib/sapphire/DSL/Browser/Verbs/Complete.rb +2 -2
  23. data/lib/sapphire/DSL/Browser/Verbs/Disable.rb +1 -1
  24. data/lib/sapphire/DSL/Browser/Verbs/Exists.rb +6 -11
  25. data/lib/sapphire/DSL/Browser/Verbs/{Close.rb → Exit.rb} +0 -0
  26. data/lib/sapphire/DSL/Browser/Verbs/Has.rb +9 -0
  27. data/lib/sapphire/DSL/Browser/Verbs/MouseOver.rb +0 -1
  28. data/lib/sapphire/DSL/Browser/Verbs/Navigate.rb +1 -2
  29. data/lib/sapphire/DSL/Browser/Verbs/On.rb +19 -0
  30. data/lib/sapphire/DSL/Browser/Verbs/Press.rb +1 -1
  31. data/lib/sapphire/DSL/Browser/Verbs/Reload.rb +1 -1
  32. data/lib/sapphire/DSL/Browser/Verbs/Remove.rb +22 -0
  33. data/lib/sapphire/DSL/Browser/Verbs/Set.rb +1 -1
  34. data/lib/sapphire/DSL/Browser/Verbs/Start.rb +14 -16
  35. data/lib/sapphire/DSL/Browser/Verbs/Uncheck.rb +0 -1
  36. data/lib/sapphire/DSL/Comparisons/CheckedComparison.rb +17 -0
  37. data/lib/sapphire/DSL/Comparisons/Comparison.rb +34 -0
  38. data/lib/sapphire/DSL/Comparisons/ContainsComparison.rb +17 -0
  39. data/lib/sapphire/DSL/Comparisons/DifferComparison.rb +17 -0
  40. data/lib/sapphire/DSL/Comparisons/EqualsComparison.rb +16 -0
  41. data/lib/sapphire/DSL/Comparisons/NotComparison.rb +21 -0
  42. data/lib/sapphire/DSL/Comparisons/SelectedComparison.rb +17 -0
  43. data/lib/sapphire/DSL/Comparisons/StartsWithComparison.rb +17 -0
  44. data/lib/sapphire/DSL/Comparisons/VisibleComparison.rb +17 -0
  45. data/lib/sapphire/DSL/Configuration/Use.rb +3 -0
  46. data/lib/sapphire/DSL/Data/GetPageField.rb +4 -8
  47. data/lib/sapphire/DSL/Evaluations/Evaluation.rb +46 -0
  48. data/lib/sapphire/DSL/Evaluations/FieldNotDefinedEvaluation.rb +21 -0
  49. data/lib/sapphire/DSL/Evaluations/FieldNotFoundEvaluation.rb +21 -0
  50. data/lib/sapphire/DSL/Evaluators/AltText.rb +17 -0
  51. data/lib/sapphire/DSL/Evaluators/Checked.rb +17 -0
  52. data/lib/sapphire/DSL/Evaluators/Contain.rb +10 -0
  53. data/lib/sapphire/DSL/Evaluators/Count.rb +9 -0
  54. data/lib/sapphire/DSL/Evaluators/Differ.rb +10 -0
  55. data/lib/sapphire/DSL/Evaluators/Evaluator.rb +22 -0
  56. data/lib/sapphire/DSL/Evaluators/Exist.rb +9 -0
  57. data/lib/sapphire/DSL/Evaluators/In.rb +10 -0
  58. data/lib/sapphire/DSL/Evaluators/Selected.rb +10 -0
  59. data/lib/sapphire/DSL/Evaluators/Show.rb +10 -0
  60. data/lib/sapphire/DSL/Evaluators/Source.rb +17 -0
  61. data/lib/sapphire/DSL/Evaluators/Transition.rb +10 -0
  62. data/lib/sapphire/DSL/Evaluators/Validate.rb +8 -0
  63. data/lib/sapphire/DSL/Events/Causes.rb +3 -0
  64. data/lib/sapphire/DSL/Events/Event.rb +19 -0
  65. data/lib/sapphire/DSL/Events/Expect.rb +19 -0
  66. data/lib/sapphire/DSL/Scenarios/then.rb +1 -1
  67. data/lib/sapphire/DSL/Scenarios/when.rb +1 -1
  68. data/lib/sapphire/DSL/TestPlans/FileHandler.rb +7 -2
  69. data/lib/sapphire/DSL/TestPlans/PathHandler.rb +2 -1
  70. data/lib/sapphire/DataAbstractions/NonQuery.rb +2 -1
  71. data/lib/sapphire/DataAbstractions/Query.rb +2 -1
  72. data/lib/sapphire/Extensions.rb +1 -0
  73. data/lib/sapphire/{DSL/Browser/Extensions → Extensions}/Class.rb +10 -0
  74. data/lib/sapphire/Extensions/Hash.rb +85 -0
  75. data/lib/sapphire/{DSL/Browser/Extensions → Extensions}/Numeric.rb +6 -6
  76. data/lib/sapphire/Extensions/Object.rb +9 -0
  77. data/lib/sapphire/{DSL/Browser/Extensions → Extensions}/String.rb +4 -0
  78. data/lib/sapphire/Extensions/Symbol.rb +105 -0
  79. data/lib/sapphire/Sessions/Parameter.rb +36 -0
  80. data/lib/sapphire/Sessions/Storage.rb +17 -0
  81. data/lib/sapphire/UI/Functions.rb +2 -1
  82. data/lib/sapphire/UI/ProcessBuilder.rb +174 -0
  83. data/lib/sapphire/Virtualization.rb +1 -1
  84. data/lib/sapphire/WebAbstractions/Browsers/Chrome.rb +22 -21
  85. data/lib/sapphire/WebAbstractions/Browsers/FireFox.rb +24 -22
  86. data/lib/sapphire/WebAbstractions/Browsers/InternetExplorer.rb +22 -21
  87. data/lib/sapphire/WebAbstractions/Controls/AlertBox.rb +21 -0
  88. data/lib/sapphire/WebAbstractions/Controls/Base/Control.rb +32 -14
  89. data/lib/sapphire/WebAbstractions/Controls/Base/Page.rb +74 -65
  90. data/lib/sapphire/WebAbstractions/Controls/CheckBox.rb +29 -28
  91. data/lib/sapphire/WebAbstractions/Controls/DropDown.rb +59 -26
  92. data/lib/sapphire/WebAbstractions/Controls/Image.rb +10 -0
  93. data/lib/sapphire/WebAbstractions/Controls/List.rb +45 -4
  94. data/lib/sapphire/WebAbstractions/Controls/RadioButton.rb +29 -18
  95. data/lib/sapphire/WebAbstractions/Controls/TextBox.rb +9 -8
  96. data/lib/sapphire/WebAbstractions/Controls/Title.rb +1 -1
  97. data/lib/sapphire/version.rb +1 -1
  98. metadata +55 -39
  99. data/lib/sapphire/Configuration/SapphireConfig.rb +0 -33
  100. data/lib/sapphire/DSL/Browser/Extensions/Hash.rb +0 -11
  101. data/lib/sapphire/DSL/Browser/Extensions/Symbol.rb +0 -37
  102. data/lib/sapphire/DSL/Browser/Not.rb +0 -39
  103. data/lib/sapphire/DSL/Browser/Nouns/AlertBox.rb +0 -15
  104. data/lib/sapphire/DSL/Browser/Verbs/Attempt.rb +0 -14
  105. data/lib/sapphire/DSL/Browser/Verbs/Contain.rb +0 -25
  106. data/lib/sapphire/DSL/Browser/Verbs/Count.rb +0 -24
  107. data/lib/sapphire/DSL/Browser/Verbs/Differ.rb +0 -19
  108. data/lib/sapphire/DSL/Browser/Verbs/Error.rb +0 -25
  109. data/lib/sapphire/DSL/Browser/Verbs/Hide.rb +0 -25
  110. data/lib/sapphire/DSL/Browser/Verbs/Show.rb +0 -25
  111. data/lib/sapphire/DSL/Browser/Verbs/Transition.rb +0 -25
  112. data/lib/sapphire/DSL/Data/Exist.rb +0 -26
  113. data/lib/sapphire/DSL/Data/Validate.rb +0 -25
  114. data/lib/sapphire/Strategies.rb +0 -2
  115. data/lib/sapphire/Strategies/ClassStrategy.rb +0 -13
  116. data/lib/sapphire/Strategies/ContainsEvaluation.rb +0 -16
  117. data/lib/sapphire/Strategies/ContainsNullModifier.rb +0 -34
  118. data/lib/sapphire/Strategies/DefaultStrategy.rb +0 -17
  119. data/lib/sapphire/Strategies/Evaluation.rb +0 -16
  120. data/lib/sapphire/Strategies/HashStrategy.rb +0 -72
  121. data/lib/sapphire/Strategies/NullModifier.rb +0 -34
  122. data/lib/sapphire/Strategies/Strategy.rb +0 -11
  123. data/lib/sapphire/Strategies/SymbolStrategy.rb +0 -59
  124. data/lib/sapphire/WebAbstractions/Controls/TableCell.rb +0 -10
@@ -3,11 +3,11 @@ module Sapphire
3
3
  module Browser
4
4
  class Popup
5
5
  def Close
6
- $browser.ClosePopup
6
+ $driver.ClosePopup
7
7
  end
8
8
 
9
9
  def Switch
10
- $browser.SwitchToPopup
10
+ $driver.SwitchToPopup
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,42 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Second(value)
5
+ second = Second.new(value, $compare1, $compare2)
6
+ $compare1 = nil
7
+ $compare2 = nil
8
+ return second
9
+ end
10
+
11
+ class Second
12
+
13
+ def initialize(value, compare1, compare2)
14
+ @value = value
15
+ if(compare1.is_a?(String))
16
+ @compare1 = Time.parse(compare1)
17
+ else
18
+ @compare1 = compare1
19
+ end
20
+
21
+ if(compare2.is_a?(String))
22
+ @compare2 = Time.parse(compare2)
23
+ else
24
+ @compare2 = compare2
25
+ end
26
+ end
27
+
28
+ def Differ(comparator)
29
+ return Fix(DifferComparison.new(Evaluation.new(@compare1.sec + @value, @compare2.sec)), comparator)
30
+ end
31
+
32
+ def Fix(evaluation, comparator)
33
+ comparator = comparator.Create(evaluation)
34
+
35
+ comparator
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -3,52 +3,7 @@ module Sapphire
3
3
  module Browser
4
4
  def Should(item)
5
5
  results = item.execute()
6
-
7
- if results.is_a? Hash
8
- @page = results[:page] if results[:page] != nil
9
- value = results[:value]
10
- modifier = results[:modifier]
11
-
12
- if value.is_a? Hash
13
- @page = value[:page] if value[:page] != nil
14
- sub_value = value[:value]
15
- modifier.Evaluate(sub_value)
16
- return
17
- end
18
- modifier.Evaluate(value)
19
-
20
- return
21
- end
22
-
23
- if(results.is_a? Evaluation)
24
- if(results.left != results.right)
25
- messages = []
26
-
27
- messages << "expected: (nil)" if results.left == nil
28
- messages << "expected: " + results.left.to_s if results.left != nil
29
- messages << "got: (nil)" if results.right == nil
30
- messages << "got: " + results.right.to_s if results.right != nil
31
-
32
- raise ExpectationException.new(messages)
33
- end
34
- return
35
- end
36
-
37
- if(results.is_a? ContainsEvaluation)
38
- if(!results.left.include? results.right)
39
- messages = []
40
-
41
- messages << "expected to contain: (nil)" if results.left == nil
42
- messages << "expected to contain: " + results.left.to_s if results.left != nil
43
- messages << "got: (nil)" if results.right == nil
44
- messages << "got: " + results.right.to_s if results.right != nil
45
-
46
- raise ExpectationException.new(messages)
47
- end
48
- return
49
- end
50
-
51
- raise "Cannot act upon result " + results.to_s + " for page " + @page.to_s
6
+ results.Output()
52
7
  end
53
8
  end
54
9
  end
@@ -2,8 +2,7 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Accept(item)
5
- x = item.new
6
- x.Accept
5
+ item.Accept
7
6
  end
8
7
  end
9
8
  end
@@ -2,7 +2,6 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Check(item)
5
- item.With(:page => @page)
6
5
  item.Check
7
6
  end
8
7
  end
@@ -2,7 +2,6 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Click(item)
5
- item.With(:page => @page)
6
5
  item.Click
7
6
  end
8
7
  end
@@ -3,16 +3,16 @@ module Sapphire
3
3
  module Browser
4
4
  def Compare(control1, control2, &block)
5
5
  if(control1.is_a? Symbol)
6
- control1text = GetPageField(control1).Text
6
+ $compare1 = GetPageField(control1).Text
7
7
  else
8
- control1text = control1
8
+ $compare1 = control1
9
9
  end
10
10
  if(control2.is_a? Symbol)
11
- control2text = GetPageField(control2).Text
11
+ $compare2 = GetPageField(control2).Text
12
12
  else
13
- control2text = control2
13
+ $compare2 = control2
14
14
  end
15
- block.call(control1text, control2text)
15
+ block.call()
16
16
  end
17
17
  end
18
18
  end
@@ -4,9 +4,9 @@ module Sapphire
4
4
  def Complete(page)
5
5
  if(page.is_a? Class)
6
6
  temp = page.new
7
- @page = temp.Complete
7
+ temp.Complete
8
8
  else
9
- @page = page.Complete
9
+ page.Complete
10
10
  end
11
11
  end
12
12
  end
@@ -2,7 +2,7 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Disable(args)
5
- return Hide(args)
5
+ return Not Show(args)
6
6
  end
7
7
  end
8
8
  end
@@ -2,19 +2,14 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Exists(symbol)
5
- @page.fields.each do |field|
6
- field.keys.each do |field_key|
7
- if(field_key == symbol)
8
- begin
9
- x = field[field_key].FindWithoutWait
10
- return x.displayed?
11
- rescue
12
- return false
13
- end
14
- end
5
+ if($page.Contains symbol)
6
+ begin
7
+ x = $page.Get(symbol).FindWithoutWait
8
+ return x.displayed?
9
+ rescue
10
+ return false
15
11
  end
16
12
  end
17
- false
18
13
  end
19
14
  end
20
15
  end
@@ -0,0 +1,9 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Has(page)
5
+ return !page.nil? && !page.empty?
6
+ end
7
+ end
8
+ end
9
+ end
@@ -2,7 +2,6 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def MouseOver(item)
5
- item.With(:page => @page)
6
5
  item.MouseOver
7
6
  end
8
7
  end
@@ -2,8 +2,7 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Navigate(page)
5
- @page = $browser.NavigateTo(page)
6
- @page.Init
5
+ $driver.NavigateTo(page)
7
6
  end
8
7
  end
9
8
  end
@@ -0,0 +1,19 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def On(page)
5
+ page = page.new if page.is_a? Class
6
+ found = $driver.CurrentUrl.upcase.start_with?(page.Url.upcase)
7
+ if(found == false)
8
+ page.AlternateUrls.each do |url|
9
+ if( found == false)
10
+ found = $driver.CurrentUrl.upcase.start_with?(url.upcase)
11
+ end
12
+ end
13
+ end
14
+
15
+ return found
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,7 +2,7 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Press(item)
5
- item.Press
5
+ item.Press(item)
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Reload(item)
5
- $browser.Reload
5
+ $driver.Reload
6
6
  Should Show item
7
7
  end
8
8
  end
@@ -0,0 +1,22 @@
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Remove(item)
5
+ ExecuteHashAgainstControl(item) do |control, arg|
6
+ wait = Selenium::WebDriver::Wait.new(:timeout => 5)
7
+ begin
8
+ evaluation = wait.until { x = control
9
+ val = x.Text
10
+ arr = item[item.keys.first]
11
+ arr.delete(val)
12
+ return nil
13
+ }
14
+ rescue
15
+ puts "Cant find item!"
16
+ return nil
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -2,9 +2,9 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Set(hash)
5
- hash.With(:page => @page)
6
5
  hash.Set hash
7
6
  end
7
+ #alias :Set :Verb
8
8
  end
9
9
  end
10
10
  end
@@ -1,16 +1,14 @@
1
- module Sapphire
2
- module DSL
3
- module Browser
4
- def Start(browser)
5
- if(browser == ConfigurationBrowser)
6
- AppConfig.Current.Browser
7
- else
8
- browser.new
9
- end
10
-
11
- $browser.SetRootUrl(@rootUrl)
12
- end
13
- end
14
- end
15
- end
16
-
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Start(browser)
5
+ if(browser == ConfigurationBrowser)
6
+ return AppConfig.Current.Browser if AppConfig.Current
7
+ raise "No App Config defined!"
8
+ end
9
+ $driver.SetRootUrl(@rootUrl)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -2,7 +2,6 @@ module Sapphire
2
2
  module DSL
3
3
  module Browser
4
4
  def Uncheck(item)
5
- item.With(:page => @page)
6
5
  item.Uncheck
7
6
  end
8
7
  end
@@ -0,0 +1,17 @@
1
+ module Sapphire
2
+ module DSL
3
+ class CheckedComparison < Comparison
4
+
5
+ def Compare(left, right)
6
+ return @comparator.Compare(left.Checked, true) if @comparator != nil
7
+ left.Checked
8
+ end
9
+
10
+ def Text
11
+ return @comparator.Text + " to be checked" if @comparator != nil
12
+ " to be checked"
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ module Sapphire
2
+ module DSL
3
+ class Comparison
4
+
5
+ attr_reader :item
6
+
7
+ def initialize(item)
8
+ @item = item
9
+ @item.CompareWith(self) if @item.is_a? Evaluation or @item.is_a? Evaluator or @item.is_a? Comparison
10
+ end
11
+
12
+ def CompareWith(item)
13
+ @comparator = item
14
+ end
15
+
16
+ def Create(item)
17
+ return self.class.new(item) if item.is_a? Comparison or item.is_a? Evaluation
18
+ item
19
+ end
20
+
21
+ def Output()
22
+ @item.Output
23
+ end
24
+
25
+ def Evaluate()
26
+ @item.Evaluate
27
+ end
28
+
29
+ def execute
30
+ @item.execute
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ module Sapphire
2
+ module DSL
3
+ class ContainsComparison < Comparison
4
+
5
+ def Compare(left, right)
6
+ return @comparator.Compare((right.include? left), true) if @comparator != nil
7
+ right.include? left
8
+ end
9
+
10
+ def Text
11
+ return @comparator.Text + " to contain" if @comparator != nil
12
+ " to contain"
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Sapphire
2
+ module DSL
3
+ class DifferComparison < Comparison
4
+
5
+ def Compare(left, right)
6
+ return @comparator.Compare((right == left), true) if @comparator != nil
7
+ right == left
8
+ end
9
+
10
+ def Text
11
+ return @comparator.Text + "" if @comparator != nil
12
+ ""
13
+ end
14
+
15
+ end
16
+ end
17
+ end