sapphire 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/bin/sapphire +0 -0
  2. data/lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb +4 -4
  3. data/lib/sapphire/DSL/Browser/Create.rb +10 -10
  4. data/lib/sapphire/DSL/Browser/ExecuteAgainstControl.rb +20 -20
  5. data/lib/sapphire/DSL/Browser/Fluff/By.rb +10 -10
  6. data/lib/sapphire/DSL/Browser/Fluff/To.rb +10 -10
  7. data/lib/sapphire/DSL/Browser/Fluff/With.rb +10 -10
  8. data/lib/sapphire/DSL/Browser/Nouns/Browser.rb +17 -17
  9. data/lib/sapphire/DSL/Browser/Nouns/Enter.rb +10 -10
  10. data/lib/sapphire/DSL/Browser/Tracker.rb +15 -15
  11. data/lib/sapphire/DSL/Browser/Verbs/Accept.rb +8 -8
  12. data/lib/sapphire/DSL/Browser/Verbs/Check.rb +10 -10
  13. data/lib/sapphire/DSL/Browser/Verbs/Clear.rb +8 -8
  14. data/lib/sapphire/DSL/Browser/Verbs/Click.rb +10 -10
  15. data/lib/sapphire/DSL/Browser/Verbs/Compare.rb +18 -18
  16. data/lib/sapphire/DSL/Browser/Verbs/Complete.rb +13 -13
  17. data/lib/sapphire/DSL/Browser/Verbs/Exists.rb +16 -16
  18. data/lib/sapphire/DSL/Browser/Verbs/Exit.rb +11 -11
  19. data/lib/sapphire/DSL/Browser/Verbs/MouseOver.rb +10 -10
  20. data/lib/sapphire/DSL/Browser/Verbs/Navigate.rb +10 -10
  21. data/lib/sapphire/DSL/Browser/Verbs/Press.rb +8 -8
  22. data/lib/sapphire/DSL/Browser/Verbs/Reload.rb +11 -11
  23. data/lib/sapphire/DSL/Browser/Verbs/Set.rb +10 -10
  24. data/lib/sapphire/DSL/Browser/Verbs/Uncheck.rb +10 -10
  25. data/lib/sapphire/DSL/Comparisons/CheckedComparison.rb +17 -17
  26. data/lib/sapphire/DSL/Comparisons/Comparison.rb +50 -50
  27. data/lib/sapphire/DSL/Comparisons/ContainsComparison.rb +17 -17
  28. data/lib/sapphire/DSL/Comparisons/DifferComparison.rb +17 -17
  29. data/lib/sapphire/DSL/Comparisons/EqualsComparison.rb +16 -16
  30. data/lib/sapphire/DSL/Comparisons/NotComparison.rb +20 -20
  31. data/lib/sapphire/DSL/Comparisons/SelectedComparison.rb +17 -17
  32. data/lib/sapphire/DSL/Comparisons/StartsWithComparison.rb +17 -17
  33. data/lib/sapphire/DSL/Comparisons/VisibleComparison.rb +17 -17
  34. data/lib/sapphire/DSL/Configuration/ConfiguredBrowser.rb +12 -12
  35. data/lib/sapphire/DSL/Configuration/ConfiguredUser.rb +10 -10
  36. data/lib/sapphire/DSL/Configuration/Use.rb +18 -18
  37. data/lib/sapphire/DSL/Data/Find.rb +10 -10
  38. data/lib/sapphire/DSL/Data/GetPageField.rb +13 -13
  39. data/lib/sapphire/DSL/Data/Verify.rb +10 -10
  40. data/lib/sapphire/DSL/Evaluations/ControlEvaluation.rb +2 -2
  41. data/lib/sapphire/DSL/Evaluations/Evaluation.rb +5 -5
  42. data/lib/sapphire/DSL/Evaluations/FieldNotDefinedEvaluation.rb +20 -20
  43. data/lib/sapphire/DSL/Evaluations/FieldNotFoundEvaluation.rb +22 -22
  44. data/lib/sapphire/DSL/Evaluators/Contain.rb +10 -10
  45. data/lib/sapphire/DSL/Evaluators/Count.rb +8 -8
  46. data/lib/sapphire/DSL/Evaluators/Differ.rb +10 -10
  47. data/lib/sapphire/DSL/Evaluators/Exist.rb +9 -9
  48. data/lib/sapphire/DSL/Evaluators/In.rb +10 -10
  49. data/lib/sapphire/DSL/Evaluators/Selected.rb +10 -10
  50. data/lib/sapphire/DSL/Evaluators/Show.rb +10 -10
  51. data/lib/sapphire/DSL/Evaluators/Transition.rb +10 -10
  52. data/lib/sapphire/DSL/Evaluators/Validate.rb +8 -8
  53. data/lib/sapphire/DSL/Scenarios/Is.rb +9 -9
  54. data/lib/sapphire/DSL/Scenarios/Pending.rb +28 -28
  55. data/lib/sapphire/DSL/Scenarios/and.rb +25 -25
  56. data/lib/sapphire/DSL/Scenarios/dsl.rb +59 -59
  57. data/lib/sapphire/DSL/Scenarios/runner.rb +40 -40
  58. data/lib/sapphire/Data.rb +1 -1
  59. data/lib/sapphire/DataAbstractions/Database.rb +57 -57
  60. data/lib/sapphire/DataAbstractions/Query.rb +20 -20
  61. data/lib/sapphire/Extensions/Hash.rb +112 -112
  62. data/lib/sapphire/Extensions/Numeric.rb +6 -6
  63. data/lib/sapphire/JobAbstractions/Job.rb +32 -32
  64. data/lib/sapphire/Plugins/Debugging/VerboseObserver.rb +36 -36
  65. data/lib/sapphire/Plugins/Highlighters/Highlighter.rb +40 -40
  66. data/lib/sapphire/Plugins/Plugin.rb +20 -20
  67. data/lib/sapphire/TeamCity.rb +10 -10
  68. data/lib/sapphire/Testing.rb +3 -3
  69. data/lib/sapphire/Testing/RakeTask.rb +108 -108
  70. data/lib/sapphire/Testing/ResultList.rb +18 -18
  71. data/lib/sapphire/Testing/ScenarioResult.rb +36 -36
  72. data/lib/sapphire/Testing/TestResult.rb +21 -21
  73. data/lib/sapphire/Testing/TestRunnerAdapter.rb +85 -85
  74. data/lib/sapphire/UI/ProcessBuilder.rb +173 -173
  75. data/lib/sapphire/Virtualization.rb +7 -7
  76. data/lib/sapphire/Web.rb +2 -2
  77. data/lib/sapphire/WebAbstractions/Controls/AlertBox.rb +20 -20
  78. data/lib/sapphire/WebAbstractions/Controls/Base/Control.rb +12 -8
  79. data/lib/sapphire/WebAbstractions/Controls/Button.rb +7 -7
  80. data/lib/sapphire/WebAbstractions/Controls/Date.rb +11 -11
  81. data/lib/sapphire/WebAbstractions/Controls/DropDown.rb +4 -4
  82. data/lib/sapphire/WebAbstractions/Controls/Hyperlink.rb +8 -8
  83. data/lib/sapphire/WebAbstractions/Controls/Label.rb +8 -8
  84. data/lib/sapphire/WebAbstractions/Controls/List.rb +11 -13
  85. data/lib/sapphire/WebAbstractions/Controls/Title.rb +12 -12
  86. data/lib/sapphire/version.rb +1 -1
  87. metadata +17 -21
