zhimin-rwebspec 1.4.0 → 1.4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -2,6 +2,8 @@ CHANGELOG
2
2
  =========
3
3
  1.4.0
4
4
  Renamed to rwebspec
5
+ 1.9 compliance
6
+ TODO: support JRuby to run against Firefox and Celerity
5
7
 
6
8
  1.3.1
7
9
  [Enhancement] better absolutize the hyperlinks in dumped page source
data/Rakefile CHANGED
@@ -10,13 +10,13 @@ $:.unshift(File.dirname(__FILE__) + "/lib")
10
10
  #require 'rwebspec'
11
11
 
12
12
  desc "Default task"
13
- task :default => [ :clean, :spec, :gem]
14
- # task :default => [ :clean, :spec, :rdoc, :gem]
13
+ task :default => [ :clean, :spec, :rdoc, :chm, :gem]
15
14
 
16
15
  desc "Clean generated files"
17
16
  task :clean do
18
17
  rm_rf 'pkg'
19
18
  rm_rf 'doc'
19
+ rm_rf 'chm'
20
20
  end
21
21
 
22
22
  desc 'Run all specs'
@@ -39,7 +39,7 @@ end
39
39
  # using DarkFish - http://deveiate.org/projects/Darkfish-Rdoc/
40
40
  Rake::RDocTask.new do |rdoc|
41
41
  rdoc.rdoc_dir = 'doc'
42
- rdoc.title = 'rWebUnit'
42
+ rdoc.title = 'RWebSpec'
43
43
  rdoc.rdoc_files.include('lib/rwebspec.rb')
44
44
  rdoc.rdoc_files.include('lib/rwebspec/*.rb')
45
45
  rdoc.options += [
@@ -48,10 +48,22 @@ Rake::RDocTask.new do |rdoc|
48
48
  ]
49
49
  end
50
50
 
51
+ Rake::RDocTask.new("chm") do |rdoc|
52
+ rdoc.rdoc_dir = 'chm'
53
+ rdoc.title = 'RWebSpec'
54
+ rdoc.rdoc_files.include('lib/rwebspec.rb')
55
+ rdoc.rdoc_files.include('lib/rwebspec/*.rb')
56
+ rdoc.options += [
57
+ '-SHN',
58
+ '-f', 'chm', # This is the important bit
59
+ ]
60
+ end
61
+
62
+
51
63
  spec = Gem::Specification.new do |s|
52
64
  s.platform= Gem::Platform::RUBY
53
65
  s.name = "rwebspec"
54
- s.version = "1.4.0"
66
+ s.version = "1.4.0.1"
55
67
  s.summary = "Executable functional specification for web applications in RSpec syntax and Watir"
56
68
  # s.description = ""
57
69
 
@@ -346,7 +346,7 @@ module RWebSpec
346
346
  spec_run_dir_name = spec_run_id.to_s.rjust(4, "0") unless spec_run_id == "unknown"
347
347
  to_dir = File.join($ITEST2_DUMP_DIR, spec_run_dir_name)
348
348
  else
349
- to_dir = ENV['TEMP_DIR'] || "C:\\temp"
349
+ to_dir = ENV['TEMP_DIR'] || (is_windows? ? "C:\\temp" : "/tmp")
350
350
  end
351
351
 
352
352
  if options[:filename]
@@ -401,6 +401,7 @@ module RWebSpec
401
401
  # absolutize_page referencs using hpricot
402
402
  #
403
403
  def absolutize_page_hpricot(content, base_url, parent_url)
404
+ return absolutize_page(content, base_url, parent_url) if RUBY_PLATFORM == 'java'
404
405
  begin
405
406
  require 'hpricot'
406
407
  doc = Hpricot(content)
@@ -502,6 +503,7 @@ module RWebSpec
502
503
  # Support browser (IE) operations using unicode
503
504
  # Example:
504
505
  # click_button("Google 搜索")
506
+ # Reference: http://jira.openqa.org/browse/WTR-219
505
507
  def support_utf8
506
508
  if is_windows?
507
509
  require 'win32ole'
@@ -42,54 +42,94 @@ module RWebSpec
42
42
  attr_accessor :context
43
43
 
44
44
  def initialize(base_url = nil, existing_browser = nil, options = {})
