sapphire 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,199 +1,209 @@
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
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
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
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(array)
124
- masterWait = Selenium::WebDriver::Wait.new(:timeout => 30)
125
-
126
- element = masterWait.until {
127
- x = nil
128
- array.each do |item|
129
-
130
- if item.is_a? Hash
131
- begin
132
- x = self.FindElement item.keys.first, item.fetch(item.keys.first)
133
- rescue
134
- #do nothing, let it keep looping
135
- end
136
- end
137
-
138
- x = self.FindElement item[0], item[1] if item.is_a? Array
139
-
140
- return x if x != nil
141
-
142
- end if array.is_a? Array
143
-
144
- x = self.FindElement array.keys.first, array.fetch(array.keys.first) if array.is_a? Hash
145
- return x if x != nil
146
- }
147
- return element if element != nil
148
- raise "Could not find control for array: " + array.to_s
149
- end
150
-
151
- def FindAllItems(array)
152
- masterWait = Selenium::WebDriver::Wait.new(:timeout => 30)
153
-
154
- element = masterWait.until {
155
- x = nil
156
- array.each do |item|
157
-
158
- if item.is_a? Hash
159
- begin
160
- x = self.FindElements item.keys.first, item.fetch(item.keys.first)
161
- x = nil if x.is_a? Array and x.empty?
162
- rescue
163
- #do nothing, let it keep looping
164
- end
165
- end
166
-
167
- x = self.FindElements item[0], item[1] if item.is_a? Array
168
- x = nil if x.is_a? Array and x.empty?
169
- return x if x != nil
170
-
171
- end if array.is_a? Array
172
-
173
- x = self.FindElement array.keys.first, array.fetch(array.keys.first) if array.is_a? Hash
174
- return x if x != nil
175
- }
176
- return element if element != nil
177
- raise "Could not find control for array: " + array.to_s
178
- end
179
-
180
- def FindElement(discriminator, selector)
181
- self.browser.find_element discriminator, selector
182
- end
183
-
184
- def FindElements(discriminator, selector)
185
- self.browser.find_elements discriminator, selector
186
- end
187
-
188
- def ExecuteScript(script)
189
- self.browser.execute_script(script)
190
- end
191
-
192
- def Create(type)
193
- Selenium::WebDriver.for type
194
- end
195
- end
196
- end
197
- end
198
-
199
-
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 SwitchToIFrame(frame)
47
+ self.browser.switch_to.frame(frame)
48
+ end
49
+
50
+ def SetRootUrl(url)
51
+ if(url.instance_of?(String))
52
+ self.Init(url)
53
+ else
54
+ x = url.new().Url
55
+ self.Init(x)
56
+ end
57
+ end
58
+
59
+ def NavigateTo(page)
60
+ if(page.is_a? Class)
61
+ nav = page.new
62
+ else
63
+ nav = page
64
+ end
65
+
66
+ self.browser.get "https://" + nav.Url
67
+ nav.Init
68
+ nav
69
+ end
70
+
71
+ def CurrentUrl
72
+ wait = Selenium::WebDriver::Wait.new(:timeout => 30)
73
+ url = wait.until { x = self.browser.current_url
74
+ x unless x == nil
75
+ }
76
+
77
+ url
78
+ end
79
+
80
+ def Reload
81
+ self.browser.get self.CurrentUrl
82
+ end
83
+
84
+ def ShouldNavigateTo(page)
85
+ if(page.is_a? Class)
86
+ nav = page.new
87
+ else
88
+ nav = page
89
+ end
90
+
91
+ wait = Selenium::WebDriver::Wait.new(:timeout => 30)
92
+ begin
93
+ found = wait.until {
94
+ x = self.CurrentUrl.upcase.start_with?("HTTP://" + nav.Url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + nav.Url.upcase)
95
+ if(x == false)
96
+ nav.AlternateUrls.each do |url|
97
+ if( x == false)
98
+ x = self.CurrentUrl.upcase.start_with?("HTTP://" + url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + url.upcase)
99
+ end
100
+ end
101
+ end
102
+ x
103
+ }
104
+ rescue
105
+ temp = Evaluation.new(self.CurrentUrl, nav.Url)
106
+ return temp, nav
107
+ end
108
+
109
+ temp = Evaluation.new(found, true)
110
+ return temp, nav
111
+ end
112
+
113
+ def Run(background)
114
+ scenario = background.new
115
+ scenario.Run
116
+ end
117
+
118
+ def ShouldShow(page)
119
+ self.ShouldNavigateTo page
120
+ end
121
+
122
+ def ShouldTransitionTo(url)
123
+ if(url.instance_of?(String))
124
+ temp = Evaluation.new(self.CurrentUrl.upcase.start_with?("HTTP://" + url.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + url.upcase), true)
125
+ @rootUrl = url
126
+ else
127
+ x = url.new().Url
128
+ temp = Evaluation.new(self.CurrentUrl.upcase.start_with?("HTTP://" + x.upcase) || self.CurrentUrl.upcase.start_with?("HTTPS://" + x.upcase), true)
129
+ @rootUrl = x
130
+ end
131
+
132
+ return temp
133
+ end
134
+
135
+ def FindItem(array)
136
+ masterWait = Selenium::WebDriver::Wait.new(:timeout => 30)
137
+
138
+ element = masterWait.until {
139
+ x = nil
140
+ array.each do |item|
141
+
142
+ if item.is_a? Hash
143
+ begin
144
+ x = self.FindElement item.keys.first, item.fetch(item.keys.first)
145
+ rescue
146
+ #do nothing, let it keep looping
147
+ end
148
+ end
149
+
150
+ x = self.FindElement item[0], item[1] if item.is_a? Array
151
+
152
+ return x if x != nil
153
+
154
+ end if array.is_a? Array
155
+
156
+ x = self.FindElement array.keys.first, array.fetch(array.keys.first) if array.is_a? Hash
157
+ return x if x != nil
158
+ }
159
+ return element if element != nil
160
+ raise "Could not find control for array: " + array.to_s
161
+ end
162
+
163
+ def FindAllItems(array)
164
+ masterWait = Selenium::WebDriver::Wait.new(:timeout => 30)
165
+
166
+ element = masterWait.until {
167
+ x = nil
168
+ array.each do |item|
169
+
170
+ if item.is_a? Hash
171
+ begin
172
+ x = self.FindElements item.keys.first, item.fetch(item.keys.first)
173
+ x = nil if x.is_a? Array and x.empty?
174
+ rescue
175
+ #do nothing, let it keep looping
176
+ end
177
+ end
178
+
179
+ x = self.FindElements item[0], item[1] if item.is_a? Array
180
+ x = nil if x.is_a? Array and x.empty?
181
+ return x if x != nil
182
+
183
+ end if array.is_a? Array
184
+
185
+ x = self.FindElement array.keys.first, array.fetch(array.keys.first) if array.is_a? Hash
186
+ return x if x != nil
187
+ }
188
+ return element if element != nil
189
+ raise "Could not find control for array: " + array.to_s
190
+ end
191
+
192
+ def FindElement(discriminator, selector)
193
+ self.browser.find_element discriminator, selector
194
+ end
195
+
196
+ def FindElements(discriminator, selector)
197
+ self.browser.find_elements discriminator, selector
198
+ end
199
+
200
+ def ExecuteScript(script)
201
+ self.browser.execute_script(script)
202
+ end
203
+
204
+ def Create(type)
205
+ Selenium::WebDriver.for type
206
+ end
207
+ end
208
+ end
209
+ end
@@ -5,14 +5,18 @@ module Sapphire
5
5
  def Show(item, modifier)
