sapphire 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/lib/sapphire.rb +38 -37
  2. data/lib/sapphire/Adapters.rb +1 -0
  3. data/lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb +190 -0
  4. data/lib/sapphire/DSL.rb +6 -6
  5. data/lib/sapphire/DSL/Browser/Accept.rb +9 -9
  6. data/lib/sapphire/DSL/Browser/AlertBox.rb +14 -19
  7. data/lib/sapphire/DSL/Browser/Browser.rb +17 -17
  8. data/lib/sapphire/DSL/Browser/By.rb +10 -10
  9. data/lib/sapphire/DSL/Browser/Check.rb +12 -12
  10. data/lib/sapphire/DSL/Browser/Clear.rb +12 -12
  11. data/lib/sapphire/DSL/Browser/Click.rb +12 -12
  12. data/lib/sapphire/DSL/Browser/Close.rb +12 -12
  13. data/lib/sapphire/DSL/Browser/Compare.rb +18 -18
  14. data/lib/sapphire/DSL/Browser/Complete.rb +15 -15
  15. data/lib/sapphire/DSL/Browser/CurrentUrl.rb +11 -11
  16. data/lib/sapphire/DSL/Browser/Day.rb +24 -24
  17. data/lib/sapphire/DSL/Browser/Differ.rb +18 -18
  18. data/lib/sapphire/DSL/Browser/Error.rb +26 -26
  19. data/lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb +45 -45
  20. data/lib/sapphire/DSL/Browser/Exists.rb +22 -22
  21. data/lib/sapphire/DSL/Browser/For.rb +10 -10
  22. data/lib/sapphire/DSL/Browser/Hide.rb +26 -26
  23. data/lib/sapphire/DSL/Browser/IsHidden.rb +10 -10
  24. data/lib/sapphire/DSL/Browser/IsVisible.rb +33 -33
  25. data/lib/sapphire/DSL/Browser/Keys/Enter.rb +10 -10
  26. data/lib/sapphire/DSL/Browser/Month.rb +24 -24
  27. data/lib/sapphire/DSL/Browser/MouseOver.rb +12 -12
  28. data/lib/sapphire/DSL/Browser/Navigate.rb +11 -11
  29. data/lib/sapphire/DSL/Browser/Popup.rb +2 -4
  30. data/lib/sapphire/DSL/Browser/Press.rb +10 -10
  31. data/lib/sapphire/DSL/Browser/Reload.rb +11 -11
  32. data/lib/sapphire/DSL/Browser/Set.rb +18 -18
  33. data/lib/sapphire/DSL/Browser/Should.rb +42 -42
  34. data/lib/sapphire/DSL/Browser/Show.rb +26 -26
  35. data/lib/sapphire/DSL/Browser/Start.rb +16 -16
  36. data/lib/sapphire/DSL/Browser/To.rb +10 -10
  37. data/lib/sapphire/DSL/Browser/Tracker.rb +15 -15
  38. data/lib/sapphire/DSL/Browser/Transition.rb +26 -26
  39. data/lib/sapphire/DSL/Browser/Uncheck.rb +12 -12
  40. data/lib/sapphire/DSL/Browser/With.rb +10 -10
  41. data/lib/sapphire/DSL/Configuration/ConfiguredBrowser.rb +12 -12
  42. data/lib/sapphire/DSL/Configuration/ConfiguredUser.rb +10 -10
  43. data/lib/sapphire/DSL/Configuration/Use.rb +15 -15
  44. data/lib/sapphire/DSL/Data/Exist.rb +27 -27
  45. data/lib/sapphire/DSL/Data/Find.rb +10 -10
  46. data/lib/sapphire/DSL/Data/GetPageField.rb +17 -17
  47. data/lib/sapphire/DSL/Data/Underscore.rb +8 -8
  48. data/lib/sapphire/DSL/Data/Validate.rb +26 -26
  49. data/lib/sapphire/DSL/Data/Verify.rb +10 -10
  50. data/lib/sapphire/DSL/Scenarios/Is.rb +9 -9
  51. data/lib/sapphire/DSL/Scenarios/Pending.rb +28 -28
  52. data/lib/sapphire/DSL/Scenarios/and.rb +25 -25
  53. data/lib/sapphire/DSL/Scenarios/background.rb +33 -33
  54. data/lib/sapphire/DSL/Scenarios/dsl.rb +59 -59
  55. data/lib/sapphire/DSL/Scenarios/finally.rb +33 -33
  56. data/lib/sapphire/DSL/Scenarios/given.rb +57 -57
  57. data/lib/sapphire/DSL/Scenarios/runner.rb +40 -40
  58. data/lib/sapphire/DSL/Scenarios/scenario.rb +53 -53
  59. data/lib/sapphire/DSL/Scenarios/then.rb +34 -34
  60. data/lib/sapphire/DSL/Scenarios/when.rb +47 -47
  61. data/lib/sapphire/Data.rb +1 -1
  62. data/lib/sapphire/DataAbstractions/Database.rb +57 -57
  63. data/lib/sapphire/DataAbstractions/Query.rb +19 -19
  64. data/lib/sapphire/JobAbstractions/Job.rb +32 -32
  65. data/lib/sapphire/Strategies.rb +1 -1
  66. data/lib/sapphire/TeamCity.rb +8 -8
  67. data/lib/sapphire/Testing.rb +2 -2
  68. data/lib/sapphire/Testing/Executable.rb +30 -30
  69. data/lib/sapphire/Testing/RakeTask.rb +108 -108
  70. data/lib/sapphire/Testing/ResultList.rb +18 -18
  71. data/lib/sapphire/Testing/ResultTree.rb +44 -44
  72. data/lib/sapphire/Testing/ScenarioResult.rb +36 -36
  73. data/lib/sapphire/Testing/TestResult.rb +21 -21
  74. data/lib/sapphire/Testing/TestRunnerAdapter.rb +69 -69
  75. data/lib/sapphire/Virtualization.rb +7 -7
  76. data/lib/sapphire/Web.rb +3 -6
  77. data/lib/sapphire/WebAbstractions/{Controls/Browsers → Browsers}/Chrome.rb +21 -21
  78. data/lib/sapphire/WebAbstractions/{Controls/Browsers → Browsers}/FireFox.rb +22 -22
  79. data/lib/sapphire/WebAbstractions/{Controls/Browsers → Browsers}/InternetExplorer.rb +21 -21
  80. data/lib/sapphire/WebAbstractions/Controls/Base/Control.rb +59 -99
  81. data/lib/sapphire/WebAbstractions/Controls/Base/Page.rb +62 -62
  82. data/lib/sapphire/WebAbstractions/Controls/Button.rb +9 -9
  83. data/lib/sapphire/WebAbstractions/Controls/CheckBox.rb +28 -28
  84. data/lib/sapphire/WebAbstractions/Controls/Date.rb +11 -11
  85. data/lib/sapphire/WebAbstractions/Controls/DropDown.rb +26 -26
  86. data/lib/sapphire/WebAbstractions/Controls/Hyperlink.rb +8 -8
  87. data/lib/sapphire/WebAbstractions/Controls/Image.rb +9 -9
  88. data/lib/sapphire/WebAbstractions/Controls/Label.rb +8 -8
  89. data/lib/sapphire/WebAbstractions/Controls/RadioButton.rb +18 -18
  90. data/lib/sapphire/WebAbstractions/Controls/TextBox.rb +31 -31
  91. data/lib/sapphire/WebAbstractions/Controls/Title.rb +12 -12
  92. data/lib/sapphire/version.rb +3 -3
  93. metadata +14 -13
  94. data/lib/sapphire/WebAbstractions/Controls/Base/WebBrowser.rb +0 -91
