sapphire 0.7.12 → 0.7.14

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sapphire.rb CHANGED
@@ -26,7 +26,6 @@ module Sapphire
26
26
  include DSL::Configuration
27
27
  include DSL::Data
28
28
  include DSL::TestPlans
29
- include DSL::Events
30
29
  include Configuration
31
30
  include DataAbstractions
32
31
  include JobAbstractions
@@ -36,4 +35,6 @@ module Sapphire
36
35
  include Testing::TeamCity
37
36
  include UI
38
37
  end
39
- end
38
+ end
39
+
40
+ $driver = Sapphire::WebAbstractions::MetaBrowser.new(nil)
@@ -8,38 +8,43 @@ module Sapphire
8
8
  @rootUrl = url
9
9
  end
10
10
 
11
+ def Browser()
12
+ raise "Browser is null. Did you forget to start the browser?" if self.browser.nil?
13
+ self.browser
14
+ end
15
+
11
16
  def Screenshot(file_name)
12
- self.browser.save_screenshot(file_name)
17
+ self.Browser().save_screenshot(file_name)
13
18
  end
14
19
 
15
20
  def Close
16
- self.browser.close
21
+ self.Browser().close
17
22
  end
18
23
 
19
24
  def Switch
20
- self.browser.switch_to.window(self.browser.window_handles[0])
25
+ self.Browser().switch_to.window(self.Browser().window_handles[0])
21
26
  end
22
27
 
23
28
  def Type(keys)
24
- self.browser.action.send_keys(keys).perform()
29
+ self.Browser().action.send_keys(keys).perform()
25
30
  end
26
31
 
27
32
  def AcceptAlert
28
- alert = self.browser.switch_to.alert
33
+ alert = self.Browser().switch_to.alert
29
34
  alert.accept()
30
- self.browser.switch_to.window(self.browser.window_handles[0])
35
+ self.Browser().switch_to.window(self.Browser().window_handles[0])
31
36
  end
32
37
 
33
38
  def SetAlert(text)
34
- alert = self.browser.switch_to.alert
39
+ alert = self.Browser().switch_to.alert
35
40
  alert.send_keys(text)
36
41
  alert.accept()
37
- self.browser.switch_to.window(self.browser.window_handles[0])
42
+ self.Browser().switch_to.window(self.Browser().window_handles[0])
38
43
  end
39
44
 
40
45
  def FindAlert()
41
46
  begin
42
- return self.browser.switch_to.alert
47
+ return self.Browser().switch_to.alert
43
48
  rescue
44
49
  return nil
45
50
  end
@@ -51,17 +56,17 @@ module Sapphire
51
56
  end
52
57
 
53
58
  def ClosePopup
54
- self.browser.switch_to.window(self.browser.window_handles.last)
55
- self.browser.close
56
- self.browser.switch_to.window(self.browser.window_handles[0])
59
+ self.Browser().switch_to.window(self.Browser().window_handles.last)
60
+ self.Browser().close
61
+ self.Browser().switch_to.window(self.Browser().window_handles[0])
57
62
  end
58
63
 
59
64
  def SwitchToPopup
60
- self.browser.switch_to.window(self.browser.window_handles.last)
65
+ self.Browser().switch_to.window(self.Browser().window_handles.last)
61
66
  end
62
67
 
63
68
  def SwitchToIFrame(frame)
64
- self.browser.switch_to.frame(frame)
69
+ self.Browser().switch_to.frame(frame)
65
70
  end
66
71
 
67
72
  def SetRootUrl(url)
@@ -80,13 +85,13 @@ module Sapphire
80
85
  $page = page
81
86
  end
82
87
 
83
- self.browser.get $page.Url
88
+ self.Browser().get $page.Url
84
89
  $page.Init
85
90
  end
86
91
 
87
92
  def CurrentUrl
88
93
  wait = Selenium::WebDriver::Wait.new(:timeout => 20)
