diff --git a/.project b/.project index b401d3fe..d7922141 100644 --- a/.project +++ b/.project @@ -1,17 +1,17 @@ - - - watir-all - - - - - - org.rubypeople.rdt.core.rubybuilder - - - - - - org.rubypeople.rdt.core.rubynature - - + + + watir-all + + + + + + org.rubypeople.rdt.core.rubybuilder + + + + + + org.rubypeople.rdt.core.rubynature + + diff --git a/Rakefile b/Rakefile index 8217f356..2228914e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,86 +1,86 @@ -require 'rubygems' -require 'rake/clean' -require 'ftools' -require 'fileutils' -require 'rake/testtask' -gem 'ci_reporter' -require 'ci/reporter/rake/test_unit' -projects = ['watir', 'firewatir', 'commonwatir'] - -desc "Generate all the Watir gems" -task :gems do - projects.each do |x| - Dir.chdir(x) {puts `rake.bat gem`} - end - FileUtils.makedirs 'gems' - gems = Dir['*/pkg/*.gem'] - gems.each {|gem| FileUtils.install gem, 'gems'} -end - -desc "Clean all the projects" -task :clean_subprojects do - projects.each do |x| - Dir.chdir(x) {puts `rake.bat clean`} - end -end - -task :clean => [:clean_subprojects] -CLEAN << 'gems/*' - -desc 'Run core_tests tests for IE' -Rake::TestTask.new :core_tests do |t| - t.test_files = FileList['watir/unittests/core_tests.rb'] - t.verbose = true -end - -desc 'Run mozilla_all_tests for FireFox' -Rake::TestTask.new :mozilla_all_tests do |t| - t.test_files = FileList['firewatir/unittests/mozilla_all_tests.rb'] - t.verbose = true -end - -namespace :cruise do - def move_reports(report_dir) - Dir[report_dir].each { |e| File::move(e, ENV['CC_BUILD_ARTIFACTS']) } - File::copy("transform-results.xsl", ENV['CC_BUILD_ARTIFACTS']) - add_style_sheet_to_reports(ENV['CC_BUILD_ARTIFACTS'] + '/*.xml') - end - - def add_style_sheet_to_reports(report_dir) - dir_arr = Dir[report_dir] - return if dir_arr.empty? - dir_arr.each do |f| - sContent = File.readlines(f, '\n') - sContent.each do |line| - line.sub!(/<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>/, "\n") - end - File.open(f, "w+") { |file| file.puts sContent } - end - end - - task :move_reports_ie do - move_reports "watir/test/reports/*.xml" - end - task :move_reports_ff do - move_reports "firewatir/test/reports/*.xml" - end - - task :ie_core_tests => ['ci:setup:testunit', :core_tests, :move_reports_ie] - task :ff_mozilla_all_tests => ['ci:setup:testunit', :mozilla_all_tests, :move_reports_ff] -end - -desc 'Build the html for the website (wtr.rubyforge.org)' -task :website do - Dir.chdir 'doc' do - puts system('call webgen -V 1') - end -end - -desc 'Build and publish the html for the website at wtr.rubyforge.org' -task :publish_website => [:website] do - user = 'bret' # userid on rubyforge - puts system("call pscp -v -r doc\\output\\*.* #{user}@rubyforge.org:/var/www/gforge-projects/wtr") -end - -desc 'Run tests for all browser' -task :test => [:test_ie, :test_ff] +require 'rubygems' +require 'rake/clean' +require 'ftools' +require 'fileutils' +require 'rake/testtask' +gem 'ci_reporter' +require 'ci/reporter/rake/test_unit' +projects = ['watir', 'firewatir', 'commonwatir'] + +desc "Generate all the Watir gems" +task :gems do + projects.each do |x| + Dir.chdir(x) {puts `rake.bat gem`} + end + FileUtils.makedirs 'gems' + gems = Dir['*/pkg/*.gem'] + gems.each {|gem| FileUtils.install gem, 'gems'} +end + +desc "Clean all the projects" +task :clean_subprojects do + projects.each do |x| + Dir.chdir(x) {puts `rake.bat clean`} + end +end + +task :clean => [:clean_subprojects] +CLEAN << 'gems/*' + +desc 'Run core_tests tests for IE' +Rake::TestTask.new :core_tests do |t| + t.test_files = FileList['watir/unittests/core_tests.rb'] + t.verbose = true +end + +desc 'Run mozilla_all_tests for FireFox' +Rake::TestTask.new :mozilla_all_tests do |t| + t.test_files = FileList['firewatir/unittests/mozilla_all_tests.rb'] + t.verbose = true +end + +namespace :cruise do + def move_reports(report_dir) + Dir[report_dir].each { |e| File::move(e, ENV['CC_BUILD_ARTIFACTS']) } + File::copy("transform-results.xsl", ENV['CC_BUILD_ARTIFACTS']) + add_style_sheet_to_reports(ENV['CC_BUILD_ARTIFACTS'] + '/*.xml') + end + + def add_style_sheet_to_reports(report_dir) + dir_arr = Dir[report_dir] + return if dir_arr.empty? + dir_arr.each do |f| + sContent = File.readlines(f, '\n') + sContent.each do |line| + line.sub!(/<\?xml version=\"1.0\" encoding=\"UTF-8\"\?>/, "\n") + end + File.open(f, "w+") { |file| file.puts sContent } + end + end + + task :move_reports_ie do + move_reports "watir/test/reports/*.xml" + end + task :move_reports_ff do + move_reports "firewatir/test/reports/*.xml" + end + + task :ie_core_tests => ['ci:setup:testunit', :core_tests, :move_reports_ie] + task :ff_mozilla_all_tests => ['ci:setup:testunit', :mozilla_all_tests, :move_reports_ff] +end + +desc 'Build the html for the website (wtr.rubyforge.org)' +task :website do + Dir.chdir 'doc' do + puts system('call webgen -V 1') + end +end + +desc 'Build and publish the html for the website at wtr.rubyforge.org' +task :publish_website => [:website] do + user = 'bret' # userid on rubyforge + puts system("call pscp -v -r doc\\output\\*.* #{user}@rubyforge.org:/var/www/gforge-projects/wtr") +end + +desc 'Run tests for all browser' +task :test => [:test_ie, :test_ff] diff --git a/commonwatir/.project b/commonwatir/.project index 37696a7d..c41e41e7 100644 --- a/commonwatir/.project +++ b/commonwatir/.project @@ -1,17 +1,17 @@ - - - watir-common - - - - - - org.rubypeople.rdt.core.rubybuilder - - - - - - org.rubypeople.rdt.core.rubynature - - + + + watir-common + + + + + + org.rubypeople.rdt.core.rubybuilder + + + + + + org.rubypeople.rdt.core.rubynature + + diff --git a/commonwatir/History.txt b/commonwatir/History.txt index 94179b5f..04fd563d 100644 --- a/commonwatir/History.txt +++ b/commonwatir/History.txt @@ -1,5 +1,5 @@ -=== 0.0.1 / 2008-08-28 - -* Created - - +=== 0.0.1 / 2008-08-28 + +* Created + + diff --git a/commonwatir/Manifest.txt b/commonwatir/Manifest.txt index 01ad32d6..2acad50b 100644 --- a/commonwatir/Manifest.txt +++ b/commonwatir/Manifest.txt @@ -1,14 +1,14 @@ -History.txt -Manifest.txt -README.txt -Rakefile -lib/watir.rb -lib/commonwatir.rb -lib/watir/assertions.rb -lib/watir/browser.rb -lib/watir/browsers.rb -lib/watir/exceptions.rb -lib/watir/matches.rb -lib/watir/options.rb -lib/watir/testcase.rb -lib/watir/waiter.rb +History.txt +Manifest.txt +README.txt +Rakefile +lib/watir.rb +lib/commonwatir.rb +lib/watir/assertions.rb +lib/watir/browser.rb +lib/watir/browsers.rb +lib/watir/exceptions.rb +lib/watir/matches.rb +lib/watir/options.rb +lib/watir/testcase.rb +lib/watir/waiter.rb diff --git a/commonwatir/README.txt b/commonwatir/README.txt index a53a2c5d..3dfeffea 100644 --- a/commonwatir/README.txt +++ b/commonwatir/README.txt @@ -1,48 +1,48 @@ -= commonwatir - -* FIX (url) - -== DESCRIPTION: - -Common code used by Watir and FireWatir - -== FEATURES/PROBLEMS: - -* FIX (list of features or problems) - -== SYNOPSIS: - - FIX (code sample of usage) - -== REQUIREMENTS: - -* FIX (list of requirements) - -== INSTALL: - -* sudo gem install commonwatir - -== LICENSE: - -(The MIT License) - -Copyright (c) 2008 Bret Pettichord - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -'Software'), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. += commonwatir + +* FIX (url) + +== DESCRIPTION: + +Common code used by Watir and FireWatir + +== FEATURES/PROBLEMS: + +* FIX (list of features or problems) + +== SYNOPSIS: + + FIX (code sample of usage) + +== REQUIREMENTS: + +* FIX (list of requirements) + +== INSTALL: + +* sudo gem install commonwatir + +== LICENSE: + +(The MIT License) + +Copyright (c) 2008 Bret Pettichord + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/commonwatir/Rakefile b/commonwatir/Rakefile index e25916a8..fde3b35e 100644 --- a/commonwatir/Rakefile +++ b/commonwatir/Rakefile @@ -1,9 +1,9 @@ -require 'rubygems' -require 'hoe' -require './lib/commonwatir.rb' - -Hoe.new('commonwatir', CommonWatir::VERSION) do |p| - p.rubyforge_name = 'wtr' - p.developer('Bret Pettichord', 'bret@watircraft.com') - p.extra_deps << 'user-choices' -end +require 'rubygems' +require 'hoe' +require './lib/commonwatir.rb' + +Hoe.new('commonwatir', CommonWatir::VERSION) do |p| + p.rubyforge_name = 'wtr' + p.developer('Bret Pettichord', 'bret@watircraft.com') + p.extra_deps << 'user-choices' +end diff --git a/commonwatir/lib/commonwatir.rb b/commonwatir/lib/commonwatir.rb index 08e69605..315095ae 100644 --- a/commonwatir/lib/commonwatir.rb +++ b/commonwatir/lib/commonwatir.rb @@ -1,3 +1,3 @@ -class CommonWatir - VERSION = '1.6.2' -end +class CommonWatir + VERSION = '1.6.2' +end diff --git a/commonwatir/lib/watir.rb b/commonwatir/lib/watir.rb index 96411e35..44222c16 100644 --- a/commonwatir/lib/watir.rb +++ b/commonwatir/lib/watir.rb @@ -1,6 +1,6 @@ -# The 'watir' library loads the common watir code, common to all watir -# implementations. The 'watir/browser' library will autoload the actual -# implementations. - -require 'watir/waiter' -require 'watir/browser' +# The 'watir' library loads the common watir code, common to all watir +# implementations. The 'watir/browser' library will autoload the actual +# implementations. + +require 'watir/waiter' +require 'watir/browser' diff --git a/commonwatir/lib/watir/assertions.rb b/commonwatir/lib/watir/assertions.rb index 19c40746..0cba368c 100644 --- a/commonwatir/lib/watir/assertions.rb +++ b/commonwatir/lib/watir/assertions.rb @@ -1,44 +1,44 @@ -require 'test/unit/assertions' - -module Watir - # Verification methods - module Assertions - include Test::Unit::Assertions - - # Log a failure if the boolean is true. The message is the failure - # message logged. - # Whether true or false, the assertion count is incremented. - def verify boolean, message = 'verify failed.' - add_assertion - add_failure message.to_s, caller unless boolean - end - - def verify_equal expected, actual, message=nil - full_message = build_message(message, < expected but was -. -EOT - verify(expected == actual, full_message) - end - def verify_match pattern, string, message=nil - pattern = case(pattern) - when String - Regexp.new(Regexp.escape(pattern)) - else - pattern - end - full_message = build_message(message, " expected to be =~\n.", string, pattern) - verify(string =~ pattern, full_message) - end - - end - -end -module Test::Unit::Assertions - def assert_false(boolean, message=nil) - _wrap_assertion do - assert_block("assert should not be called with a block.") { !block_given? } - assert_block(build_message(message, " is not false.", boolean)) { !boolean } - end - end -end +require 'test/unit/assertions' + +module Watir + # Verification methods + module Assertions + include Test::Unit::Assertions + + # Log a failure if the boolean is true. The message is the failure + # message logged. + # Whether true or false, the assertion count is incremented. + def verify boolean, message = 'verify failed.' + add_assertion + add_failure message.to_s, caller unless boolean + end + + def verify_equal expected, actual, message=nil + full_message = build_message(message, < expected but was +. +EOT + verify(expected == actual, full_message) + end + def verify_match pattern, string, message=nil + pattern = case(pattern) + when String + Regexp.new(Regexp.escape(pattern)) + else + pattern + end + full_message = build_message(message, " expected to be =~\n.", string, pattern) + verify(string =~ pattern, full_message) + end + + end + +end +module Test::Unit::Assertions + def assert_false(boolean, message=nil) + _wrap_assertion do + assert_block("assert should not be called with a block.") { !block_given? } + assert_block(build_message(message, " is not false.", boolean)) { !boolean } + end + end +end diff --git a/commonwatir/lib/watir/browser.rb b/commonwatir/lib/watir/browser.rb index 654a553e..ffa61524 100644 --- a/commonwatir/lib/watir/browser.rb +++ b/commonwatir/lib/watir/browser.rb @@ -1,149 +1,149 @@ -# watir/browser -require 'watir/options' -module Watir - -=begin rdoc - -Watir is a family of open-source drivers for automating web browsers. You -can use it to write tests that are easy to read and maintain. - -Watir drives browsers the same way people do. It clicks links, fills in forms, -presses buttons. Watir also checks results, such as whether expected text -appears on a page. - -The Watir family currently includes support for Internet Explorer (on Windows), -Firefox (on Windows, Mac and Linux) and Safari (on Mac). - -Project Homepage: http://wtr.rubyforge.org - -This Browser module provides a generic interface -that tests can use to access any browser. The actual browser (and thus -the actual Watir driver) is determined at runtime based on configuration -settings. - - require 'watir' - browser = Watir::Browser.new - browser.goto 'http://google.com' - browser.text_field(:name, 'q').set 'pickaxe' - browser.button(:name, 'btnG').click - if browser.text.include? 'Programming Ruby' - puts 'Text was found' - else - puts 'Text was not found' - end - -A comprehensive summary of the Watir API can be found here -http://wiki.openqa.org/display/WTR/Methods+supported+by+Element - -There are two ways to configure the browser that will be used by your tests. - -One is to set the +watir_browser+ environment variable to +ie+ or +firefox+. -(How you do this depends on your platform.) - -The other is to create a file that looks like this. - - browser: ie - -And then to add this line to your script, after the require statement and -before you invoke Browser.new. - - Watir.options_file = 'path/to/the/file/you/just/created' - -=end rdoc - - module Browser - @@browser_classes = {} - @@sub_options = {} - @@default = nil - class << self - - # Create a new instance of a browser driver, as determined by the - # configuration settings. (Don't be fooled: this is not actually - # an instance of Browser class.) - def new - set_sub_options - klass.new - end - # Create a new instance as with #new and start the browser on the - # specified url. - def start url - set_sub_options - klass.start url - end - # Attach to an existing browser. - def attach(how, what) - set_sub_options - klass.attach(how, what) - end - def set_options options - return unless defined?(klass.set_options) - klass.set_options options - end - def options - return {} unless defined?(klass.options) - klass.options - end - - def klass - key = Watir.options[:browser] - eval @@browser_classes[key] # this triggers the autoload - end - private :klass - # Add support for the browser option, using the specified class, - # provided as a string. Optionally, additional options supported by - # the class can be specified as an array of symbols. Options specified - # by the user and included in this list will be passed (as a hash) to - # the set_options class method (if defined) before creating an instance. - def support hash_args - option = hash_args[:name] - class_string = hash_args[:class] - additional_options = hash_args[:options] - library = hash_args[:library] - gem = hash_args[:gem] || library - - @@browser_classes[option] = class_string - @@sub_options[option] = additional_options - - autoload class_string, library - activate_gem gem, option - end - - def default - @@default - end - # Specifies a default browser. Must be specified before options are parsed. - def default= option - @@default = option - end - # Returns the names of the browsers that are supported by this module. - # These are the options for 'watir_browser' (env var) or 'browser:' (yaml). - def browser_names - @@browser_classes.keys - end - - private - def autoload class_string, library - mod, klass = class_string.split('::') - eval "module ::#{mod}; autoload :#{klass}, '#{library}'; end" - end - # Activate the gem (if installed). The default browser will be set - # to the first gem that activates. - def activate_gem gem_name, option - begin - gem gem_name - @@default ||= option - rescue Gem::LoadError - end - end - def set_sub_options - sub_options = @@sub_options[Watir.options[:browser]] - return if sub_options.nil? - specified_options = Watir.options.reject {|k, v| !sub_options.include? k} - self.set_options specified_options - end - end - end - -end - -require 'watir/browsers' +# watir/browser +require 'watir/options' +module Watir + +=begin rdoc + +Watir is a family of open-source drivers for automating web browsers. You +can use it to write tests that are easy to read and maintain. + +Watir drives browsers the same way people do. It clicks links, fills in forms, +presses buttons. Watir also checks results, such as whether expected text +appears on a page. + +The Watir family currently includes support for Internet Explorer (on Windows), +Firefox (on Windows, Mac and Linux) and Safari (on Mac). + +Project Homepage: http://wtr.rubyforge.org + +This Browser module provides a generic interface +that tests can use to access any browser. The actual browser (and thus +the actual Watir driver) is determined at runtime based on configuration +settings. + + require 'watir' + browser = Watir::Browser.new + browser.goto 'http://google.com' + browser.text_field(:name, 'q').set 'pickaxe' + browser.button(:name, 'btnG').click + if browser.text.include? 'Programming Ruby' + puts 'Text was found' + else + puts 'Text was not found' + end + +A comprehensive summary of the Watir API can be found here +http://wiki.openqa.org/display/WTR/Methods+supported+by+Element + +There are two ways to configure the browser that will be used by your tests. + +One is to set the +watir_browser+ environment variable to +ie+ or +firefox+. +(How you do this depends on your platform.) + +The other is to create a file that looks like this. + + browser: ie + +And then to add this line to your script, after the require statement and +before you invoke Browser.new. + + Watir.options_file = 'path/to/the/file/you/just/created' + +=end rdoc + + module Browser + @@browser_classes = {} + @@sub_options = {} + @@default = nil + class << self + + # Create a new instance of a browser driver, as determined by the + # configuration settings. (Don't be fooled: this is not actually + # an instance of Browser class.) + def new + set_sub_options + klass.new + end + # Create a new instance as with #new and start the browser on the + # specified url. + def start url + set_sub_options + klass.start url + end + # Attach to an existing browser. + def attach(how, what) + set_sub_options + klass.attach(how, what) + end + def set_options options + return unless defined?(klass.set_options) + klass.set_options options + end + def options + return {} unless defined?(klass.options) + klass.options + end + + def klass + key = Watir.options[:browser] + eval @@browser_classes[key] # this triggers the autoload + end + private :klass + # Add support for the browser option, using the specified class, + # provided as a string. Optionally, additional options supported by + # the class can be specified as an array of symbols. Options specified + # by the user and included in this list will be passed (as a hash) to + # the set_options class method (if defined) before creating an instance. + def support hash_args + option = hash_args[:name] + class_string = hash_args[:class] + additional_options = hash_args[:options] + library = hash_args[:library] + gem = hash_args[:gem] || library + + @@browser_classes[option] = class_string + @@sub_options[option] = additional_options + + autoload class_string, library + activate_gem gem, option + end + + def default + @@default + end + # Specifies a default browser. Must be specified before options are parsed. + def default= option + @@default = option + end + # Returns the names of the browsers that are supported by this module. + # These are the options for 'watir_browser' (env var) or 'browser:' (yaml). + def browser_names + @@browser_classes.keys + end + + private + def autoload class_string, library + mod, klass = class_string.split('::') + eval "module ::#{mod}; autoload :#{klass}, '#{library}'; end" + end + # Activate the gem (if installed). The default browser will be set + # to the first gem that activates. + def activate_gem gem_name, option + begin + gem gem_name + @@default ||= option + rescue Gem::LoadError + end + end + def set_sub_options + sub_options = @@sub_options[Watir.options[:browser]] + return if sub_options.nil? + specified_options = Watir.options.reject {|k, v| !sub_options.include? k} + self.set_options specified_options + end + end + end + +end + +require 'watir/browsers' diff --git a/commonwatir/lib/watir/browsers.rb b/commonwatir/lib/watir/browsers.rb index f2d9a193..d5e03aee 100644 --- a/commonwatir/lib/watir/browsers.rb +++ b/commonwatir/lib/watir/browsers.rb @@ -1,12 +1,12 @@ -# watir/browsers -# Define browsers supported by Watir - -Watir::Browser.support :name => 'ie', :class => 'Watir::IE', - :library => 'watir/ie', :gem => 'watir', - :options => [:speed, :visible] - -Watir::Browser.support :name => 'firefox', :class => 'FireWatir::Firefox', - :library => 'firewatir' - -Watir::Browser.support :name => 'safari', :class => 'Watir::Safari', - :library => 'safariwatir' +# watir/browsers +# Define browsers supported by Watir + +Watir::Browser.support :name => 'ie', :class => 'Watir::IE', + :library => 'watir/ie', :gem => 'watir', + :options => [:speed, :visible] + +Watir::Browser.support :name => 'firefox', :class => 'FireWatir::Firefox', + :library => 'firewatir' + +Watir::Browser.support :name => 'safari', :class => 'Watir::Safari', + :library => 'safariwatir' diff --git a/commonwatir/lib/watir/matches.rb b/commonwatir/lib/watir/matches.rb index 7903743f..b839eb4f 100644 --- a/commonwatir/lib/watir/matches.rb +++ b/commonwatir/lib/watir/matches.rb @@ -1,17 +1,17 @@ -class String - def matches(x) - return self == x - end -end - -class Regexp - def matches(x) - return self.match(x) - end -end - -class Integer - def matches(x) - return self == x - end -end +class String + def matches(x) + return self == x + end +end + +class Regexp + def matches(x) + return self.match(x) + end +end + +class Integer + def matches(x) + return self == x + end +end diff --git a/commonwatir/lib/watir/options.rb b/commonwatir/lib/watir/options.rb index 113b09d8..d8b466f4 100644 --- a/commonwatir/lib/watir/options.rb +++ b/commonwatir/lib/watir/options.rb @@ -1,52 +1,52 @@ -# watir/options -require 'rubygems' - -require 'user-choices' - -module Watir - @@options_file = nil - @@options = nil - class << self - # Specify the location of a yaml file containing Watir options. Must be - # specified before the options are parsed. - def options_file= file - @@options_file = file - end - def options_file - @@options_file - end - def options= x - @@options = x - end - # Return the Watir options, as a hash. If they haven't been parsed yet, - # they will be now. - def options - @@options ||= Watir::Options.new.execute - end - end - - class Options < UserChoices::Command - include UserChoices - def add_sources builder - builder.add_source EnvironmentSource, :with_prefix, 'watir_' - if Watir.options_file - builder.add_source YamlConfigFileSource, :from_complete_path, - Watir.options_file - end - end - def add_choices builder - builder.add_choice :browser, - :type => Watir::Browser.browser_names, - :default => Watir::Browser.default - builder.add_choice :speed, - :type => ['slow', 'fast', 'zippy'], - :default => 'fast' - builder.add_choice :visible, - :type => :boolean - end - def execute - @user_choices[:speed] = @user_choices[:speed].to_sym - @user_choices - end - end -end +# watir/options +require 'rubygems' + +require 'user-choices' + +module Watir + @@options_file = nil + @@options = nil + class << self + # Specify the location of a yaml file containing Watir options. Must be + # specified before the options are parsed. + def options_file= file + @@options_file = file + end + def options_file + @@options_file + end + def options= x + @@options = x + end + # Return the Watir options, as a hash. If they haven't been parsed yet, + # they will be now. + def options + @@options ||= Watir::Options.new.execute + end + end + + class Options < UserChoices::Command + include UserChoices + def add_sources builder + builder.add_source EnvironmentSource, :with_prefix, 'watir_' + if Watir.options_file + builder.add_source YamlConfigFileSource, :from_complete_path, + Watir.options_file + end + end + def add_choices builder + builder.add_choice :browser, + :type => Watir::Browser.browser_names, + :default => Watir::Browser.default + builder.add_choice :speed, + :type => ['slow', 'fast', 'zippy'], + :default => 'fast' + builder.add_choice :visible, + :type => :boolean + end + def execute + @user_choices[:speed] = @user_choices[:speed].to_sym + @user_choices + end + end +end diff --git a/commonwatir/lib/watir/testcase.rb b/commonwatir/lib/watir/testcase.rb index e622bf1d..f1c0c389 100644 --- a/commonwatir/lib/watir/testcase.rb +++ b/commonwatir/lib/watir/testcase.rb @@ -1,58 +1,58 @@ -require 'test/unit' -require 'watir/assertions' - -module Watir - - class TestCase < Test::Unit::TestCase - include Watir::Assertions - @@order = :sequentially - def initialize name - throw :invalid_test if name == :default_test && self.class == Watir::TestCase - super - end - class << self - attr_accessor :test_methods, :order - def test_methods - @test_methods ||= [] - end - def order - @order || @@order - end - def default_order= order - @@order = order - end - def sorted_test_methods - case order - when :alphabetically then test_methods.sort - when :sequentially then test_methods - when :reversed_sequentially then test_methods.reverse - when :reversed_alphabetically then test_methods.sort.reverse - else raise ArgumentError, "Execute option not supported: #{@order}" - end - end - def suite - suite = Test::Unit::TestSuite.new(name) - sorted_test_methods.each do |test| - catch :invalid_test do - suite << new(test) - end - end - if (suite.empty?) - catch :invalid_test do - suite << new(:default_test) - end - end - return suite - end - def method_added id - name = id.id2name - test_methods << name if name =~ /^test./ - end - def execute order - @order = order - end - end - public :add_assertion - end - -end +require 'test/unit' +require 'watir/assertions' + +module Watir + + class TestCase < Test::Unit::TestCase + include Watir::Assertions + @@order = :sequentially + def initialize name + throw :invalid_test if name == :default_test && self.class == Watir::TestCase + super + end + class << self + attr_accessor :test_methods, :order + def test_methods + @test_methods ||= [] + end + def order + @order || @@order + end + def default_order= order + @@order = order + end + def sorted_test_methods + case order + when :alphabetically then test_methods.sort + when :sequentially then test_methods + when :reversed_sequentially then test_methods.reverse + when :reversed_alphabetically then test_methods.sort.reverse + else raise ArgumentError, "Execute option not supported: #{@order}" + end + end + def suite + suite = Test::Unit::TestSuite.new(name) + sorted_test_methods.each do |test| + catch :invalid_test do + suite << new(test) + end + end + if (suite.empty?) + catch :invalid_test do + suite << new(:default_test) + end + end + return suite + end + def method_added id + name = id.id2name + test_methods << name if name =~ /^test./ + end + def execute order + @order = order + end + end + public :add_assertion + end + +end diff --git a/commonwatir/lib/watir/waiter.rb b/commonwatir/lib/watir/waiter.rb index 9e2a48fb..99e26021 100644 --- a/commonwatir/lib/watir/waiter.rb +++ b/commonwatir/lib/watir/waiter.rb @@ -1,92 +1,92 @@ -require 'watir/exceptions' - -module Watir - - def wait_until(*args) - Waiter.wait_until(*args) {yield} - end - -class TimeKeeper - attr_reader :sleep_time - def initialize - @sleep_time = 0.0 - end - def sleep seconds - @sleep_time += Kernel.sleep seconds - end - def now - Time.now - end -end - -class Waiter - # This is an interface to a TimeKeeper which proxies - # calls to "sleep" and "Time.now". - # Useful for unit testing Waiter. - attr_accessor :timer - - # How long to wait between each iteration through the wait_until - # loop. In seconds. - attr_accessor :polling_interval - - # Timeout for wait_until. - attr_accessor :timeout - - @@default_polling_interval = 0.5 - @@default_timeout = 60.0 - - def initialize(timeout=@@default_timeout, - polling_interval=@@default_polling_interval) - @timeout = timeout - @polling_interval = polling_interval - @timer = TimeKeeper.new - end - - # Execute the provided block until either (1) it returns true, or - # (2) the timeout (in seconds) has been reached. If the timeout is reached, - # a TimeOutException will be raised. The block will always - # execute at least once. - # - # waiter = Waiter.new(5) - # waiter.wait_until {puts 'hello'} - # - # This code will print out "hello" for five seconds, and then raise a - # Watir::TimeOutException. - def wait_until # block - start_time = now - until yield do - if (duration = now - start_time) > @timeout - raise Watir::Exception::TimeOutException.new(duration, @timeout), - "Timed out after #{duration} seconds." - end - sleep @polling_interval - end - end - - # Execute the provided block until either (1) it returns true, or - # (2) the timeout (in seconds) has been reached. If the timeout is reached, - # a TimeOutException will be raised. The block will always - # execute at least once. - # - # Waiter.wait_until(5) {puts 'hello'} - # - # This code will print out "hello" for five seconds, and then raise a - # Watir::TimeOutException. - - # IDEA: wait_until: remove defaults from Waiter.wait_until - def self.wait_until(timeout=@@default_timeout, - polling_interval=@@default_polling_interval) - waiter = new(timeout, polling_interval) - waiter.wait_until { yield } - end - - private - def sleep seconds - @timer.sleep seconds - end - def now - @timer.now - end -end - +require 'watir/exceptions' + +module Watir + + def wait_until(*args) + Waiter.wait_until(*args) {yield} + end + +class TimeKeeper + attr_reader :sleep_time + def initialize + @sleep_time = 0.0 + end + def sleep seconds + @sleep_time += Kernel.sleep seconds + end + def now + Time.now + end +end + +class Waiter + # This is an interface to a TimeKeeper which proxies + # calls to "sleep" and "Time.now". + # Useful for unit testing Waiter. + attr_accessor :timer + + # How long to wait between each iteration through the wait_until + # loop. In seconds. + attr_accessor :polling_interval + + # Timeout for wait_until. + attr_accessor :timeout + + @@default_polling_interval = 0.5 + @@default_timeout = 60.0 + + def initialize(timeout=@@default_timeout, + polling_interval=@@default_polling_interval) + @timeout = timeout + @polling_interval = polling_interval + @timer = TimeKeeper.new + end + + # Execute the provided block until either (1) it returns true, or + # (2) the timeout (in seconds) has been reached. If the timeout is reached, + # a TimeOutException will be raised. The block will always + # execute at least once. + # + # waiter = Waiter.new(5) + # waiter.wait_until {puts 'hello'} + # + # This code will print out "hello" for five seconds, and then raise a + # Watir::TimeOutException. + def wait_until # block + start_time = now + until yield do + if (duration = now - start_time) > @timeout + raise Watir::Exception::TimeOutException.new(duration, @timeout), + "Timed out after #{duration} seconds." + end + sleep @polling_interval + end + end + + # Execute the provided block until either (1) it returns true, or + # (2) the timeout (in seconds) has been reached. If the timeout is reached, + # a TimeOutException will be raised. The block will always + # execute at least once. + # + # Waiter.wait_until(5) {puts 'hello'} + # + # This code will print out "hello" for five seconds, and then raise a + # Watir::TimeOutException. + + # IDEA: wait_until: remove defaults from Waiter.wait_until + def self.wait_until(timeout=@@default_timeout, + polling_interval=@@default_polling_interval) + waiter = new(timeout, polling_interval) + waiter.wait_until { yield } + end + + private + def sleep seconds + @timer.sleep seconds + end + def now + @timer.now + end +end + end # module \ No newline at end of file diff --git a/commonwatir/unittests/attach_to_existing_window_test.rb b/commonwatir/unittests/attach_to_existing_window_test.rb index 1abb1ef0..d4123354 100644 --- a/commonwatir/unittests/attach_to_existing_window_test.rb +++ b/commonwatir/unittests/attach_to_existing_window_test.rb @@ -1,71 +1,71 @@ -# feature tests for attaching to existing IE windows -# revision: $Revision: 1417 $ - -$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED -require 'unittests/setup' - -class TC_ExistingWindow < Test::Unit::TestCase - location __FILE__ - include Watir - - def setup - @original_timeout = Browser.options[:attach_timeout] - @browsers = [] - uses_page "pass.html" - end - - def teardown - Browser.set_options :attach_timeout => @original_timeout - @browsers.each {|x| x.close} - end - - def test_missing_window - Browser.set_options :attach_timeout => 0.1 - assert_raises(NoMatchingWindowFoundException) { Browser.attach(:title, "missing") } - assert_raises(NoMatchingWindowFoundException) { Browser.attach(:title, /missing/) } - assert_raises(NoMatchingWindowFoundException) { Browser.attach(:url, "missing") } - assert_raises(NoMatchingWindowFoundException) { Browser.attach(:url, /missing/) } - end - - # Open a few browsers so that the test has a few windows to choose - # from. The test harness has already opened a window that we won't - # use. - def open_several_windows - ["buttons1.html", "whitespace.html"].each do |file| - @browsers << Browser.start(self.class.html_root + file) - end - end - - def test_existing_window - open_several_windows - - b1 = Browser.attach(:title , /buttons/i) - assert_equal("Test page for buttons", b1.title) - - b2 = Browser.attach(:title , "Test page for buttons") - assert_equal("Test page for buttons", b2.title) - - b3 = Browser.attach(:url, /buttons1.html/) - assert_equal("Test page for buttons", b3.title) - end - - def test_title_and_url_are_correct_after_reload - uses_page "whitespace.html" - assert_equal 'Test page for whitespace', browser.title - assert_match /whitespace.html/, browser.url - browser.link(:text, 'Login').click - assert_equal 'Pass Page', browser.title - assert_match /pass.html/, browser.url - end - - tag_method :test_working_back_and_forth, :fails_on_firefox - def test_working_back_and_forth - open_several_windows - buttons = Browser.attach(:url, /buttons1.html/) - whitespace = Browser.attach(:url, /whitespace.html/) - assert_match /This button is a submit/, buttons.text - whitespace.link(:text, 'Login').click - assert_match /pass/i, whitespace.text - end -end - +# feature tests for attaching to existing IE windows +# revision: $Revision: 1417 $ + +$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED +require 'unittests/setup' + +class TC_ExistingWindow < Test::Unit::TestCase + location __FILE__ + include Watir + + def setup + @original_timeout = Browser.options[:attach_timeout] + @browsers = [] + uses_page "pass.html" + end + + def teardown + Browser.set_options :attach_timeout => @original_timeout + @browsers.each {|x| x.close} + end + + def test_missing_window + Browser.set_options :attach_timeout => 0.1 + assert_raises(NoMatchingWindowFoundException) { Browser.attach(:title, "missing") } + assert_raises(NoMatchingWindowFoundException) { Browser.attach(:title, /missing/) } + assert_raises(NoMatchingWindowFoundException) { Browser.attach(:url, "missing") } + assert_raises(NoMatchingWindowFoundException) { Browser.attach(:url, /missing/) } + end + + # Open a few browsers so that the test has a few windows to choose + # from. The test harness has already opened a window that we won't + # use. + def open_several_windows + ["buttons1.html", "whitespace.html"].each do |file| + @browsers << Browser.start(self.class.html_root + file) + end + end + + def test_existing_window + open_several_windows + + b1 = Browser.attach(:title , /buttons/i) + assert_equal("Test page for buttons", b1.title) + + b2 = Browser.attach(:title , "Test page for buttons") + assert_equal("Test page for buttons", b2.title) + + b3 = Browser.attach(:url, /buttons1.html/) + assert_equal("Test page for buttons", b3.title) + end + + def test_title_and_url_are_correct_after_reload + uses_page "whitespace.html" + assert_equal 'Test page for whitespace', browser.title + assert_match /whitespace.html/, browser.url + browser.link(:text, 'Login').click + assert_equal 'Pass Page', browser.title + assert_match /pass.html/, browser.url + end + + tag_method :test_working_back_and_forth, :fails_on_firefox + def test_working_back_and_forth + open_several_windows + buttons = Browser.attach(:url, /buttons1.html/) + whitespace = Browser.attach(:url, /whitespace.html/) + assert_match /This button is a submit/, buttons.text + whitespace.link(:text, 'Login').click + assert_match /pass/i, whitespace.text + end +end + diff --git a/commonwatir/unittests/form2_test.rb b/commonwatir/unittests/form2_test.rb index 65b38717..e974cb26 100644 --- a/commonwatir/unittests/form2_test.rb +++ b/commonwatir/unittests/form2_test.rb @@ -1,22 +1,22 @@ -$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED -require 'unittests/setup' - -class TC_Form_Entertainment < Test::Unit::TestCase - location __FILE__ - def setup - uses_page "entertainment_com.html" - end - def test_bare_button - assert_nothing_raised do - browser.button(:src, Regexp.new('/images/button_continue.gif')).click - end - end - - # http://jira.openqa.org/browse/WTR-80 - tag_method :test_button_in_form, :fails_on_ie - def test_button_in_form - assert_nothing_raised do - browser.form(:name, 'shipaddress').button(:src, Regexp.new('/images/button_continue.gif')).click - end - end +$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED +require 'unittests/setup' + +class TC_Form_Entertainment < Test::Unit::TestCase + location __FILE__ + def setup + uses_page "entertainment_com.html" + end + def test_bare_button + assert_nothing_raised do + browser.button(:src, Regexp.new('/images/button_continue.gif')).click + end + end + + # http://jira.openqa.org/browse/WTR-80 + tag_method :test_button_in_form, :fails_on_ie + def test_button_in_form + assert_nothing_raised do + browser.form(:name, 'shipaddress').button(:src, Regexp.new('/images/button_continue.gif')).click + end + end end \ No newline at end of file diff --git a/commonwatir/unittests/html/buttons2.html b/commonwatir/unittests/html/buttons2.html index aab37cf9..a74ff434 100644 --- a/commonwatir/unittests/html/buttons2.html +++ b/commonwatir/unittests/html/buttons2.html @@ -1,61 +1,61 @@ - - - -Test page for buttons - - - - -CVS Revision: $Revision: 1.0 $ -
-
- - - - - - - - - - - - - - - - - - - -
-
- - -
- -
-
The top button is for testing buttons with names -
The second button is used for testing disabled buttons -
-
-
-
-
This button is a submit ( the others are buttons) -
-
-
-
-
This button is an image. It should behave the same as a submit - -
-
- - -
- -
The top button is for testing buttons with names -
The second button is used for testing disabled buttons -
- - + + + +Test page for buttons + + + + +CVS Revision: $Revision: 1.0 $ +
+
+ + + + + + + + + + + + + + + + + + + +
+
+ + +
+ +
+
The top button is for testing buttons with names +
The second button is used for testing disabled buttons +
+
+
+
+
This button is a submit ( the others are buttons) +
+
+
+
+
This button is an image. It should behave the same as a submit + +
+
+ + +
+ +
The top button is for testing buttons with names +
The second button is used for testing disabled buttons +
+ + diff --git a/commonwatir/unittests/html/entertainment_com.html b/commonwatir/unittests/html/entertainment_com.html index 97e52f09..914947bd 100644 --- a/commonwatir/unittests/html/entertainment_com.html +++ b/commonwatir/unittests/html/entertainment_com.html @@ -1,11 +1,11 @@ - - - - -Entertainment.com - - - + + + + +Entertainment.com + + + @@ -17,50 +17,50 @@ - + - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
- - + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + @@ -75,561 +75,561 @@ - - -
- - - - - - - - - - - - - - - - - - + +
- - - - - - - - - - - - - -
Billing Information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*First Name:
*Last Name: 
*Phone: 
*Street Address 1: 
Street Address 2: 
*City: 
*State/Province: 
*Country:  - -
*Zip/Postal Code: 
*E-mail Address: 
*Confirm E-mail Address: 
   
 
- - - - - - -
Where do you want to
- ship your order?
  - - - - - - - - - - -
 Billing Address
 Different Address