@@ -1,174 +1,174 @@
1
- module ChildProcess
2
- module Windows
3
- class ProcessBuilder
4
- attr_accessor :inherit, :detach, :duplex, :environment, :stdout, :stderr
5
- attr_reader :stdin
6
-
7
- def initialize(args)
8
- @args = args
9
-
10
- @inherit = false
11
- @detach = false
12
- @duplex = false
13
- @environment = nil
14
-
15
- @stdout = nil
16
- @stderr = nil
17
- @stdin = nil
18
-
19
- @flags = 0
20
- @cmd_ptr = nil
21
- @env_ptr = nil
22
- end
23
-
24
- def start
25
- create_command_pointer
26
- create_environment_pointer
27
-
28
- setup_detach
29
- setup_io
30
-
31
- pid = create_process
32
- close_handles
33
-
34
- pid
35
- end
36
-
37
- private
38
-
39
- def create_command_pointer
40
- string = @args.map { |arg| quote_if_necessary(arg.to_s) }.join ' '
41
- @cmd_ptr = FFI::MemoryPointer.from_string string
42
- end
43
-
44
- def create_environment_pointer
45
- return unless @environment.kind_of?(Hash) && @environment.any?
46
-
47
- # inherited env
48
- strings = ENV.map { |k,v| "#{k}=#{v}\0" }
49
-
50
- # extras
51
- @environment.each do |key, value|
52
- if key.include?("=")
53
- raise InvalidEnvironmentVariableName, key
54
- end
55
-
56
- strings << "#{key}=#{value}\0"
57
- end
58
-
59
- strings << "\0" # terminate the env block
60
- env_str = strings.join
61
-
62
- @env_ptr = FFI::MemoryPointer.new(:long, env_str.bytesize)
63
- @env_ptr.put_bytes 0, env_str, 0, env_str.bytesize
64
- end
65
-
66
- def create_process
67
- @startup_info[:lpDesktop] = FFI::MemoryPointer.from_string("test") if $isVirtual
68
-
69
- ok = Lib.create_process(
70
- nil, # application name
71
- @cmd_ptr, # command line
72
- nil, # process attributes
73
- nil, # thread attributes
74
- @inherit, # inherit handles
75
- @flags, # creation flags
76
- @env_ptr, # environment
77
- nil, # current directory
78
- startup_info, # startup info
79
- process_info # process info
80
- )
81
-
82
- ok or raise LaunchError, Lib.last_error_message
83
-
84
- process_info[:dwProcessId]
85
- end
86
-
87
- def startup_info
88
- @startup_info ||= StartupInfo.new
89
- end
90
-
91
- def process_info
92
- @process_info ||= ProcessInfo.new
93
- end
94
-
95
- def setup_detach
96
- @flags |= DETACHED_PROCESS if @detach
97
- end
98
-
99
- def setup_io
100
- if @stdout || @stderr
101
- startup_info[:dwFlags] ||= 0
102
- startup_info[:dwFlags] |= STARTF_USESTDHANDLES
103
-
104
- @inherit = true
105
-
106
- if @stdout
107
- startup_info[:hStdOutput] = std_stream_handle_for(@stdout)
108
- end
109
-
110
- if @stderr
111
- startup_info[:hStdError] = std_stream_handle_for(@stderr)
112
- end
113
- end
114
-
115
- setup_stdin if @duplex
116
- end
117
-
118
- def setup_stdin
119
- read_pipe_ptr = FFI::MemoryPointer.new(:pointer)
120
- write_pipe_ptr = FFI::MemoryPointer.new(:pointer)
121
- sa = SecurityAttributes.new(:inherit => true)
122
-
123
- ok = Lib.create_pipe(read_pipe_ptr, write_pipe_ptr, sa, 0)
124
- Lib.check_error ok
125
-
126
- @read_pipe = read_pipe_ptr.read_pointer
127
- @write_pipe = write_pipe_ptr.read_pointer
128
-
129
- @inherit = true
130
- Lib.set_handle_inheritance @read_pipe, true
131
- Lib.set_handle_inheritance @write_pipe, false
132
-
133
- startup_info[:hStdInput] = @read_pipe
134
- end
135
-
136
- def std_stream_handle_for(io)
137
- handle = Lib.handle_for(io)
138
-
139
- begin
140
- Lib.set_handle_inheritance handle, true
141
- rescue ChildProcess::Error
142
- # If the IO was set to close on exec previously, this call will fail.
143
- # That's probably OK, since the user explicitly asked for it to be
144
- # closed (at least I have yet to find other cases where this will
145
- # happen...)
146
- end
147
-
148
- handle
149
- end
150
-
151
- def close_handles
152
- Lib.close_handle process_info[:hProcess]
153
- Lib.close_handle process_info[:hThread]
154
-
155
- if @duplex
156
- @stdin = Lib.io_for(Lib.duplicate_handle(@write_pipe), File::WRONLY)
157
- Lib.close_handle @read_pipe
158
- Lib.close_handle @write_pipe
159
- end
160
- end
161
-
162
- def quote_if_necessary(str)
163
- quote = str.start_with?('"') ? "'" : '"'
164
-
165
- case str
166
- when /[\s\\'"]/
167
- [quote, str, quote].join
168
- else
169
- str
170
- end
171
- end
172
- end # ProcessBuilder
173
- end # Windows
1
+ module ChildProcess
2
+ module Windows
3
+ class ProcessBuilder
4
+ attr_accessor :inherit, :detach, :duplex, :environment, :stdout, :stderr
5
+ attr_reader :stdin
6
+
7
+ def initialize(args)
8
+ @args = args
9
+
10
+ @inherit = false
11
+ @detach = false
12
+ @duplex = false
13
+ @environment = nil
14
+
15
+ @stdout = nil
16
+ @stderr = nil
17
+ @stdin = nil
18
+
19
+ @flags = 0
20
+ @cmd_ptr = nil
21
+ @env_ptr = nil
22
+ end
23
+
24
+ def start
25
+ create_command_pointer
26
+ create_environment_pointer
27
+
28
+ setup_detach
29
+ setup_io
30
+
31
+ pid = create_process
32
+ close_handles
33
+
34
+ pid
35
+ end
36
+
37
+ private
38
+
39
+ def create_command_pointer
40
+ string = @args.map { |arg| quote_if_necessary(arg.to_s) }.join ' '
41
+ @cmd_ptr = FFI::MemoryPointer.from_string string
42
+ end
43
+
44
+ def create_environment_pointer
45
+ return unless @environment.kind_of?(Hash) && @environment.any?
46
+
47
+ # inherited env
48
+ strings = ENV.map { |k,v| "#{k}=#{v}\0" }
49
+
50
+ # extras
51
+ @environment.each do |key, value|
52
+ if key.include?("=")
53
+ raise InvalidEnvironmentVariableName, key
54
+ end
55
+
56
+ strings << "#{key}=#{value}\0"
57
+ end
58
+
59
+ strings << "\0" # terminate the env block
60
+ env_str = strings.join
61
+
62
+ @env_ptr = FFI::MemoryPointer.new(:long, env_str.bytesize)
63
+ @env_ptr.put_bytes 0, env_str, 0, env_str.bytesize
64
+ end
65
+
66
+ def create_process
67
+ @startup_info[:lpDesktop] = FFI::MemoryPointer.from_string("test") if $isVirtual
68
+
69
+ ok = Lib.create_process(
70
+ nil, # application name
71
+ @cmd_ptr, # command line
72
+ nil, # process attributes
73
+ nil, # thread attributes
74
+ @inherit, # inherit handles
75
+ @flags, # creation flags
76
+ @env_ptr, # environment
77
+ nil, # current directory
78
+ startup_info, # startup info
79
+ process_info # process info
80
+ )
81
+
82
+ ok or raise LaunchError, Lib.last_error_message
83
+
84
+ process_info[:dwProcessId]
85
+ end
86
+
87
+ def startup_info
88
+ @startup_info ||= StartupInfo.new
89
+ end
90
+
91
+ def process_info
92
+ @process_info ||= ProcessInfo.new
93
+ end
94
+
95
+ def setup_detach
96
+ @flags |= DETACHED_PROCESS if @detach
97
+ end
98
+
99
+ def setup_io
100
+ if @stdout || @stderr
101
+ startup_info[:dwFlags] ||= 0
102
+ startup_info[:dwFlags] |= STARTF_USESTDHANDLES
103
+
104
+ @inherit = true
105
+
106
+ if @stdout
107
+ startup_info[:hStdOutput] = std_stream_handle_for(@stdout)
108
+ end
109
+
110
+ if @stderr
111
+ startup_info[:hStdError] = std_stream_handle_for(@stderr)
112
+ end
113
+ end
114
+
115
+ setup_stdin if @duplex
116
+ end
117
+
118
+ def setup_stdin
119
+ read_pipe_ptr = FFI::MemoryPointer.new(:pointer)
120
+ write_pipe_ptr = FFI::MemoryPointer.new(:pointer)
121
+ sa = SecurityAttributes.new(:inherit => true)
122
+
123
+ ok = Lib.create_pipe(read_pipe_ptr, write_pipe_ptr, sa, 0)
124
+ Lib.check_error ok
125
+
126
+ @read_pipe = read_pipe_ptr.read_pointer
127
+ @write_pipe = write_pipe_ptr.read_pointer
128
+
129
+ @inherit = true
130
+ Lib.set_handle_inheritance @read_pipe, true
131
+ Lib.set_handle_inheritance @write_pipe, false
132
+
133
+ startup_info[:hStdInput] = @read_pipe
134
+ end
135
+
136
+ def std_stream_handle_for(io)
137
+ handle = Lib.handle_for(io)
138
+
139
+ begin
140
+ Lib.set_handle_inheritance handle, true
141
+ rescue ChildProcess::Error
142
+ # If the IO was set to close on exec previously, this call will fail.
143
+ # That's probably OK, since the user explicitly asked for it to be
144
+ # closed (at least I have yet to find other cases where this will
145
+ # happen...)
146
+ end
147
+
148
+ handle
149
+ end
150
+
151
+ def close_handles
152
+ Lib.close_handle process_info[:hProcess]
153
+ Lib.close_handle process_info[:hThread]
154
+
155
+ if @duplex
156
+ @stdin = Lib.io_for(Lib.duplicate_handle(@write_pipe), File::WRONLY)
157
+ Lib.close_handle @read_pipe
158
+ Lib.close_handle @write_pipe
159
+ end
160
+ end
161
+
162
+ def quote_if_necessary(str)
163
+ quote = str.start_with?('"') ? "'" : '"'
164
+
165
+ case str
166
+ when /[\s\\'"]/
167
+ [quote, str, quote].join
168
+ else
169
+ str
170
+ end
171
+ end
172
+ end # ProcessBuilder
173
+ end # Windows
174
174
  end # ChildProcess
@@ -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
@@ -4,6 +4,7 @@ module Sapphire
4
4
 
5
5
  attr_accessor :found_by_type
6
6
  attr_accessor :found_by_value
7
+ attr_accessor :control
7
8
 
8
9
  def initialize(args)
9
10
  return if args.nil?
@@ -11,13 +12,13 @@ module Sapphire
11
12
 
12
13
  if args.is_a? Hash
13
14
  @control = args.fetch :instance if args.has_key? :instance
14
- @found_by_type = @by
15
- @found_by_value = @value
15
+ @found_by_type = args.keys.first
16
+ @found_by_value = args.fetch(args.keys.first)
16
17
  end
17
18
  end
18
19
 
19
20
  def Find(comparator = nil)
20
- @control, @found_by_type, @found_by_value = $driver.FindItemWithWait(@array, comparator) if @control.nil?
21
+ @control, @found_by_type, @found_by_value = $driver.FindItemWithWait(@array, comparator)
21
22
  @control
22
23
  end
23
24
 
@@ -33,7 +34,8 @@ module Sapphire
33
34
  end
34
35
 
35
36
  def FindWithoutWait(comparator = nil)
36
- $driver.FindItemWithoutWait(@array, comparator)
37
+ @control, @found_by_type, @found_by_value = $driver.FindItemWithoutWait(@array, comparator)
38
+ @control
37
39
  end
38
40
 
39
41
  def Text
@@ -42,11 +44,12 @@ module Sapphire
42
44
  end
43
45
 
44
46
  def Click
45
- control = self.Find
46
- control.click
47
+ self.Find if @control.nil?
48
+ @control.click
47
49
  end
48
50
 
49
51
  def MouseOver
52
+ self.Find
50
53
  if(@found_by_type == :id)
51
54
  $driver.ExecuteScript("document.getElementById('"+ @found_by_value +"').style.visibility = 'visible'; ")
52
55
  elsif (@found_by_type == :name)
@@ -69,8 +72,8 @@ module Sapphire
69
72
  EqualsComparison.new(evaluation)
70
73
  end
71
74
 
72
- def Contain(value)
73
- return ContainsComparison.new(ControlEvaluation.new(self.Text, value, self))
75
+ def Contain(expected_value)
76
+ return ContainsComparison.new(ControlEvaluation.new(self.Text, expected_value, self))
74
77
  end
75
78
 
76
79
  def In(values, comparator)
@@ -105,6 +108,7 @@ module Sapphire
105
108
 
106
109
  return result
107
110
  rescue
111
+ puts $!.backtrace if !$verbose.nil?
108
112
  return ControlEvaluation.new(evaluation.left, evaluation.right, self)
109
113
  end
110
114
  end