89
- url = wait.until { x = self.browser.current_url
94
+ url = wait.until { x = self.Browser().current_url
90
95
  x unless x == nil
91
96
  }
92
97
 
@@ -94,7 +99,7 @@ module Sapphire
94
99
  end
95
100
 
96
101
  def Reload
97
- self.browser.get self.CurrentUrl
102
+ self.Browser().get self.CurrentUrl
98
103
  end
99
104
 
100
105
  def GetValue(item, key)
@@ -131,12 +136,12 @@ module Sapphire
131
136
  begin
132
137
  item = wait.until {
133
138
  x = self.CurrentUrl.upcase.start_with?($page.Url.upcase)
134
- y = StartsWithComparison.new(Evaluation.new($page.Url.upcase, self.CurrentUrl.upcase))
139
+ y = StartsWithComparison.new(Evaluation.new(self.CurrentUrl.upcase, $page.Url.upcase))
135
140
  if(comparator.Compare(x == false, true))
136
141
  $page.AlternateUrls.each do |url|
137
142
  if(comparator.Compare(x == false, true))
138
143
  x = self.CurrentUrl.upcase.start_with?(url.upcase)
139
- y = StartsWithComparison.new(Evaluation.new(url.upcase, self.CurrentUrl.upcase))
144
+ y = StartsWithComparison.new(Evaluation.new(self.CurrentUrl.upcase, url.upcase))
140
145
  end
141
146
  end
142
147
  end
@@ -159,11 +164,11 @@ module Sapphire
159
164
 
160
165
  def ShouldTransitionTo(url, comparator)
161
166
  if(url.instance_of?(String))
162
- temp = StartsWithComparison.new(Evaluation.new(url.upcase, self.CurrentUrl.upcase))
167
+ temp = StartsWithComparison.new(Evaluation.new(self.CurrentUrl.upcase, url.upcase))
163
168
  @rootUrl = url
164
169
  else
165
170
  x = url.new().Url
166
- temp = StartsWithComparison.new(Evaluation.new(x.upcase, self.CurrentUrl.upcase))
171
+ temp = StartsWithComparison.new(Evaluation.new(self.CurrentUrl.upcase, x.upcase))
167
172
  @rootUrl = x
168
173
  end
169
174
 
@@ -231,15 +236,15 @@ module Sapphire
231
236
  end
232
237
 
233
238
  def FindElement(discriminator, selector)
234
- self.browser.find_element discriminator, selector
239
+ self.Browser().find_element discriminator, selector
235
240
  end
236
241
 
237
242
  def FindElements(discriminator, selector)
238
- self.browser.find_elements discriminator, selector
243
+ self.Browser().find_elements discriminator, selector
239
244
  end
240
245
 
241
246
  def ExecuteScript(script)
242
- self.browser.execute_script(script)
247
+ self.Browser().execute_script(script)
243
248
  end
244
249
 
245
250
  def Create(type)
@@ -32,10 +32,10 @@ module Sapphire
32
32
  if(!Compare(@left, @right))
33
33
  messages = []
34
34
 
35
- messages << "expected" + @comparator.Text + ": (nil)" if @left == nil
36
- messages << "expected" + @comparator.Text + ": " + @left.to_s if @left != nil
37
- messages << "got: (nil)" if @right == nil
38
- messages << "got: " + @right.to_s if @right != nil
35
+ messages << "expected" + @comparator.Text + ": (nil)" if @right == nil
36
+ messages << "expected" + @comparator.Text + ": " + @right.to_s if @right != nil
37
+ messages << "got: (nil)" if @left == nil
38
+ messages << "got: " + @left.to_s if @left != nil
39
39
 
40
40
  raise ExpectationException.new(messages)
41
41
  end
@@ -48,7 +48,11 @@ module Sapphire
48
48
  def execute
49
49
  Report do |x| x.BeginTesting end
50
50
  $stdout.puts ""
51
- @block.call
51
+ begin
52
+ @block.call
53
+ rescue => e
54
+ Report do |x| x.TestFailed TestPlanResult.new('fail', self, e.message, e.backtrace, 0) end
55
+ end
52
56
  Report do |x| x.TestingComplete end
53
57
  Report do |x| x.OutputResults end
54
58
  end
@@ -53,7 +53,7 @@ module Sapphire
53
53
  end
54
54
  @output.puts ""
55
55
  result.stack.each do |line|
56
- if (!line.include? "sapphire")
56
+ if (!line.include? "sapphire" and ! line.include? "-e:1")
57
57
  Indent(depth+1)
58
58
  @output.puts line
59
59
  end
@@ -108,6 +108,8 @@ module Sapphire
108
108
  @not_passing = @not_passing.merge!({ r.parent.parent => r.parent.parent })
109
109
  elsif !result_passes and (r.item.is_a? And and r.parent.item.is_a? Then)
110
110
  @not_passing = @not_passing.merge!({ r.parent.parent.parent => r.parent.parent.parent })
111
+ elsif r.item.is_a? TestPlan
112
+ @not_passing = @not_passing.merge!({ r => r })
111
113
  end
112
114
 
113
115
  end
@@ -151,6 +153,9 @@ module Sapphire
151
153
  self.PrintItem entry.parent, 0
152
154
  self.Output entry, 1
153
155
  self.InsertLineBreak
156
+ elsif entry.item.is_a? TestPlan
157
+ self.PrintItem entry, 0
158
+ self.InsertLineBreak
154
159
  else
155
160
  self.PrintResult entry.parent
156
161
  end
@@ -0,0 +1,24 @@
1
+ module Sapphire
2
+ module Testing
3
+ class TestPlanResult
4
+
5
+ attr_reader :execution_time
6
+ attr_reader :message
7
+ attr_reader :item
8
+ attr_reader :type
9
+ attr_reader :stack
10
+ attr_reader :messages
11
+ attr_reader :text
12
+
13
+ def initialize(type, item, message, stack, execution_time)
14
+ @item = item
15
+ @text = "Failure running commands in TestPlan: " + item.text
16
+ @execution_time = execution_time
17
+ @messages = message
18
+ @stack = stack
19
+ @type = type
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -13,9 +13,11 @@ module Sapphire
13
13
  def initialize()
14
14
  @browser = self.Create :chrome
15
15
  super @browser
16
- $driver = self
16
+ $driver = MetaBrowser.new(self)
17
17
  end
18
18
  end
19
+
20
+
19
21
  end
20
22
  end
21
23
 
@@ -8,7 +8,7 @@ module Sapphire
8
8
  def initialize()
9
9
  @browser = self.Create :firefox
10
10
  super(@browser)
11
- $driver = self
11
+ $driver = MetaBrowser.new(self)
12
12
  end
13
13
 
14
14
  end
@@ -14,7 +14,7 @@ module Sapphire
14
14
  def initialize
15
15
  @browser = self.Create :ie
16
16
  super(@browser)
17
- $driver = self
17
+ $driver = MetaBrowser.new(self)
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,22 @@
1
+ module Sapphire
2
+ module WebAbstractions
3
+
4
+ class MetaBrowser
5
+ include RubySeleniumWebDriver
6
+
7
+ attr_reader :driver
8
+
9
+ def initialize(driver)
10
+ @driver = driver
11
+ end
12
+
13
+ def Browser()
14
+ raise "Browser is null. Did you forget to start the browser?" if self.driver.nil? or self.driver.browser.nil?
15
+ self.driver.browser
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+
22
+
@@ -3,7 +3,7 @@ module Sapphire
3
3
  class Title < Control
4
4
 
5
5
  def Text
6
- $driver.browser.title
6
+ $driver.Browser().title
7
7
  end
8
8
 
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Sapphire
2
- VERSION = "0.7.12"
2
+ VERSION = "0.7.14"
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.7.12
4
+ version: 0.7.14
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: 2012-03-19 00:00:00.000000000Z
12
+ date: 2012-03-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: selenium-webdriver
16
- requirement: &9923892 !ruby/object:Gem::Requirement
16
+ requirement: &9813300 !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: *9923892
24
+ version_requirements: *9813300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: colorize
27
- requirement: &9923640 !ruby/object:Gem::Requirement
27
+ requirement: &9813048 !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: *9923640
35
+ version_requirements: *9813048
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: Platform
38
- requirement: &9923388 !ruby/object:Gem::Requirement
38
+ requirement: &9812796 !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: *9923388
46
+ version_requirements: *9812796
47
47
  description: An automated web acceptance test framework for non-technical resources
48
48
  using selenium-wedriver.
49
49
  email:
@@ -180,6 +180,7 @@ files:
180
180
  - lib/sapphire/Testing/ResultList.rb
181
181
  - lib/sapphire/Testing/ResultTree.rb
182
182
  - lib/sapphire/Testing/ScenarioResult.rb
183
+ - lib/sapphire/Testing/TestPlanResult.rb
183
184
  - lib/sapphire/Testing/TestResult.rb
184
185
  - lib/sapphire/Testing/TestRunnerAdapter.rb
185
186
  - lib/sapphire/Testing.rb
@@ -192,6 +193,7 @@ files:
192
193
  - lib/sapphire/WebAbstractions/Browsers/Chrome.rb
193
194
  - lib/sapphire/WebAbstractions/Browsers/FireFox.rb
194
195
  - lib/sapphire/WebAbstractions/Browsers/InternetExplorer.rb
196
+ - lib/sapphire/WebAbstractions/Browsers/MetaBrowser.rb
195
197
  - lib/sapphire/WebAbstractions/Controls/AlertBox.rb
196
198
  - lib/sapphire/WebAbstractions/Controls/Base/Control.rb
197
199
  - lib/sapphire/WebAbstractions/Controls/Base/Page.rb