-
-
- -
   
*Required Field. Customer order information is processed on a secure server.
- See Privacy Policy.
-
- -
-
+ + +
+ + + + + + + + + + + + + + + + + + - -
+ + + + + + + + + + + + + +
Billing Information
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
*First Name:
*Last Name: 
*Phone: 
*Street Address 1: 
Street Address 2: 
*City: 
*State/Province: 
*Country:  + +
*Zip/Postal Code: 
*E-mail Address: 
*Confirm E-mail Address: 
   
 
+ + + + + + +
Where do you want to
+ ship your order?
  + + + + + + + + + + +
 Billing Address
 Different Address
+
+
+ +
   
*Required Field. Customer order information is processed on a secure server.
+ See Privacy Policy.
+
+ +
+
@@ -643,20 +643,20 @@
- -
+ +
- - - - -
+ + + + +
diff --git a/commonwatir/unittests/html/pass.html b/commonwatir/unittests/html/pass.html index 2d5bb5d3..b2bf206f 100644 --- a/commonwatir/unittests/html/pass.html +++ b/commonwatir/unittests/html/pass.html @@ -1,10 +1,10 @@ - - - -Pass Page - - - -PASS - + + + +Pass Page + + + +PASS + \ No newline at end of file diff --git a/commonwatir/unittests/html/visibility.html b/commonwatir/unittests/html/visibility.html index 446012ba..7e1d4773 100644 --- a/commonwatir/unittests/html/visibility.html +++ b/commonwatir/unittests/html/visibility.html @@ -1,90 +1,90 @@ - -Visibility test - Using CSS with and without inline style - - - - - - -
    -
  1. DIV 1: - -
  2. DIV 2: - -
  3. DIV 3: - -