45
- default_options = {:speed => "zippy", :visible => true,
46
- :highlight_colour => 'yellow', :close_others => true}
45
+ default_options = {:speed => "zippy",
46
+ :visible => true,
47
+ :highlight_colour => 'yellow',
48
+ :close_others => true
49
+ }
47
50
  options = default_options.merge options
48
51
  @context = Context.new base_url if base_url
49
52
 
50
- if $celerity_loaded
51
- @browser = Celerity::Browser.new(:proxy => options[:proxy])
52
- @browser.goto(base_url)
53
- else
54
- if (existing_browser) then
55
- @browser = existing_browser
56
- else
57
- if (options[:firefox] && $firewatir_loaded) || ($firewatir_loaded and !$watir_loaded)
58
- # JSSH is running, 9997
59
- begin
60
- require 'net/telnet'
61
- firefox_jssh = Net::Telnet::new("Host" => "127.0.0.1", "Port" => 9997)
62
- FireWatir::Firefox.firefox_started = true
63
- rescue => e
64
- # puts "debug: XXX #{e}"
65
- sleep 1
53
+ case RUBY_PLATFORM
54
+ when /java/i
55
+ # Java, maybe firewatir or celerity
56
+ puts "Ruby java platform"
57
+ raise "Not supported, no FireWatir or Celerity detected" unless $firewatir_loaded || $celerity_loaded
58
+ if $firewatir_loaded && $celerity_loaded then
59
+ # choose one out of two, :default to celerity
60
+ if options[:firefox] then
61
+ initialize_firefox_browser(existing_browser, base_url, options)
62
+ else
63
+ initialize_celerity_browser(base_url, options)
66
64
  end
67
- @browser = FireWatir::Firefox.start(base_url)
68
- elsif $watir_loaded
69
- @browser = Watir::IE.new
65
+ elsif $firewatir_loaded
66
+ initialize_firefox_browser(existing_browser, base_url, options)
67
+ else
68
+ initialize_celerity_browser(base_url, options)
70
69
  end
71
- end
72
70
 
71
+ when /mswin|windows|mingw/i
72
+ puts "Ruby windows platform"
73
+ raise "Not supported, no Watir or FireWatir detected" unless $watir_loaded || $firewatir_loaded
74
+ if $firewatir_loaded && options[:firefox] then
75
+ initialize_firefox_browser(existing_browser, base_url, options)
76
+ else
77
+ initialize_ie_browser(existing_browser, options)
78
+ end
79
+ else
80
+ raise "Not supported, no FireWatirdetected" unless $firewatir_loaded
81
+ puts "Ruby Linux or Mac platform: firefox"
82
+ initialize_firefox_browser(base_url, options)
73
83
  end
84
+ end
74
85
 
75
- raise "rWebUnit initialiazation error, most likely Watir or Firewatir not present" if @browser.nil?
76
- if $watir_loaded && @browser.class == Watir::IE
77
- if $ITEST2_EMULATE_TYPING && $ITEST2_TYPING_SPEED then
78
- @browser.set_slow_speed if $ITEST2_TYPING_SPEED == 'slow'
79
- @browser.set_fast_speed if $ITEST2_TYPING_SPEED == 'fast'
80
- else
81
- @browser.speed = :zippy
82
- end
83
- @browser.activeObjectHighLightColor = options[:highlight_colour]
84
- @browser.visible = options[:visible] unless $HIDE_IE
86
+ def initialize_firefox_browser(existing_browser, base_url, options)
87
+ if existing_browser then
88
+ @browser = existing_browser
89
+ return
90
+ end
91
+ # JSSH is running, 9997
92
+ begin
93
+ require 'net/telnet'
94
+ firefox_jssh = Net::Telnet::new("Host" => "127.0.0.1", "Port" => 9997)
95
+ FireWatir::Firefox.firefox_started = true
96
+ rescue => e
97
+ # puts "debug: XXX #{e}"
98
+ sleep 1
99
+ end
100
+ @browser = FireWatir::Firefox.start(base_url)
101
+ end
85
102
 