@@ -1,38 +1,39 @@
1
- $:.unshift File.expand_path("..", __FILE__)
2
-
3
- require 'rubygems'
4
- require 'Platform'
5
- require 'yaml'
6
- require 'selenium-webdriver'
7
- require 'delegate'
8
- require 'Forwardable'
9
- require 'colorize'
10
-
11
- require 'sapphire/Strategies'
12
- require 'sapphire/Testing'
13
- require 'sapphire/Web'
14
- require 'sapphire/DSL'
15
- require 'sapphire/CommandLine'
16
- require 'sapphire/Configuration'
17
- require 'sapphire/Data'
18
- require 'sapphire/Virtualization'
19
- require 'sapphire/TeamCity'
20
-
21
- module Sapphire
22
- module Sapphire
23
- include DSL::Strategies
24
- include DSL::Scenarios
25
- include DSL::Browser
26
- include DSL::Configuration
27
- include DSL::Data
28
- include DSL::TestPlans
29
- include Configuration::AttrMethods
30
- include Configuration
31
- include DataAbstractions
32
- include JobAbstractions
33
- include WebAbstractions
34
- include Testing
35
- include Testing::TeamCity
36
- include UI
37
- end
1
+ $:.unshift File.expand_path("..", __FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'Platform'
5
+ require 'yaml'
6
+ require 'selenium-webdriver'
7
+ require 'delegate'
8
+ require 'Forwardable'
9
+ require 'colorize'
10
+
11
+ require 'sapphire/Adapters'
12
+ require 'sapphire/Strategies'
13
+ require 'sapphire/Testing'
14
+ require 'sapphire/Web'
15
+ require 'sapphire/DSL'
16
+ require 'sapphire/CommandLine'
17
+ require 'sapphire/Configuration'
18
+ require 'sapphire/Data'
19
+ require 'sapphire/Virtualization'
20
+ require 'sapphire/TeamCity'
21
+
22
+ module Sapphire
23
+ module Sapphire
24
+ include DSL::Strategies
25
+ include DSL::Scenarios
26
+ include DSL::Browser
27
+ include DSL::Configuration
28
+ include DSL::Data
29
+ include DSL::TestPlans
30
+ include Configuration::AttrMethods
31
+ include Configuration
32
+ include DataAbstractions
33
+ include JobAbstractions
34
+ include WebAbstractions
35
+ include Testing
36
+ include Testing::TeamCity
37
+ include UI
38
+ end
38
39
  end
@@ -0,0 +1 @@
1
+ Dir[File.dirname(__FILE__) + '/Adapters/Selenium/*.rb'].each {|file| require file }
@@ -0,0 +1,190 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+ module RubySeleniumWebDriver
4
+
5
+ attr_reader :rootUrl
6
+
7
+ def Init(url)
8
+ @rootUrl = url
9
+ end
10
+
11
+ def Close
12
+ self.browser.close
13
+ end
14
+
15
+ def Switch
16
+ self.browser.switch_to.window(self.browser.window_handles[0])
17
+ end
18
+
19
+ def Type(keys)
20
+ self.browser.action.send_keys(keys).perform()
21
+ end
22
+
23
+ def AcceptAlert
24
+ alert = self.browser.switch_to.alert
25
+ alert.accept()
26
+ self.browser.switch_to.window(self.browser.window_handles[0])
27
+ end
28
+
29
+ def SetAlert(text)
30
+ alert = self.browser.switch_to.alert
31
+ alert.send_keys(text)
32
+ alert.accept()
33
+ self.browser.switch_to.window(self.browser.window_handles[0])
34
+ end
35
+
36
+ def ClosePopup
37
+ self.browser.switch_to.window(self.browser.window_handles.last)
38
+ self.browser.close
39
+ self.browser.switch_to.window(self.browser.window_handles[0])
40
+ end
41
+
42
+ def SwitchToPopup
43
+ self.browser.switch_to.window(self.browser.window_handles.last)
44
+ end
45
+
46
+ def SetRootUrl(url)
47
+ if(url.instance_of?(String))
48
+ self.Init(url)
49
+ else
50
+ x = url.new().Url
51
+ self.Init(x)
52
+ end
53
+ end
54
+
55
+ def NavigateTo(page)
56
+ if(page.is_a? Class)
57
+ nav = page.new self
58
+ else
59
+ nav = page
60
+ end
61
+
62
+ self.browser.get "https://" + nav.Url
63
+ nav.Init
64
+ nav
65
+ end
66
+
67
+ def CurrentUrl
68
+ wait = Selenium::WebDriver::Wait.new(:timeout => 30)
69
+ url = wait.until { x = self.browser.current_url
70
+ x unless x == nil
71
+ }
72
+
73
+ url
74
+ end
75
+
76
+ def Reload
77
+ self.browser.get self.CurrentUrl
78
+ end
79
+
80
+ def ShouldNavigateTo(page)
81
+ if(page.is_a? Class)
82
+ nav = page.new self
83
+ else
84
+ nav = page
85
+ end
86
+
87
+ wait = Selenium::WebDriver::Wait.new(:timeout => 30)
88
+ found = wait.until {
89
+ x = self.CurrentUrl.upcase.start_with?("HTTP://" + nav.Url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + nav.Url.upcase)
90
+ if(x == false)
91
+ nav.AlternateUrls.each do |url|
92
+ x = self.CurrentUrl.upcase.start_with?("HTTP://" + url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + url.upcase)
93
+ end
94
+ end
95
+ x
96
+ }
97
+ temp = Evaluation.new(found, true)
98
+ return temp, nav
99
+ end
100
+
101
+ def Run(background)
102
+ scenario = background.new self
103
+ scenario.Run
104
+ end
105
+
106
+ def ShouldShow(page)
107
+ self.ShouldNavigateTo page
108
+ end
109
+
110
+ def ShouldTransitionTo(url)
111
+ if(url.instance_of?(String))
112
+ temp = Evaluation.new(self.CurrentUrl.upcase.start_with?("HTTP://" + url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + url.upcase), true)
113
+ @rootUrl = url
114
+ else
115
+ x = url.new().Url
116
+ temp = Evaluation.new(self.CurrentUrl.upcase.start_with?("HTTP://" + x.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + x.upcase), true)
117
+ @rootUrl = x
118
+ end
119
+
120
+ return temp
121
+ end
122
+
123
+ def FindItem(hash)
124
+ masterWait = Selenium::WebDriver::Wait.new(:timeout => 30)
125
+
126
+ element = masterWait.until {
127
+ hash.each do |item|
128
+ wait = Selenium::WebDriver::Wait.new(:timeout => 1)
129
+ begin
130
+ y = wait.until {
131
+ x = self.FindElement item.keys.first, item.fetch(item.keys.first) if item.is_a? Hash
132
+ x = self.FindElement item[0], item[1] if item.is_a? Array
133
+ return x if x != nil
134
+ }
135
+ return y if y != nil
136
+ rescue
137
+ end
138
+ end if hash.is_a? Array
139
+
140
+ x = self.FindElement hash.keys.first, hash.fetch(hash.keys.first) if hash.is_a? Hash
141
+ return x if x != nil
142
+ }
143
+ return element if element != nil
144
+ raise "Could not find control for symbol: " + @hash.to_s
145
+ end
146
+
147
+ def FindAllItems(hash)
148
+ masterWait = Selenium::WebDriver::Wait.new(:timeout => 30)
149
+
150
+ element = masterWait.until {
151
+ hash.each do |item|
152
+ wait = Selenium::WebDriver::Wait.new(:timeout => 1)
153
+ begin
154
+ y = wait.until {
155
+ x = self.FindElements item.keys.first, item.fetch(item.keys.first) if item.is_a? Hash
156
+ x = self.FindElements item[0], item[1] if item.is_a? Array
157
+ return x if x != nil
158
+ }
159
+ return y if y != nil
160
+ rescue
161
+ end
162
+ end if hash.is_a? Array
163
+
164
+ x = self.FindElements hash.keys.first, hash.fetch(hash.keys.first) if hash.is_a? Hash
165
+ return x if x != nil
166
+ }
167
+ return element if element != nil
168
+ raise "Could not find control for symbol: " + @hash.to_s
169
+ end
170
+
171
+ def FindElement(discriminator, selector)
172
+ self.browser.find_element discriminator, selector
173
+ end
174
+
175
+ def FindElements(discriminator, selector)
176
+ self.browser.find_elements discriminator, selector
177
+ end
178
+
179
+ def ExecuteScript(script)
180
+ self.browser.execute_script(script)
181
+ end
182
+
183
+ def Create(type)
184
+ Selenium::WebDriver.for type
185
+ end
186
+ end
187
+ end
188
+ end
189
+
190
+
@@ -1,6 +1,6 @@
1
- Dir[File.dirname(__FILE__) + '/DSL/Browser/*.rb'].each {|file| require file }
2
- Dir[File.dirname(__FILE__) + '/DSL/Browser/Keys/*.rb'].each {|file| require file }
3
- Dir[File.dirname(__FILE__) + '/DSL/Configuration/*.rb'].each {|file| require file }
4
- Dir[File.dirname(__FILE__) + '/DSL/Data/*.rb'].each {|file| require file }
5
- Dir[File.dirname(__FILE__) + '/DSL/Scenarios/*.rb'].each {|file| require file }
6
- Dir[File.dirname(__FILE__) + '/DSL/TestPlans/*.rb'].each {|file| require file }
1
+ Dir[File.dirname(__FILE__) + '/DSL/Browser/*.rb'].each {|file| require file }
2
+ Dir[File.dirname(__FILE__) + '/DSL/Browser/Keys/*.rb'].each {|file| require file }
3
+ Dir[File.dirname(__FILE__) + '/DSL/Configuration/*.rb'].each {|file| require file }
4
+ Dir[File.dirname(__FILE__) + '/DSL/Data/*.rb'].each {|file| require file }
5
+ Dir[File.dirname(__FILE__) + '/DSL/Scenarios/*.rb'].each {|file| require file }
6
+ Dir[File.dirname(__FILE__) + '/DSL/TestPlans/*.rb'].each {|file| require file }
@@ -1,10 +1,10 @@
1
- module Sapphire
2
- module DSL
3
- module Browser
4
- def Accept(browser)
5
- x = browser.new
6
- x.Accept
7
- end
8
- end
9
- end
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Accept(browser)
5
+ x = browser.new
6
+ x.Accept
7
+ end
8
+ end
9
+ end
10
10
  end
@@ -1,20 +1,15 @@
1
- module Sapphire
2
- module DSL
3
- module Browser
4
- class AlertBox
5
- def Accept
6
- alert = $browser.switch_to.alert
7
- alert.accept()
8
- $browser.switch_to.window($browser.window_handles[0])
9
- end
10
-
11
- def Set(text)
12
- alert = $browser.switch_to.alert
13
- alert.send_keys(text)
14
- alert.accept()
15
- $browser.switch_to.window($browser.window_handles[0])
16
- end
17
- end
18
- end
19
- end
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ class AlertBox
5
+ def Accept
6
+ $browser.AcceptAlert
7
+ end
8
+
9
+ def Set(text)
10
+ $browser.SetAlert(text)
11
+ end
12
+ end
13
+ end
14
+ end
20
15
  end
@@ -1,17 +1,17 @@
1
- module Sapphire
2
- module DSL
3
- module Browser
4
- class Browser
5
- def Close
6
- sleep(2)
7
- $browser.close
8
- end
9
-
10
- def Switch
11
- $browser.switch_to.window($browser.window_handles[0])
12
- end
13
- end
14
- end
15
- end
16
- end
17
-
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ class Browser
5
+ def Close
6
+ sleep(2)
7
+ $browser.Close
8
+ end
9
+
10
+ def Switch
11
+ $browser.Switch
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -1,10 +1,10 @@
1
- module Sapphire
2
- module DSL
3
- module Browser
4
- def By(value, compare1, compare2)
5
- return value, compare1, compare2
6
- end
7
- end
8
- end
9
- end
10
-
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def By(value, compare1, compare2)
5
+ return value, compare1, compare2
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -1,12 +1,12 @@
1
- module Sapphire
2
- module DSL
3
- module Browser
4
- def Check(*args)
5
- ExecuteAgainstControl(args) do |control, arg|
6
- control.Check true
7
- end
8
- end
9
- end
10
- end
11
- end
12
-
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Check(*args)
5
+ ExecuteAgainstControl(args) do |control, arg|
6
+ control.Check true
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -1,13 +1,13 @@
1
- module Sapphire
2
- module DSL
3
- module Browser
4
- def Clear(item)
5
- if(item.is_a? Class)
6
- x = item.new $browser
7
- x.Clear
8
- return
9
- end
10
- end
11
- end
12
- end
1
+ module Sapphire
2
+ module DSL
3
+ module Browser
4
+ def Clear(item)
5
+ if(item.is_a? Class)
6
+ x = item.new @browser
7
+ x.Clear
8
+ return
9
+ end
10
+ end
11
+ end
12
+ end
13
13
  end