- -
- - - -
- -
- - - -
- -
- - - -
- - - - - + +Visibility test - Using CSS with and without inline style + + + + + + +
    +
  1. DIV 1: + +
  2. DIV 2: + +
  3. DIV 3: + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ + + + + diff --git a/commonwatir/unittests/html/whitespace.html b/commonwatir/unittests/html/whitespace.html index 19ddcc6a..5da065b8 100644 --- a/commonwatir/unittests/html/whitespace.html +++ b/commonwatir/unittests/html/whitespace.html @@ -1,29 +1,29 @@ - - - -Test page for whitespace - - - - - - Login  -

- - Test for nbsp. - -

- - Test for multiple spaces. - -

- - Test for space and tab. - -

- - Test for space and - cr. - - + + + +Test page for whitespace + + + + + + Login  +

+ + Test for nbsp. + +

+ + Test for multiple spaces. + +

+ + Test for space and tab. + +

+ + Test for space and + cr. + + \ No newline at end of file diff --git a/commonwatir/unittests/options.yml.example b/commonwatir/unittests/options.yml.example index 18f4a859..5081dbb4 100644 --- a/commonwatir/unittests/options.yml.example +++ b/commonwatir/unittests/options.yml.example @@ -1,13 +1,13 @@ -# This file specifies options affecting the unit tests. -# You need to copy this file to "options.yml" before it to work. - -# These options can also be set using environment variables prefixed with 'watir_'. -# These environment variables will override settings from this file. - -# 'ie' (Watir::IE) or 'firefox' (FireWatir::Firefox) -browser: ie - -# These options only affect IE. -# speed options are fast, slow, and zippy -speed: fast +# This file specifies options affecting the unit tests. +# You need to copy this file to "options.yml" before it to work. + +# These options can also be set using environment variables prefixed with 'watir_'. +# These environment variables will override settings from this file. + +# 'ie' (Watir::IE) or 'firefox' (FireWatir::Firefox) +browser: ie + +# These options only affect IE. +# speed options are fast, slow, and zippy +speed: fast visible: true \ No newline at end of file diff --git a/commonwatir/unittests/setup/browser.rb b/commonwatir/unittests/setup/browser.rb index 3f5cf2ce..286597da 100644 --- a/commonwatir/unittests/setup/browser.rb +++ b/commonwatir/unittests/setup/browser.rb @@ -1,14 +1,14 @@ -# setup/browser -require 'watir/browser' -case Watir.options[:browser] -when 'ie' - $LOAD_PATH.unshift File.expand_path($watir_dev_lib) -when 'firefox' - $LOAD_PATH.unshift File.expand_path($firewatir_dev_lib) -end -$browser = Watir::Browser.new - -# close browser at completion of the tests -# the at_exit execute before loading test/unit, otherwise IE will close *before* the tests run. -at_exit {$browser.close if $browser} - +# setup/browser +require 'watir/browser' +case Watir.options[:browser] +when 'ie' + $LOAD_PATH.unshift File.expand_path($watir_dev_lib) +when 'firefox' + $LOAD_PATH.unshift File.expand_path($firewatir_dev_lib) +end +$browser = Watir::Browser.new + +# close browser at completion of the tests +# the at_exit execute before loading test/unit, otherwise IE will close *before* the tests run. +at_exit {$browser.close if $browser} + diff --git a/commonwatir/unittests/setup/filter.rb b/commonwatir/unittests/setup/filter.rb index 59109dcb..148f117c 100644 --- a/commonwatir/unittests/setup/filter.rb +++ b/commonwatir/unittests/setup/filter.rb @@ -1,23 +1,23 @@ -require 'test/unit' -require 'test/unit/collector/objectspace' - -# Modify the Test::Unit runner in Eclipse, so it only runs our tests -module Test::Unit - module RDT - def self.buildSuite filename - collector = Test::Unit::Collector::ObjectSpace.new - collector.filter = Watir::UnitTest.filter - collector.collect filename - end - end -end - -# Invoke default test runner so it only runs our tests -at_exit do - unless $! || Test::Unit.run? - runner = Test::Unit::AutoRunner.new false - runner.process_args ARGV - runner.filters = Watir::UnitTest.filter - exit runner.run - end -end +require 'test/unit' +require 'test/unit/collector/objectspace' + +# Modify the Test::Unit runner in Eclipse, so it only runs our tests +module Test::Unit + module RDT + def self.buildSuite filename + collector = Test::Unit::Collector::ObjectSpace.new + collector.filter = Watir::UnitTest.filter + collector.collect filename + end + end +end + +# Invoke default test runner so it only runs our tests +at_exit do + unless $! || Test::Unit.run? + runner = Test::Unit::AutoRunner.new false + runner.process_args ARGV + runner.filters = Watir::UnitTest.filter + exit runner.run + end +end diff --git a/commonwatir/unittests/setup/lib.rb b/commonwatir/unittests/setup/lib.rb index ea9ca22e..952242c2 100644 --- a/commonwatir/unittests/setup/lib.rb +++ b/commonwatir/unittests/setup/lib.rb @@ -1,21 +1,21 @@ -$myDir.sub!( %r{/cygdrive/(\w)/}, '\1:/' ) # convert from cygwin to dos - -require 'watir/options' -Watir.options_file = $suite_options_file = $myDir + '/options.yml' -require 'unittests/setup/options' -unit_options = Watir::UnitTest::Options.new.execute -require 'unittests/setup/browser' -require 'unittests/setup/filter' -require 'unittests/setup/watir-unittest' - -failure_tag = "fails_on_#{Watir.options[:browser]}".to_sym -case unit_options[:coverage] - when 'regression' - Watir::UnitTest.filter_out_tests_tagged failure_tag - when 'known failures' - Watir::UnitTest.filter_out do |test| - !(test.tagged? failure_tag) - end -end - - +$myDir.sub!( %r{/cygdrive/(\w)/}, '\1:/' ) # convert from cygwin to dos + +require 'watir/options' +Watir.options_file = $suite_options_file = $myDir + '/options.yml' +require 'unittests/setup/options' +unit_options = Watir::UnitTest::Options.new.execute +require 'unittests/setup/browser' +require 'unittests/setup/filter' +require 'unittests/setup/watir-unittest' + +failure_tag = "fails_on_#{Watir.options[:browser]}".to_sym +case unit_options[:coverage] + when 'regression' + Watir::UnitTest.filter_out_tests_tagged failure_tag + when 'known failures' + Watir::UnitTest.filter_out do |test| + !(test.tagged? failure_tag) + end +end + + diff --git a/commonwatir/unittests/setup/options.rb b/commonwatir/unittests/setup/options.rb index ce57367b..9fa3a695 100644 --- a/commonwatir/unittests/setup/options.rb +++ b/commonwatir/unittests/setup/options.rb @@ -1,29 +1,29 @@ -# setup/options -require 'user-choices' - -module Watir - module UnitTest - class Options < UserChoices::Command - include UserChoices - def add_sources builder - builder.add_source EnvironmentSource, :with_prefix, 'watir_' - builder.add_source YamlConfigFileSource, :from_complete_path, - $suite_options_file - end - def add_choices builder - builder.add_choice :coverage, - :type => ['regression', 'all', 'known failures'], - :default => 'regression' - end - def execute - Watir::UnitTest.options = @user_choices - end - end - def self.options - @@options - end - def self.options= x - @@options = x - end - end -end +# setup/options +require 'user-choices' + +module Watir + module UnitTest + class Options < UserChoices::Command + include UserChoices + def add_sources builder + builder.add_source EnvironmentSource, :with_prefix, 'watir_' + builder.add_source YamlConfigFileSource, :from_complete_path, + $suite_options_file + end + def add_choices builder + builder.add_choice :coverage, + :type => ['regression', 'all', 'known failures'], + :default => 'regression' + end + def execute + Watir::UnitTest.options = @user_choices + end + end + def self.options + @@options + end + def self.options= x + @@options = x + end + end +end diff --git a/commonwatir/unittests/setup/testUnitAddons.rb b/commonwatir/unittests/setup/testUnitAddons.rb index 40a25e45..68c3ca56 100644 --- a/commonwatir/unittests/setup/testUnitAddons.rb +++ b/commonwatir/unittests/setup/testUnitAddons.rb @@ -1,8 +1,8 @@ -module Test::Unit::Assertions - def assert_false(boolean, message=nil) - _wrap_assertion do - assert_block("assert should not be called with a block.") { !block_given? } - assert_block(build_message(message, " is not false.", boolean)) { !boolean } - end - end -end # module test +module Test::Unit::Assertions + def assert_false(boolean, message=nil) + _wrap_assertion do + assert_block("assert should not be called with a block.") { !block_given? } + assert_block(build_message(message, " is not false.", boolean)) { !boolean } + end + end +end # module test diff --git a/commonwatir/unittests/setup/watir-unittest.rb b/commonwatir/unittests/setup/watir-unittest.rb index ade495b2..5a165c1e 100644 --- a/commonwatir/unittests/setup/watir-unittest.rb +++ b/commonwatir/unittests/setup/watir-unittest.rb @@ -1,74 +1,74 @@ -$htmlRoot = "file:///#{$myDir}/html/" - -module Watir::UnitTest - # navigate the browser to the specified page in unittests/html - def goto_page page - new_url = self.class.html_root + page - browser.goto new_url - end - # navigate the browser to the specified page in unittests/html IF the browser is not already on that page. - def uses_page page # only works with IE - new_url = self.class.html_root + page - browser.goto new_url unless browser.url == new_url - end - def browser - $browser - end - - def assert_class element, klass - assert_match(Regexp.new(klass, Regexp::IGNORECASE), element.class.to_s, "element class should be #{klass}; got #{element.class}") - end - - @@filter = [] - class << self - def filter - @@filter - end - def filter= proc - @@filter = proc - end - # Add a filter that excludes tests matching the provided block - def filter_out &block - @@filter << Proc.new do |test| - block.call(test) ? false : nil - end - end - def filter_out_tests_tagged tag - filter_out do |test| - test.tagged? tag - end - end - end -end - -class Test::Unit::TestCase - include Watir::UnitTest - include Watir::Exception - - class << self - def tags *names - @tags ||= [] - @tags += names - end - def tag_method method_name, *tags - self.method_tags[method_name.to_s] = tags - end - def method_tags - @method_tags ||= Hash.new [] - end - def html_root - return "file:///#{File.expand_path @html_dir}/" if @html_dir - $htmlRoot - end - def location path - @html_dir = File.join File.dirname(path), 'html' - end - end - - def tagged? tag - self.class.tags.include?(tag) || - self.class.method_tags[@method_name].include?(tag) - end - -end - +$htmlRoot = "file:///#{$myDir}/html/" + +module Watir::UnitTest + # navigate the browser to the specified page in unittests/html + def goto_page page + new_url = self.class.html_root + page + browser.goto new_url + end + # navigate the browser to the specified page in unittests/html IF the browser is not already on that page. + def uses_page page # only works with IE + new_url = self.class.html_root + page + browser.goto new_url unless browser.url == new_url + end + def browser + $browser + end + + def assert_class element, klass + assert_match(Regexp.new(klass, Regexp::IGNORECASE), element.class.to_s, "element class should be #{klass}; got #{element.class}") + end + + @@filter = [] + class << self + def filter + @@filter + end + def filter= proc + @@filter = proc + end + # Add a filter that excludes tests matching the provided block + def filter_out &block + @@filter << Proc.new do |test| + block.call(test) ? false : nil + end + end + def filter_out_tests_tagged tag + filter_out do |test| + test.tagged? tag + end + end + end +end + +class Test::Unit::TestCase + include Watir::UnitTest + include Watir::Exception + + class << self + def tags *names + @tags ||= [] + @tags += names + end + def tag_method method_name, *tags + self.method_tags[method_name.to_s] = tags + end + def method_tags + @method_tags ||= Hash.new [] + end + def html_root + return "file:///#{File.expand_path @html_dir}/" if @html_dir + $htmlRoot + end + def location path + @html_dir = File.join File.dirname(path), 'html' + end + end + + def tagged? tag + self.class.tags.include?(tag) || + self.class.method_tags[@method_name].include?(tag) + end + +end + diff --git a/commonwatir/unittests/visibility_test.rb b/commonwatir/unittests/visibility_test.rb index 13aab1bd..68c54cb8 100644 --- a/commonwatir/unittests/visibility_test.rb +++ b/commonwatir/unittests/visibility_test.rb @@ -1,47 +1,47 @@ -# feature tests for Visibility - -$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED -require 'unittests/setup' - -class TC_Visibility < Test::Unit::TestCase - location __FILE__ - - def setup - uses_page "visibility.html" - end - - # will check for divs which are visible on the screen (not inline style) - def test_initial_divs - assert_equal(true, browser.div(:id, "div1").visible?) - assert_equal(false, browser.div(:id, "div2").visible?) - assert_equal(false, browser.div(:id, "div3").visible?) - end - - # will check for textfields which are visible on the screen (not inline style) - # if any textfields style displays true, it checks if all the parents are true else displays false - def test_initial_text_fields - assert_equal(true, browser.text_field(:id, "lgnId1").visible?) - assert_equal(false, browser.text_field(:id, "lgnId2").visible?) - assert_equal(false, browser.text_field(:id, "lgnId3").visible?) - end - - # Check if the second div becomes visible (inline visibility test) - def test_make_visible_second_div - browser.link(:id, "div2vis").click - #wait_until { browser.div(:id, "div2").visible? } - assert_equal(true, browser.div(:id, "div2").visible? ) - assert_equal(true, browser.text_field(:id, "lgnId2").visible? ) - end - - # Check if the second div becomes visible (inline Display block test) - def test_make_display_third_div - browser.link(:id, "div3blk").click - #wait_until { browser.div(:id, "div3").visible? } - assert_equal(true, browser.div(:id, "div3").visible? ) - assert_equal(true, browser.text_field(:id, "lgnId3").visible? ) - end - - def test_hidden_element - assert_equal(false, browser.hidden(:id, 'hidden-type').visible? ) - end -end +# feature tests for Visibility + +$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED +require 'unittests/setup' + +class TC_Visibility < Test::Unit::TestCase + location __FILE__ + + def setup + uses_page "visibility.html" + end + + # will check for divs which are visible on the screen (not inline style) + def test_initial_divs + assert_equal(true, browser.div(:id, "div1").visible?) + assert_equal(false, browser.div(:id, "div2").visible?) + assert_equal(false, browser.div(:id, "div3").visible?) + end + + # will check for textfields which are visible on the screen (not inline style) + # if any textfields style displays true, it checks if all the parents are true else displays false + def test_initial_text_fields + assert_equal(true, browser.text_field(:id, "lgnId1").visible?) + assert_equal(false, browser.text_field(:id, "lgnId2").visible?) + assert_equal(false, browser.text_field(:id, "lgnId3").visible?) + end + + # Check if the second div becomes visible (inline visibility test) + def test_make_visible_second_div + browser.link(:id, "div2vis").click + #wait_until { browser.div(:id, "div2").visible? } + assert_equal(true, browser.div(:id, "div2").visible? ) + assert_equal(true, browser.text_field(:id, "lgnId2").visible? ) + end + + # Check if the second div becomes visible (inline Display block test) + def test_make_display_third_div + browser.link(:id, "div3blk").click + #wait_until { browser.div(:id, "div3").visible? } + assert_equal(true, browser.div(:id, "div3").visible? ) + assert_equal(true, browser.text_field(:id, "lgnId3").visible? ) + end + + def test_hidden_element + assert_equal(false, browser.hidden(:id, 'hidden-type').visible? ) + end +end diff --git a/commonwatir/unittests/whitespace_test.rb b/commonwatir/unittests/whitespace_test.rb index ef98a2cc..75688230 100644 --- a/commonwatir/unittests/whitespace_test.rb +++ b/commonwatir/unittests/whitespace_test.rb @@ -1,40 +1,40 @@ -# feature tests for white space - -$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED -require 'unittests/setup' - -class TC_WhiteSpace < Test::Unit::TestCase - location __FILE__ - - def setup - uses_page "whitespace.html" - end - - def test_text_with_nbsp - assert_equal 'Login', browser.link(:index => 1).text - end - - def test_nbsp_beginning_and_end - assert browser.link(:text, 'Login').exists? - end - - def test_single_nbsp - assert_equal "Test for nbsp.", browser.span(:id, 'single_nbsp').text - end - - def test_multiple_spaces - assert_equal "Test for multiple spaces.", browser.span(:id, 'multiple_spaces').text - end - - def test_multiple_spaces_access - assert_equal 'multiple_spaces', browser.span(:text, "Test for multiple spaces.").id - end - - def test_space_tab - assert_equal "Test for space and tab.", browser.span(:id, 'space_tab').text - end - - def test_space_w_cr - assert_equal "Test for space and cr.", browser.span(:id, 'space_w_cr').text - end -end +# feature tests for white space + +$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED +require 'unittests/setup' + +class TC_WhiteSpace < Test::Unit::TestCase + location __FILE__ + + def setup + uses_page "whitespace.html" + end + + def test_text_with_nbsp + assert_equal 'Login', browser.link(:index => 1).text + end + + def test_nbsp_beginning_and_end + assert browser.link(:text, 'Login').exists? + end + + def test_single_nbsp + assert_equal "Test for nbsp.", browser.span(:id, 'single_nbsp').text + end + + def test_multiple_spaces + assert_equal "Test for multiple spaces.", browser.span(:id, 'multiple_spaces').text + end + + def test_multiple_spaces_access + assert_equal 'multiple_spaces', browser.span(:text, "Test for multiple spaces.").id + end + + def test_space_tab + assert_equal "Test for space and tab.", browser.span(:id, 'space_tab').text + end + + def test_space_w_cr + assert_equal "Test for space and cr.", browser.span(:id, 'space_w_cr').text + end +end diff --git a/doc/.loadpath b/doc/.loadpath index c4415b3d..9a622201 100644 --- a/doc/.loadpath +++ b/doc/.loadpath @@ -1,5 +1,5 @@ - - - - - + + + + + diff --git a/doc/.project b/doc/.project index 324a44b9..8a7d3beb 100644 --- a/doc/.project +++ b/doc/.project @@ -1,17 +1,17 @@ - - - watir-doc - - - - - - org.rubypeople.rdt.core.rubybuilder - - - - - - org.rubypeople.rdt.core.rubynature - - + + + watir-doc + + + + + + org.rubypeople.rdt.core.rubybuilder + + + + + + org.rubypeople.rdt.core.rubynature + + diff --git a/doc/README b/doc/README index dfc37c16..3f94715d 100644 --- a/doc/README +++ b/doc/README @@ -1,3 +1,3 @@ -This directory contains the pages used on wtr.rubyforge.org. - -It was build with webgen 0.4.7. +This directory contains the pages used on wtr.rubyforge.org. + +It was build with webgen 0.4.7. diff --git a/doc/src/browserfix.css b/doc/src/browserfix.css index 374470fa..b8e9bc39 100644 --- a/doc/src/browserfix.css +++ b/doc/src/browserfix.css @@ -1,7 +1,7 @@ -/**************** IE fixes ****************/ - -html -{overflow:hidden;} - -body +/**************** IE fixes ****************/ + +html +{overflow:hidden;} + +body {height:100%; width:100%; overflow:auto;} \ No newline at end of file