86
- if RUBY_VERSION =~ /^1\.8/ && options[:close_others] then
87
- puts "close other browser instances not working yet in Ruby 1.9.1 version of Watir"
88
- @browser.close_others
89
- end
103
+ def initialize_celerity_browser(base_url, options)
104
+ default_celerity_options = { :proxy => nil, :browser => :firefox, :resynchronize => true, :log_level => :off }
105
+ options = default_celerity_options.merge options
106
+ options.each { |k, v| options.delete(k) unless default_celerity_options.keys.include?(k)}
107
+ puts "Starting Celerity: #{options.inspect}"
108
+ @browser = Celerity::Browser.new(options)
109
+ @browser.goto(base_url)
110
+ end
90
111
 
112
+ def initialize_ie_browser(existing_browser, options)
113
+ if existing_browser then
114
+ @browser = existing_browser
115
+ return
91
116
  end
92
117
 
118
+ @browser = Watir::IE.new
119
+ if $ITEST2_EMULATE_TYPING && $ITEST2_TYPING_SPEED then
120
+ @browser.set_slow_speed if $ITEST2_TYPING_SPEED == 'slow'
121
+ @browser.set_fast_speed if $ITEST2_TYPING_SPEED == 'fast'
122
+ else
123
+ @browser.speed = :zippy
124
+ end
125
+ @browser.activeObjectHighLightColor = options[:highlight_colour]
126
+ @browser.visible = options[:visible] unless $HIDE_IE
127
+ #NOTE: close_others fails
128
+ if RUBY_VERSION =~ /^1\.8/ && options[:close_others] then
129
+ @browser.close_others
130
+ else
131
+ puts "close other browser instances not working yet in Ruby 1.9.1 version of Watir"
132
+ end
93
133
  end
94
134
 
95
135
  def self.reuse(base_url, options)
@@ -139,6 +179,7 @@ module RWebSpec
139
179
  @browser.html()
140
180
  #@browser.document.body
141
181
  end
182
+
142
183
  alias html_body page_source
143
184
 
144
185
  def html
@@ -150,10 +191,13 @@ module RWebSpec
150
191
  end
151
192
 
152
193
  def page_title
153
- if is_firefox?
194
+ case @browser.class.to_s
195
+ when "FireWatir::Firefox"
154
196
  @browser.title
155
- else
197
+ when "Watir::IE"
156
198
  @browser.document.title
199
+ else
200
+ @browser.title
157
201
  end
158
202
  end
159
203
 
@@ -188,13 +232,17 @@ module RWebSpec
188
232
  # Close the browser window. Useful for automated test suites to reduce
189
233
  # test interaction.
190
234
  def close_browser
191
- if is_firefox? then
235
+ case @browser.class.to_s
236
+ when "FireWatir::Firefox"
192
237
  @browser.close
238
+ when "Watir::IE"
239
+ @browser.getIE.quit
193
240
  else
194
- @browser.getIE.quit
241
+ puts "#{@browser.class} can't close, ignore"
195
242
  end
196
243
  sleep 2
197
244
  end
245
+
198
246
  alias close close_browser
199
247
 
200
248
  #TODO determine browser type, check FireWatir support or not
@@ -273,6 +321,7 @@ module RWebSpec
273
321
  wait_before_and_after { text_field(:name, name).set(text) }
274
322
  end
275
323
  end
324
+
276
325
  alias set_form_element enter_text_into_field_with_name
277
326
  alias enter_text enter_text_into_field_with_name
278
327
 
@@ -62,6 +62,7 @@ module RWebSpec
62
62
  def source
63
63
  @web_browser.page_source
64
64
  end
65
+ alias html source
65
66
 
66
67
  # return current page title
67
68
  def title
@@ -75,9 +76,10 @@ module RWebSpec
75
76
 
76
77
  # TO validate
77
78
  def contains?(ary)
79
+ return true if ary.nil?
78
80
  the_page_source = source
79
81
  found = false
80
- ary.each do |str|
82
+ ary.each_line do |str|
81
83
  found ||= the_page_source.include?(str)
82
84
  end
83
85
  return found
data/lib/rwebspec.rb CHANGED
@@ -13,7 +13,7 @@ end
13
13
  require 'active_support/core_ext'
14
14
  require 'spec'
15
15
 
16
- RWEBUNIT_VERSION = "1.4.0"
16
+ RWEBSPEC_VERSION = RWEBUNIT_VERSION = "1.4.0.1"
17
17
 
