commonwatir 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ === 0.0.1 / 2008-08-28
2
+
3
+ * Created
4
+
5
+
@@ -0,0 +1,14 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/watir.rb
6
+ lib/watir-common.rb
7
+ lib/watir/assertions.rb
8
+ lib/watir/browser.rb
9
+ lib/watir/browsers.rb
10
+ lib/watir/exceptions.rb
11
+ lib/watir/matches.rb
12
+ lib/watir/options.rb
13
+ lib/watir/testcase.rb
14
+ lib/watir/waiter.rb
@@ -0,0 +1,48 @@
1
+ = watir-common
2
+
3
+ * FIX (url)
4
+
5
+ == DESCRIPTION:
6
+
7
+ Common code used by Watir and FireWatir
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * sudo gem install watir-common
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 Bret Pettichord
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ require './lib/watir-common.rb'
4
+
5
+ Hoe.new('commonwatir', WatirCommon::VERSION) do |p|
6
+ p.rubyforge_name = 'wtr'
7
+ p.developer('Bret Pettichord', 'bret@watircraft.com')
8
+ p.extra_deps << 'user-choices'
9
+ end
@@ -0,0 +1,3 @@
1
+ class WatirCommon
2
+ VERSION = '1.6.2'
3
+ end
@@ -0,0 +1,6 @@
1
+ # The 'watir' library loads the common watir code, common to all watir
2
+ # implementations. The 'watir/browser' library will autoload the actual
3
+ # implementations.
4
+
5
+ require 'watir/waiter'
6
+ require 'watir/browser'
@@ -0,0 +1,44 @@
1
+ require 'test/unit/assertions'
2
+
3
+ module Watir
4
+ # Verification methods
5
+ module Assertions
6
+ include Test::Unit::Assertions
7
+
8
+ # Log a failure if the boolean is true. The message is the failure
9
+ # message logged.
10
+ # Whether true or false, the assertion count is incremented.
11
+ def verify boolean, message = 'verify failed.'
12
+ add_assertion
13
+ add_failure message.to_s, caller unless boolean
14
+ end
15
+
16
+ def verify_equal expected, actual, message=nil
17
+ full_message = build_message(message, <<EOT, expected, actual)
18
+ <?> expected but was
19
+ <?>.
20
+ EOT
21
+ verify(expected == actual, full_message)
22
+ end
23
+ def verify_match pattern, string, message=nil
24
+ pattern = case(pattern)
25
+ when String
26
+ Regexp.new(Regexp.escape(pattern))
27
+ else
28
+ pattern
29
+ end
30
+ full_message = build_message(message, "<?> expected to be =~\n<?>.", string, pattern)
31
+ verify(string =~ pattern, full_message)
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ module Test::Unit::Assertions
38
+ def assert_false(boolean, message=nil)
39
+ _wrap_assertion do
40
+ assert_block("assert should not be called with a block.") { !block_given? }
41
+ assert_block(build_message(message, "<?> is not false.", boolean)) { !boolean }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,130 @@
1
+ # watir/browser
2
+ require 'watir/options'
3
+ module Watir
4
+
5
+ =begin rdoc
6
+
7
+ Watir is a family of open-source drivers for automating web browsers. You
8
+ can use it to write tests that are easy to read and maintain.
9
+
10
+ Watir drives browsers the same way people do. It clicks links, fills in forms,
11
+ presses buttons. Watir also checks results, such as whether expected text
12
+ appears on a page.
13
+
14
+ The Watir family currently includes support for Internet Explorer (on Windows),
15
+ Firefox (on Windows, Mac and Linux) and Safari (on Mac).
16
+
17
+ Project Homepage: http://wtr.rubyforge.org
18
+
19
+ This Browser module provides a generic interface
20
+ that tests can use to access any browser. The actual browser (and thus
21
+ the actual Watir driver) is determined at runtime based on configuration
22
+ settings.
23
+
24
+ require 'watir'
25
+ browser = Watir::Browser.new
26
+ browser.goto 'http://google.com'
27
+ browser.text_field(:name, 'q').set 'pickaxe'
28
+ browser.button(:name, 'btnG').click
29
+ if browser.text.include? 'Programming Ruby'
30
+ puts 'Text was found'
31
+ else
32
+ puts 'Text was not found'
33
+ end
34
+
35
+ A comprehensive summary of the Watir API can be found here
36
+ http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
37
+
38
+ There are two ways to configure the browser that will be used by your tests.
39
+
40
+ One is to set the +watir_browser+ environment variable to +ie+ or +firefox+.
41
+ (How you do this depends on your platform.)
42
+
43
+ The other is to create a file that looks like this.
44
+
45
+ browser: ie
46
+
47
+ And then to add this line to your script, after the require statement and
48
+ before you invoke Browser.new.
49
+
50
+ Watir.options_file = 'path/to/the/file/you/just/created'
51
+
52
+ =end rdoc
53
+
54
+ module Browser
55
+ @@browser_classes = {}
56
+ @@sub_options = {}
57
+ @@default = nil
58
+ class << self
59
+
60
+ # Create a new instance of a browser driver, as determined by the
61
+ # configuration settings. (Don't be fooled: this is not actually
62
+ # an instance of Browser class.)
63
+ def new
64
+ set_sub_options
65
+ klass.new
66
+ end
67
+ # Create a new instance as with #new and start the browser on the
68
+ # specified url.
69
+ def start url
70
+ set_sub_options
71
+ klass.start url
72
+ end
73
+ def klass
74
+ key = Watir.options[:browser]
75
+ eval @@browser_classes[key] # this triggers the autoload
76
+ end
77
+ private :klass
78
+ # Add support for the browser option, using the specified class,
79
+ # provided as a string. Optionally, additional options supported by
80
+ # the class can be specified as an array of symbols. Options specified
81
+ # by the user and included in this list will be passed (as a hash) to
82
+ # the set_options class method (if defined) before creating an instance.
83
+ def support hash_args
84
+ option = hash_args[:name]
85
+ class_string = hash_args[:class]
86
+ additional_options = hash_args[:options]
87
+ library = hash_args[:library]
88
+ gem = hash_args[:gem] || library
89
+
90
+ @@browser_classes[option] = class_string
91
+ @@sub_options[option] = additional_options
92
+
93
+ autoload class_string, library
94
+ activate_gem gem, option
95
+ end
96
+ def autoload class_string, library
97
+ mod, klass = class_string.split('::')
98
+ eval "module ::#{mod}; autoload :#{klass}, '#{library}'; end"
99
+ end
100
+ # Activate the gem (if installed). The default browser will be set
101
+ # to the first gem that activates.
102
+ def activate_gem gem_name, option
103
+ begin
104
+ gem gem_name
105
+ @@default ||= option
106
+ rescue Gem::LoadError
107
+ end
108
+ end
109
+ def default
110
+ @@default
111
+ end
112
+ # Specifies a default browser. Must be specified before options are parsed.
113
+ def default= option
114
+ @@default = option
115
+ end
116
+ def options
117
+ @@browser_classes.keys
118
+ end
119
+ def set_sub_options
120
+ return unless defined?(klass.set_options)
121
+ sub_options = @@sub_options[Watir.options[:browser]]
122
+ specified_options = Watir.options.reject {|k, v| !sub_options.include? k}
123
+ klass.set_options specified_options
124
+ end
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ require 'watir/browsers'
@@ -0,0 +1,12 @@
1
+ # watir/browsers
2
+ # Define browsers supported by Watir
3
+
4
+ Watir::Browser.support :name => 'ie', :class => 'Watir::IE',
5
+ :library => 'watir/ie', :gem => 'watir',
6
+ :options => [:speed, :visible]
7
+
8
+ Watir::Browser.support :name => 'firefox', :class => 'FireWatir::Firefox',
9
+ :library => 'firewatir'
10
+
11
+ Watir::Browser.support :name => 'safari', :class => 'Watir::Safari',
12
+ :library => 'safariwatir'
@@ -0,0 +1,48 @@
1
+ module Watir
2
+ module Exception
3
+
4
+ # Root class for all Watir Exceptions
5
+ class WatirException < RuntimeError
6
+ def initialize(message="")
7
+ super(message)
8
+ end
9
+ end
10
+
11
+ # This exception is thrown if an attempt is made to access an object that doesn't exist
12
+ class UnknownObjectException < WatirException; end
13
+ # This exception is thrown if an attempt is made to access an object that is in a disabled state
14
+ class ObjectDisabledException < WatirException; end
15
+ # This exception is thrown if an attempt is made to access a frame that cannot be found
16
+ class UnknownFrameException< WatirException; end
17
+ # This exception is thrown if an attempt is made to access a form that cannot be found
18
+ class UnknownFormException< WatirException; end
19
+ # This exception is thrown if an attempt is made to access an object that is in a read only state
20
+ class ObjectReadOnlyException < WatirException; end
21
+ # This exception is thrown if an attempt is made to access an object when the specified value cannot be found
22
+ class NoValueFoundException < WatirException; end
23
+ # This exception gets raised if part of finding an object is missing
24
+ class MissingWayOfFindingObjectException < WatirException; end
25
+ # this exception is raised if an attempt is made to access a table cell that doesnt exist
26
+ class UnknownCellException < WatirException; end
27
+ # This exception is thrown if the window cannot be found
28
+ class NoMatchingWindowFoundException < WatirException; end
29
+ # This exception is thrown if an attemp is made to acces the status bar of the browser when it doesnt exist
30
+ class NoStatusBarException < WatirException; end
31
+ # This exception is thrown if an http error, such as a 404, 500 etc is encountered while navigating
32
+ class NavigationException < WatirException; end
33
+ # This exception is raised if a timeout is exceeded
34
+ class TimeOutException < WatirException
35
+ def initialize(duration, timeout)
36
+ @duration, @timeout = duration, timeout
37
+ end
38
+ attr_reader :duration, :timeout
39
+ end
40
+
41
+ # Return an error message for when unable to locate the element
42
+ def self.message_for_unable_to_locate(how, what)
43
+ result = "using #{how.inspect}"
44
+ result << ", #{what.inspect}" if what
45
+ "Unable to locate element, #{result}"
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,17 @@
1
+ class String
2
+ def matches(x)
3
+ return self == x
4
+ end
5
+ end
6
+
7
+ class Regexp
8
+ def matches(x)
9
+ return self.match(x)
10
+ end
11
+ end
12
+
13
+ class Integer
14
+ def matches(x)
15
+ return self == x
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ # watir/options
2
+
3
+ require 'user-choices'
4
+
5
+ module Watir
6
+ @@options_file = nil
7
+ @@options = nil
8
+ class << self
9
+ # Specify the location of a yaml file containing Watir options. Must be
10
+ # specified before the options are parsed.
11
+ def options_file= file
12
+ @@options_file = file
13
+ end
14
+ def options_file
15
+ @@options_file
16
+ end
17
+ def options= x
18
+ @@options = x
19
+ end
20
+ # Return the Watir options, as a hash. If they haven't been parsed yet,
21
+ # they will be now.
22
+ def options
23
+ @@options ||= Watir::Options.new.execute
24
+ end
25
+ end
26
+
27
+ class Options < UserChoices::Command
28
+ include UserChoices
29
+ def add_sources builder
30
+ builder.add_source EnvironmentSource, :with_prefix, 'watir_'
31
+ if Watir.options_file
32
+ builder.add_source YamlConfigFileSource, :from_complete_path,
33
+ Watir.options_file
34
+ end
35
+ end
36
+ def add_choices builder
37
+ builder.add_choice :browser,
38
+ :type => Watir::Browser.options,
39
+ :default => Watir::Browser.default
40
+ builder.add_choice :speed,
41
+ :type => ['slow', 'fast', 'zippy'],
42
+ :default => 'fast'
43
+ builder.add_choice :visible,
44
+ :type => :boolean
45
+ end
46
+ def execute
47
+ @user_choices[:speed] = @user_choices[:speed].to_sym
48
+ @user_choices
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,58 @@
1
+ require 'test/unit'
2
+ require 'watir/assertions'
3
+
4
+ module Watir
5
+
6
+ class TestCase < Test::Unit::TestCase
7
+ include Watir::Assertions
8
+ @@order = :sequentially
9
+ def initialize name
10
+ throw :invalid_test if name == :default_test && self.class == Watir::TestCase
11
+ super
12
+ end
13
+ class << self
14
+ attr_accessor :test_methods, :order
15
+ def test_methods
16
+ @test_methods ||= []
17
+ end
18
+ def order
19
+ @order || @@order
20
+ end
21
+ def default_order= order
22
+ @@order = order
23
+ end
24
+ def sorted_test_methods
25
+ case order
26
+ when :alphabetically then test_methods.sort
27
+ when :sequentially then test_methods
28
+ when :reversed_sequentially then test_methods.reverse
29
+ when :reversed_alphabetically then test_methods.sort.reverse
30
+ else raise ArgumentError, "Execute option not supported: #{@order}"
31
+ end
32
+ end
33
+ def suite
34
+ suite = Test::Unit::TestSuite.new(name)
35
+ sorted_test_methods.each do |test|
36
+ catch :invalid_test do
37
+ suite << new(test)
38
+ end
39
+ end
40
+ if (suite.empty?)
41
+ catch :invalid_test do
42
+ suite << new(:default_test)
43
+ end
44
+ end
45
+ return suite
46
+ end
47
+ def method_added id
48
+ name = id.id2name
49
+ test_methods << name if name =~ /^test./
50
+ end
51
+ def execute order
52
+ @order = order
53
+ end
54
+ end
55
+ public :add_assertion
56
+ end
57
+
58
+ end
@@ -0,0 +1,92 @@
1
+ require 'watir/exceptions'
2
+
3
+ module Watir
4
+
5
+ def wait_until(*args)
6
+ Waiter.wait_until(*args) {yield}
7
+ end
8
+
9
+ class TimeKeeper
10
+ attr_reader :sleep_time
11
+ def initialize
12
+ @sleep_time = 0.0
13
+ end
14
+ def sleep seconds
15
+ @sleep_time += Kernel.sleep seconds
16
+ end
17
+ def now
18
+ Time.now
19
+ end
20
+ end
21
+
22
+ class Waiter
23
+ # This is an interface to a TimeKeeper which proxies
24
+ # calls to "sleep" and "Time.now".
25
+ # Useful for unit testing Waiter.
26
+ attr_accessor :timer
27
+
28
+ # How long to wait between each iteration through the wait_until
29
+ # loop. In seconds.
30
+ attr_accessor :polling_interval
31
+
32
+ # Timeout for wait_until.
33
+ attr_accessor :timeout
34
+
35
+ @@default_polling_interval = 0.5
36
+ @@default_timeout = 60.0
37
+
38
+ def initialize(timeout=@@default_timeout,
39
+ polling_interval=@@default_polling_interval)
40
+ @timeout = timeout
41
+ @polling_interval = polling_interval
42
+ @timer = TimeKeeper.new
43
+ end
44
+
45
+ # Execute the provided block until either (1) it returns true, or
46
+ # (2) the timeout (in seconds) has been reached. If the timeout is reached,
47
+ # a TimeOutException will be raised. The block will always
48
+ # execute at least once.
49
+ #
50
+ # waiter = Waiter.new(5)
51
+ # waiter.wait_until {puts 'hello'}
52
+ #
53
+ # This code will print out "hello" for five seconds, and then raise a
54
+ # Watir::TimeOutException.
55
+ def wait_until # block
56
+ start_time = now
57
+ until yield do
58
+ if (duration = now - start_time) > @timeout
59
+ raise Watir::Exception::TimeOutException.new(duration, @timeout),
60
+ "Timed out after #{duration} seconds."
61
+ end
62
+ sleep @polling_interval
63
+ end
64
+ end
65
+
66
+ # Execute the provided block until either (1) it returns true, or
67
+ # (2) the timeout (in seconds) has been reached. If the timeout is reached,
68
+ # a TimeOutException will be raised. The block will always
69
+ # execute at least once.
70
+ #
71
+ # Waiter.wait_until(5) {puts 'hello'}
72
+ #
73
+ # This code will print out "hello" for five seconds, and then raise a
74
+ # Watir::TimeOutException.
75
+
76
+ # IDEA: wait_until: remove defaults from Waiter.wait_until
77
+ def self.wait_until(timeout=@@default_timeout,
78
+ polling_interval=@@default_polling_interval)
79
+ waiter = new(timeout, polling_interval)
80
+ waiter.wait_until { yield }
81
+ end
82
+
83
+ private
84
+ def sleep seconds
85
+ @timer.sleep seconds
86
+ end
87
+ def now
88
+ @timer.now
89
+ end
90
+ end
91
+
92
+ end # module
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commonwatir
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.2
5
+ platform: ruby
6
+ authors:
7
+ - Bret Pettichord
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-06 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: user-choices
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.0
34
+ version:
35
+ description: Common code used by Watir and FireWatir
36
+ email:
37
+ - bret@watircraft.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - History.txt
44
+ - Manifest.txt
45
+ - README.txt
46
+ files:
47
+ - History.txt
48
+ - Manifest.txt
49
+ - README.txt
50
+ - Rakefile
51
+ - lib/watir.rb
52
+ - lib/watir-common.rb
53
+ - lib/watir/assertions.rb
54
+ - lib/watir/browser.rb
55
+ - lib/watir/browsers.rb
56
+ - lib/watir/exceptions.rb
57
+ - lib/watir/matches.rb
58
+ - lib/watir/options.rb
59
+ - lib/watir/testcase.rb
60
+ - lib/watir/waiter.rb
61
+ has_rdoc: true
62
+ homepage: FIX (url)
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --main
66
+ - README.txt
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: wtr
84
+ rubygems_version: 1.2.0
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: Common code used by Watir and FireWatir
88
+ test_files: []
89
+