red-glass 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ require 'observer'
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ class Driver
6
+ include SearchContext
7
+ include Observable
8
+
9
+ def found_element(element)
10
+ changed
11
+ notify_observers element
12
+ end
13
+
14
+ end # Driver
15
+ end # WebDriver
16
+ end # Selenium
@@ -0,0 +1,23 @@
1
+ require 'observer'
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ class Element
6
+ include SearchContext
7
+ include Observable
8
+
9
+ def click
10
+ result = bridge.clickElement @id
11
+ changed
12
+ notify_observers
13
+ result
14
+ end
15
+
16
+ def found_element(element)
17
+ changed
18
+ notify_observers element
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'observer'
2
+
3
+ module Selenium
4
+ module WebDriver
5
+ class Navigation
6
+ include Observable
7
+
8
+ def to(url)
9
+ result = @bridge.get url
10
+ changed
11
+ notify_observers url
12
+ result
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ module Selenium
2
+ module WebDriver
3
+ module SearchContext
4
+
5
+ def find_element(*args)
6
+ how, what = extract_args(args)
7
+
8
+ unless by = FINDERS[how.to_sym]
9
+ raise ArgumentError, "cannot find element by #{how.inspect}"
10
+ end
11
+
12
+ result = bridge.find_element_by by, what.to_s, ref
13
+ self.found_element result
14
+ result
15
+ end
16
+
17
+ def find_elements(*args)
18
+ how, what = extract_args(args)
19
+
20
+ unless by = FINDERS[how.to_sym]
21
+ raise ArgumentError, "cannot find elements by #{how.inspect}"
22
+ end
23
+
24
+ bridge.find_elements_by by, what.to_s, ref
25
+ end
26
+
27
+ end # SearchContext
28
+ end # WebDriver
29
+ end # Selenium
@@ -1,31 +1,64 @@
1
1
  require "selenium-webdriver"
2
2
  require "uuid"
3
3
  require "net/http"
4
+ require_relative "../Selenium/driver"
5
+ require_relative "../Selenium/element"
6
+ require_relative "../Selenium/navigation"
7
+ require_relative "../Selenium/search_context"
4
8
 
5
9
  class RedGlass
6
- attr_accessor :driver, :test_id, :opts, :port, :pid
10
+ attr_accessor :driver, :test_id, :opts, :port, :pid, :recording
7
11
 
8
12
  PROJ_ROOT = File.dirname(__FILE__).to_s
9
13
 
10
14
  def initialize(driver, opts={})
11
15
  @driver = driver
16
+ @driver.navigate.add_observer self
17
+ @driver.add_observer self, :found_element_event
12
18
  @opts = opts
19
+ @recording = false
20
+ end
21
+
22
+ def update(url=nil)
23
+ if @recording
24
+ reload
25
+ end
26
+ end
27
+
28
+ def click_event(url=nil)
29
+ if @recording
30
+ reload if !has_red_glass_js?
31
+ end
32
+ end
33
+
34
+ def found_element_event(element)
35
+ if @recording
36
+ element.add_observer self, :click_event
37
+ end
13
38
  end
14
39
 
15
40
  def start
16
41
  set_config
17
- if !is_server_ready? 1
18
- @pid = Process.spawn("ruby","#{PROJ_ROOT}/red-glass-app.rb")
19
- raise "Red Glass server could not bet started." if !is_server_ready?
20
- Process.detach @pid
21
- end
42
+ start_server
22
43
  uuid = UUID.new
23
44
  @test_id = uuid.generate
24
45
  load_js
46
+ @recording = true
47
+ end
48
+
49
+ def reload
50
+ set_config
51
+ start_server
52
+ load_js
53
+ end
54
+
55
+ def pause
56
+ @recording = false
25
57
  end
26
58
 
27
59
  def stop
28
60
  Process.kill('INT', @pid)
61
+ @recording = false
29
62
  end
30
63
 
31
64
  private
@@ -47,6 +80,14 @@ class RedGlass
47
80
  is_server_ready
48
81
  end
49
82
 
83
+ def start_server
84
+ if !is_server_ready? 1
85
+ @pid = Process.spawn("ruby","#{PROJ_ROOT}/red-glass-app.rb")
86
+ raise "Red Glass server could not bet started." if !is_server_ready?
87
+ Process.detach @pid
88
+ end
89
+ end
90
+
50
91
  def set_config