6
6
  ExecuteHashAgainstControl(item, @page) do |control, arg|
7
7
  wait = Selenium::WebDriver::Wait.new(:timeout => 30)
8
- text = wait.until { x = control
9
- val = x.Equals(arg)
10
- if (val.left == val.right)
11
- x
12
- end
13
- }
8
+ begin
9
+ evaluation = wait.until { x = control
10
+ val = x.Equals(arg)
11
+ if (val.left == val.right)
12
+ val
13
+ end
14
+ }
15
+ rescue
16
+ return Evaluation.new(control.Text, arg)
17
+ end
14
18
 
15
- return text.Equals(arg)
19
+ return evaluation
16
20
  end
17
21
  end
18
22
 
@@ -1,11 +1,11 @@
1
1
  module Sapphire
2
2
  module Testing
3
3
  module Coverage
4
- def Test(token, hash)
5
- $features.last().AddTest(Test.new(token, hash))
4
+ def Behavior(token, hash)
5
+ $features.last().AddBehavior(Behavior.new(token, hash))
6
6
  end
7
7
 
8
- class Test
8
+ class Behavior
9
9
 
10
10
  attr_reader :token
11
11
  attr_reader :type
@@ -14,15 +14,15 @@ module Sapphire
14
14
 
15
15
  def initialize(token)