18
18
  # Extra full path to load libraries
19
19
  require File.dirname(__FILE__) + "/rwebspec/using_pages"
@@ -1,65 +1,69 @@
1
+ if RUBY_PLATFORM == "java" then
2
+ # no need to load firefox extension
3
+ else
4
+ module FireWatir
5
+ class Firefox
1
6
 
2
- module FireWatir
3
- class Firefox
7
+ @@firefox_started = false
4
8
 
5
- @@firefox_started = false
6
-
7
- def initialize(options = {})
8
- if(options.kind_of?(Integer))
9
- options = {:waitTime => options}
10
- end
9
+ def initialize(options = {})
10
+ if(options.kind_of?(Integer))
11
+ options = {:waitTime => options}
12
+ end
11
13
 
12
- if(options[:profile])
13
- profile_opt = "-no-remote -P #{options[:profile]}"
14
- else
15
- profile_opt = ""
16
- end
14
+ if(options[:profile])
15
+ profile_opt = "-no-remote -P #{options[:profile]}"
16
+ else
17
+ profile_opt = ""
18
+ end
17
19
 
18
- waitTime = options[:waitTime] || 2
20
+ waitTime = options[:waitTime] || 2
19
21
 
20
- case RUBY_PLATFORM
21
- when /mswin/
22
- # Get the path to Firefox.exe using Registry.
23
- require 'win32/registry.rb'
24
- path_to_bin = ""
25
- Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Mozilla\Mozilla Firefox') do |reg|
26
- keys = reg.keys
27
- reg1 = Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Mozilla\\Mozilla Firefox\\#{keys[0]}\\Main")
28
- reg1.each do |subkey, type, data|
29
- if(subkey =~ /pathtoexe/i)
30
- path_to_bin = data
22
+ case RUBY_PLATFORM
23
+ when /mswin/
24
+ # Get the path to Firefox.exe using Registry.
25
+ require 'win32/registry.rb'
26
+ path_to_bin = ""
27
+ Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Mozilla\Mozilla Firefox') do |reg|
28
+ keys = reg.keys
29
+ reg1 = Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Mozilla\\Mozilla Firefox\\#{keys[0]}\\Main")
30
+ reg1.each do |subkey, type, data|
31
+ if(subkey =~ /pathtoexe/i)
32
+ path_to_bin = data
33
+ end
31
34
  end
32
35
  end
33
- end
34
36
 
35
- when /linux/i
36
- path_to_bin = `which firefox`.strip
37
- when /darwin/i
38
- path_to_bin = '/Applications/Firefox.app/Contents/MacOS/firefox'
39
- when /java/
40
- raise "Not implemented: Create a browser finder in JRuby"
41
- end
37
+ when /linux/i
38
+ path_to_bin = `which firefox`.strip
39
+ when /darwin/i
40
+ path_to_bin = '/Applications/Firefox.app/Contents/MacOS/firefox'
41
+ when /java/
42
+ raise "Not implemented: Create a browser finder in JRuby"
43
+ end
42
44
 
43
- @t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")} unless @@firefox_started
45
+ @t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")} unless @@firefox_started
44
46
 
45
- sleep waitTime
46
- begin
47
- set_defaults()
48
- rescue Watir::Exception::UnableToStartJSShException
49
- if !@t # no new thread starting browser, try again
50
- puts "Firefox with JSSH not detected after you indicated @@firefox_started"
51
- @t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")}
52
- sleep waitTime
53
- set_defaults
47
+ sleep waitTime
48
+ begin
49
+ set_defaults()
50
+ rescue Watir::Exception::UnableToStartJSShException
51
+ if !@t # no new thread starting browser, try again
52
+ puts "Firefox with JSSH not detected after you indicated @@firefox_started"
53
+ @t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")}
54
+ sleep waitTime
55
+ set_defaults
56
+ end
54
57
  end
58
+ get_window_number()
59
+ set_browser_document()
55
60
  end
56
- get_window_number()
57
- set_browser_document()
58
- end
59
61
 
60
- def self.firefox_started=(value)
61
- @@firefox_started = value
62
- end
62
+ def self.firefox_started=(value)
63
+ @@firefox_started = value
64
+ end
63
65
 
66
+ end
64
67
  end
68
+
65
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zhimin-rwebspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhimin Zhan