51
92
  @port = @opts[:red_glass_port].nil? ? '4567' : @opts[:red_glass_port].to_s
52
93
  ENV['red_glass_port'] = @port
@@ -77,11 +118,15 @@ class RedGlass
77
118
  @driver.execute_script raw_js
78
119
  end
79
120
 
121
+ def has_red_glass_js?
122
+ @driver.execute_script "var hasRedGlass = typeof jQuery().redGlass == 'function' ? true : false; return hasRedGlass"
123
+ end
124
+
80
125
  def load_red_glass_js
81
126
  raw_js = File.open(File.expand_path("#{PROJ_ROOT}/public/scripts/jquery.red-glass-0.1.0.js"), 'rb').read
82
- @driver.execute_script raw_js
127
+ @driver.execute_script raw_js if !has_red_glass_js?
83
128
  @driver.execute_script("jQuery(document).redGlass('#{@test_id}', '#{@port}')")
84
- @driver.execute_script "jQuery.noConflict(true)"
129
+ #@driver.execute_script "jQuery.noConflict(true)"
85
130
  end
86
131
 
87
132
  end
@@ -39,7 +39,6 @@
39
39
  </div>
40
40
  <div id="waiting" class="prepend-8 span-8 append-8 last">
41
41
  <h1>Waiting for events</h1>
42
- <img class="push-3" src="/images/ajax-loader.gif"/>
43
42
  </div>
44
43
  </div>
45
44
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red-glass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-05 00:00:00.000000000 Z
12
+ date: 2012-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70208572273860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *70208572273860
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: em-websocket
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70208572273240 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: '0'
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *70208572273240
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: thin
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &70208572272580 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: '0'
54
44
  type: :runtime
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
46
+ version_requirements: *70208572272580
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: selenium-webdriver
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &70208572271860 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ! '>='
@@ -69,15 +54,10 @@ dependencies:
69
54
  version: '0'
70
55
  type: :runtime
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
57
+ version_requirements: *70208572271860
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: json
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &70208572271180 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ! '>='
@@ -85,15 +65,10 @@ dependencies:
85
65
  version: '0'
86
66
  type: :runtime
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
68
+ version_requirements: *70208572271180
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: uuid
96
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &70208572270400 !ruby/object:Gem::Requirement
97
72
  none: false
98
73
  requirements:
99
74
  - - ! '>='
@@ -101,15 +76,10 @@ dependencies:
101
76
  version: '0'
102
77
  type: :runtime
103
78
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
79
+ version_requirements: *70208572270400
110
80
  - !ruby/object:Gem::Dependency
111
81
  name: rack-test
112
- requirement: !ruby/object:Gem::Requirement
82
+ requirement: &70208572285860 !ruby/object:Gem::Requirement
113
83
  none: false
114
84
  requirements:
115
85
  - - ! '>='
@@ -117,12 +87,7 @@ dependencies:
117
87
  version: '0'
118
88
  type: :development
119
89
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
90
+ version_requirements: *70208572285860
126
91
  description: Red Glass works alongside Selenium to observe browser events, and provides
127
92
  an interactive log which illustrates changes to the DOM during an automation session.
128
93
  email: frankj.ohara@gmail.com
@@ -202,7 +167,11 @@ files:
202
167
  - lib/red-glass/red_glass.rb
203
168
  - lib/red-glass/views/index.erb
204
169
  - lib/red-glass.rb
205
- homepage: http://rubygems.org/gems/red-glass
170
+ - lib/Selenium/driver.rb
171
+ - lib/Selenium/element.rb
172
+ - lib/Selenium/navigation.rb
173
+ - lib/Selenium/search_context.rb
174
+ homepage: https://github.com/fohara/red-glass
206
175
  licenses: []
207
176
  post_install_message:
208
177
  rdoc_options: []
@@ -222,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
191
  version: '0'
223
192
  requirements: []
224
193
  rubyforge_project:
225
- rubygems_version: 1.8.24
194
+ rubygems_version: 1.8.10
226
195
  signing_key:
227
196
  specification_version: 3
228
197
  summary: ! 'Red Glass: Selenium event pane'