16
16
  @token = token
17
- @requirements = []
17
+ @behaviors = []
18
18
  end
19
19
 
20
20
  def AddRequirement(requirement)
21
21
  @requirements << requirement
22
22
  end
23
23
 
24
- def AddTest(test)
25
- @requirements.last().AddTest test
24
+ def AddBehavior(behavior)
25
+ @requirements.last().AddBehavior behavior
26
26
  end
27
27
 
28
28
  end
@@ -10,16 +10,16 @@ module Sapphire
10
10
 
11
11
  attr_reader :token
12
12
  attr_reader :priority
13
- attr_reader :tests
13
+ attr_reader :behaviors
14
14
 
15
15
  def initialize(hash)
16
16
  @token = hash.keys.first
17
17
  @priority = hash[hash.keys.first]
18
- @tests = []
18
+ @behaviors = []
19
19
  end
20
20
 
21
- def AddTest(test)
22
- @tests << test
21
+ def AddBehavior(behavior)
22
+ @behaviors << behavior
23
23
  end
24
24
 
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Sapphire
2
- VERSION = "0.5.9"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sapphire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-19 00:00:00.000000000Z
12
+ date: 2011-12-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
16
- requirement: &10066392 !ruby/object:Gem::Requirement
16
+ requirement: &10000008 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *10066392
24
+ version_requirements: *10000008
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: colorize
27
- requirement: &10066140 !ruby/object:Gem::Requirement
27
+ requirement: &9999756 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *10066140
35
+ version_requirements: *9999756
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: Platform
38
- requirement: &10065888 !ruby/object:Gem::Requirement
38
+ requirement: &9999504 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *10065888
46
+ version_requirements: *9999504
47
47
  description: An automated web acceptance test framework for non-technical resources
48
48
  using selenium-wedriver.
49
49
  email:
@@ -146,10 +146,10 @@ files:
146
146
  - lib/sapphire/TeamCity/TeamCityReporter.rb
147
147
  - lib/sapphire/TeamCity.rb
148
148
  - lib/sapphire/Testing/ConsoleReporter.rb
149
+ - lib/sapphire/Testing/Coverage/Behavior.rb
149
150
  - lib/sapphire/Testing/Coverage/Covers.rb
150
151
  - lib/sapphire/Testing/Coverage/Feature.rb
151
152
  - lib/sapphire/Testing/Coverage/Requirement.rb
152
- - lib/sapphire/Testing/Coverage/Test.rb
153
153
  - lib/sapphire/Testing/Executable.rb
154
154
  - lib/sapphire/Testing/ExpectationException.rb
155
155
  - lib/sapphire/Testing/HtmlReporter.rb