marekj-watirloo 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -0
- data/Manifest.txt +59 -34
- data/README.rdoc +63 -80
- data/Rakefile.rb +32 -39
- data/config/locker.yml +0 -0
- data/lib/watirloo.rb +9 -162
- data/lib/watirloo/browsers.rb +73 -0
- data/lib/watirloo/desktop.rb +44 -0
- data/lib/watirloo/{firewatir_ducktape.rb → extension/firewatir_ducktape.rb} +0 -0
- data/lib/watirloo/extension/object.rb +26 -0
- data/lib/watirloo/{watir_ducktape.rb → extension/watir_ducktape.rb} +181 -16
- data/lib/watirloo/extension/watir_reflector.rb +83 -0
- data/lib/watirloo/locker.rb +84 -0
- data/lib/watirloo/page.rb +105 -0
- data/spec/browser_spec.rb +38 -0
- data/spec/browser_threads_spec.rb +45 -0
- data/spec/checkbox_group_spec.rb +136 -0
- data/spec/checkbox_groups_spec.rb +55 -0
- data/spec/checkboxes_value_spec.rb +35 -0
- data/spec/desktop_spec.rb +54 -0
- data/spec/extra/browser_events_spec.rb +76 -0
- data/spec/extra/page_objects_metrics.rb +139 -0
- data/spec/face_mixing_spec.rb +55 -0
- data/{test → spec}/firewatir/attach_instance_test.rb +0 -0
- data/spec/firewatir/spec_results.html +263 -0
- data/spec/firewatir/spec_results.txt +23 -0
- data/spec/firewatir/spec_results_failed.txt +3 -0
- data/{test → spec}/html/census.html +0 -0
- data/spec/html/checkbox_group1.html +33 -0
- data/spec/html/labels.html +53 -0
- data/spec/html/no_title.html +13 -0
- data/{test → spec}/html/person.html +0 -0
- data/spec/html/radio_group.html +35 -0
- data/{test → spec}/html/select_lists.html +0 -0
- data/spec/input_element_spec.rb +51 -0
- data/spec/label_spec.rb +65 -0
- data/spec/locker_spec.rb +49 -0
- data/spec/page_spec.rb +53 -0
- data/spec/person_def_wrappers_spec.rb +40 -0
- data/spec/radio_group_spec.rb +95 -0
- data/spec/radio_groups_spec.rb +55 -0
- data/spec/reflector_spec.rb +82 -0
- data/spec/select_list_options_spec.rb +40 -0
- data/spec/select_lists_spec.rb +151 -0
- data/{test/test_helper.rb → spec/spec_helper.rb} +6 -4
- data/spec/spec_helper_ff.rb +5 -0
- data/spec/spec_helper_runner.rb +13 -0
- data/spec/spec_results.html +566 -0
- data/spec/spec_results.txt +179 -0
- data/spec/spec_results_failed.txt +1 -0
- data/spec/text_fields_spec.rb +56 -0
- data/watirloo.gemspec +44 -44
- metadata +80 -39
- data/lib/watirloo/reflector.rb +0 -137
- data/test/checkbox_group_test.rb +0 -83
- data/test/checkboxes_value_test.rb +0 -50
- data/test/html/checkbox_group1.html +0 -20
- data/test/html/labels.html +0 -32
- data/test/html/radio_group.html +0 -41
- data/test/interfaces_test.rb +0 -79
- data/test/label_test.rb +0 -64
- data/test/person_def_wrappers_test.rb +0 -55
- data/test/radio_group_test.rb +0 -97
- data/test/select_list_in_class_test.rb +0 -39
- data/test/select_list_options_test.rb +0 -39
- data/test/select_lists_test.rb +0 -145
- data/test/text_fields_test.rb +0 -68
data/History.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== 0.0.5 22Jul2009
|
2
|
+
* Page is a module and not a class. include Watirloo::Page in your testcase (rspec group or cucumber feature) to add view methods.
|
3
|
+
* Locker uses config/locker.yml by default. If you want your own somewhere in your project update the Watirloo::Locker.locker = "path/to/your/config/locker.yml"
|
4
|
+
* multiple browser support with Watirloo::Desktop and Locker
|
5
|
+
* 115 examples in rspec
|
6
|
+
|
7
|
+
== 0.0.4 16feb2009
|
8
|
+
* Radio and Checkbox Groups, UseCase class and reflector
|
9
|
+
* RadioGroups class and enhance radio_group(how, what) method
|
10
|
+
* CheckboxGroups class and enhance checkbox_group(how, what) method
|
11
|
+
* ElementCollections.reflect and Container.reflect method redesign
|
12
|
+
|
1
13
|
== 0.0.3 25jan2009
|
2
14
|
|
3
15
|
* implement inheritable class interfaces
|
data/Manifest.txt
CHANGED
@@ -1,34 +1,59 @@
|
|
1
|
-
History.txt
|
2
|
-
Manifest.txt
|
3
|
-
README.rdoc
|
4
|
-
Rakefile.rb
|
5
|
-
|
6
|
-
lib/watirloo
|
7
|
-
lib/watirloo/
|
8
|
-
lib/watirloo/
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
script/
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.rdoc
|
4
|
+
Rakefile.rb
|
5
|
+
config/locker.yml
|
6
|
+
lib/watirloo.rb
|
7
|
+
lib/watirloo/browsers.rb
|
8
|
+
lib/watirloo/desktop.rb
|
9
|
+
lib/watirloo/extension/firewatir_ducktape.rb
|
10
|
+
lib/watirloo/extension/object.rb
|
11
|
+
lib/watirloo/extension/watir_ducktape.rb
|
12
|
+
lib/watirloo/extension/watir_reflector.rb
|
13
|
+
lib/watirloo/locker.rb
|
14
|
+
lib/watirloo/page.rb
|
15
|
+
script/console
|
16
|
+
script/console.cmd
|
17
|
+
script/destroy
|
18
|
+
script/destroy.cmd
|
19
|
+
script/generate
|
20
|
+
script/generate.cmd
|
21
|
+
script/reflect.rb
|
22
|
+
spec/browser_spec.rb
|
23
|
+
spec/browser_threads_spec.rb
|
24
|
+
spec/checkbox_group_spec.rb
|
25
|
+
spec/checkbox_groups_spec.rb
|
26
|
+
spec/checkboxes_value_spec.rb
|
27
|
+
spec/desktop_spec.rb
|
28
|
+
spec/extra/browser_events_spec.rb
|
29
|
+
spec/extra/page_objects_metrics.rb
|
30
|
+
spec/face_mixing_spec.rb
|
31
|
+
spec/firewatir/attach_instance_test.rb
|
32
|
+
spec/firewatir/spec_results.html
|
33
|
+
spec/firewatir/spec_results.txt
|
34
|
+
spec/firewatir/spec_results_failed.txt
|
35
|
+
spec/html/census.html
|
36
|
+
spec/html/checkbox_group1.html
|
37
|
+
spec/html/labels.html
|
38
|
+
spec/html/no_title.html
|
39
|
+
spec/html/person.html
|
40
|
+
spec/html/radio_group.html
|
41
|
+
spec/html/select_lists.html
|
42
|
+
spec/input_element_spec.rb
|
43
|
+
spec/label_spec.rb
|
44
|
+
spec/locker_spec.rb
|
45
|
+
spec/page_spec.rb
|
46
|
+
spec/person_def_wrappers_spec.rb
|
47
|
+
spec/radio_group_spec.rb
|
48
|
+
spec/radio_groups_spec.rb
|
49
|
+
spec/reflector_spec.rb
|
50
|
+
spec/select_list_options_spec.rb
|
51
|
+
spec/select_lists_spec.rb
|
52
|
+
spec/spec_helper.rb
|
53
|
+
spec/spec_helper_ff.rb
|
54
|
+
spec/spec_helper_runner.rb
|
55
|
+
spec/spec_results.html
|
56
|
+
spec/spec_results.txt
|
57
|
+
spec/spec_results_failed.txt
|
58
|
+
spec/text_fields_spec.rb
|
59
|
+
watirloo.gemspec
|
data/README.rdoc
CHANGED
@@ -1,112 +1,95 @@
|
|
1
1
|
= Watirloo
|
2
2
|
|
3
|
-
* http://watirloo
|
3
|
+
* http://github.com/marekj/watirloo
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
|
-
Watir
|
8
|
-
|
9
|
-
on the page as Semantic Page Objects rather than their DOM implementations.
|
10
|
-
It is not a DSL but it helps you write human readable tests and hooks them up
|
11
|
-
to Watir browsers for implementation
|
7
|
+
Custom Extensions for Watir, Firewatir. Acceptance Test Helper based on semantic page objects modeling customer's domain language
|
8
|
+
It helps you write human readable and machine executable browser tests. Isolates GUI from Tests.
|
12
9
|
|
13
|
-
|
10
|
+
The Human Readable part helps you create interfaces to elements on the page and tags them with friendly names
|
11
|
+
based on vocabulary of Business Domain. The Machine Executable parts talk to Watir API hooking into DOM elements.
|
12
|
+
it helps you concentrate in your acceptance tests on the intention and the customer's language and not on implementation of DOM.
|
13
|
+
Write customer facing tests hence the metaphor of face for Page Objects of Significance to the Customer.
|
14
14
|
|
15
15
|
== FEATURES/PROBLEMS:
|
16
16
|
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*
|
20
|
-
*
|
21
|
-
*
|
22
|
-
*
|
17
|
+
* Extensioins to Watir and Firewatir gems to ease testing
|
18
|
+
* group radios in #radio_group and checkboxes in #checkbox_group and acts each group as page object
|
19
|
+
* Maintains multiple browsers on the desktop and stores window handles so you can reattach to the browser under test later (see Watirloo::Locker)
|
20
|
+
* Watches and maintains your desktop for browsers existence. (Watirloo::Desktop)
|
21
|
+
* Browser is managed automatically with Watirloo::browser
|
22
|
+
* Isolates GUI from tests with face methods that introduce customer facing friendly names for elements
|
23
|
+
* add reflect method to generate scaffolding code for your page elements (reflect currently uses browser as container. Alter scaffodling if you use frames)
|
24
|
+
* look at spec dir for examples of usage with rspec
|
25
|
+
|
23
26
|
|
24
27
|
== SYNOPSIS:
|
25
28
|
|
26
|
-
By convention Watirloo::
|
29
|
+
By convention Watirloo::browser attaches itself to the existing IE browser instance on the desktop and maintains the handles to reattach later
|
27
30
|
|
28
|
-
Example:
|
29
|
-
You can define hash with key as semantic name and value as watir implementation
|
31
|
+
Example:
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
Given a page with text fields for last name and first name
|
34
|
+
When I want to enter the name 'Kurt Vonnegut'
|
35
|
+
And I don't want to talk to implementation
|
36
|
+
But I want a friendly name of element on the page
|
37
|
+
Then I use Watirloo shortcuts
|
38
|
+
When I define an interface to watir implementation with a semantic key
|
39
|
+
And I define my data as hash with the same semantic key
|
40
|
+
Then I can automatically let watirloo enter my test data on a page
|
41
|
+
|
42
|
+
# rspec as container
|
43
|
+
|
44
|
+
describe "using watirloo page to isolate and bind gui view to data" do
|
45
|
+
include Watirloo::Page
|
46
|
+
face(:last) {browser.text_field(:name, 'l_nm')}
|
47
|
+
face(:first) {browser.text_field(:name, 'f_nm')}
|
48
|
+
|
49
|
+
it "enters data on the page" do
|
50
|
+
last.set "Vonnegut"
|
51
|
+
first.set "Kurt"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "sprays data on elements defined" do
|
55
|
+
spray :last => 'Vonnegut', :first => 'Kurt'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "grabs data from elements and validates" do
|
59
|
+
data = {:first => "Kurt", :last => 'Vonnegut'}
|
60
|
+
spray data
|
61
|
+
scrape(data.keys).should == data
|
62
|
+
end
|
36
63
|
|
37
|
-
Or you can create a wrapper method that delegates to the browser
|
38
|
-
|
39
|
-
class Person < Watirloo::Page
|
40
|
-
def last
|
41
|
-
@b.text_field(:name, 'lnm')
|
42
|
-
end
|
43
|
-
def first
|
44
|
-
@b.text_field(:name, 'fnm')
|
45
64
|
end
|
46
|
-
end
|
47
|
-
|
48
|
-
Or define a hash where key will match the defined faces to be set
|
49
|
-
params = {:first => 'Kurt', :last => 'Vonnegut'}
|
50
|
-
page = Watirloo::Page.new.spray params
|
51
|
-
|
52
|
-
Or pass page cofiguration in the block at page creation
|
53
|
-
|
54
|
-
page = Person.new do
|
55
|
-
last.set 'Vonnegut'
|
56
|
-
first.set 'Kurt'
|
57
|
-
end
|
58
|
-
|
59
65
|
|
60
66
|
== REQUIREMENTS:
|
61
67
|
|
62
|
-
* watir
|
63
|
-
* firewatir
|
64
|
-
*
|
65
|
-
*
|
68
|
+
* watir = 1.6.2
|
69
|
+
* firewatir = 1.6.2 if you want to use Firefox
|
70
|
+
* newgem
|
71
|
+
* rspec gem if you want to run watirloo examples included
|
66
72
|
|
67
73
|
== INSTALL:
|
68
74
|
|
69
|
-
*
|
70
|
-
|
71
|
-
=== ROADMAP
|
75
|
+
* Run the following if you haven't already:
|
76
|
+
gem sources -a http://gems.github.com
|
72
77
|
|
73
|
-
|
78
|
+
* Install the gem(s):
|
79
|
+
gem install marekj-watirloo
|
74
80
|
|
75
|
-
*
|
76
|
-
* UseCase class, scenario based runner
|
77
|
-
* clean up reflector method to reflect according to new interface structures
|
78
|
-
* move RadioGroup and CheckboxGroup to Watir gem (work with Bret)
|
79
|
-
* make RadioGroups and CheckboxGroups classes for both IE and Firefox
|
81
|
+
* or download from : http://github.com/marekj/watirloo/downloads
|
80
82
|
|
81
|
-
|
83
|
+
=== ROADMAP
|
82
84
|
|
83
|
-
*
|
84
|
-
*
|
85
|
-
*
|
86
|
-
*
|
85
|
+
* add Logging gem and log all actions for audit
|
86
|
+
* provide UserStory type of container for exploratory testing (UseCase, Feature, TestScenario etc...)
|
87
|
+
* provide examples for Cucumber
|
88
|
+
* make specs run with firewatir
|
87
89
|
|
88
90
|
== LICENSE:
|
89
91
|
|
90
92
|
(The MIT License)
|
91
93
|
|
92
94
|
Copyright (c) 2008 marekj
|
93
|
-
|
94
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
95
|
-
a copy of this software and associated documentation files (the
|
96
|
-
'Software'), to deal in the Software without restriction, including
|
97
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
98
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
99
|
-
permit persons to whom the Software is furnished to do so, subject to
|
100
|
-
the following conditions:
|
101
|
-
|
102
|
-
The above copyright notice and this permission notice shall be
|
103
|
-
included in all copies or substantial portions of the Software.
|
104
|
-
|
105
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
106
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
107
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
108
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
109
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
110
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
111
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
112
|
-
|
95
|
+
http://www.opensource.org/licenses/mit-license.php
|
data/Rakefile.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen spec].each { |f| require f }
|
2
2
|
require File.dirname(__FILE__) + '/lib/watirloo'
|
3
3
|
|
4
4
|
# Generate all the Rake tasks
|
@@ -12,10 +12,10 @@ $hoe = Hoe.new('watirloo', Watirloo::VERSION) do |p|
|
|
12
12
|
]
|
13
13
|
p.extra_dev_deps = [
|
14
14
|
['newgem', ">= #{::Newgem::VERSION}"],
|
15
|
-
['
|
15
|
+
['rspec', ">= #{::Spec::VERSION::STRING}"]
|
16
16
|
]
|
17
|
-
p.test_globs =['
|
18
|
-
p.testlib = ['
|
17
|
+
p.test_globs =['spec/*_spec.rb']
|
18
|
+
p.testlib = ['spec']
|
19
19
|
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
20
20
|
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
21
21
|
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/, ''), 'rdoc')
|
@@ -25,43 +25,36 @@ end
|
|
25
25
|
require 'newgem/tasks' # load /tasks/*.rake
|
26
26
|
Dir['tasks/**/*.rake'].each { |t| load t }
|
27
27
|
|
28
|
-
desc "run all tests on IE."
|
29
|
-
task :test_ie do
|
30
|
-
require 'rubygems' # needed?
|
31
|
-
gem 'ci_reporter'
|
32
|
-
require 'ci/reporter/rake/test_unit'
|
33
|
-
load 'ci/reporter/rake/test_unit_loader.rb'
|
34
28
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
29
|
+
require 'spec/rake/spectask'
|
30
|
+
desc "spec with ie browser"
|
31
|
+
Spec::Rake::SpecTask.new do |t|
|
32
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
33
|
+
t.fail_on_error = false
|
34
|
+
t.spec_opts = [
|
35
|
+
#"--require spec/spec_helper_runner.rb", # slow execution expected
|
36
|
+
"--format specdoc",
|
37
|
+
"--format specdoc:spec/spec_results.txt",
|
38
|
+
"--format failing_examples:spec/spec_results_failed.txt",
|
39
|
+
"--format html:spec/spec_results.html",
|
40
|
+
#"--diff",
|
41
|
+
"--loadby mtime",
|
42
|
+
#"--dry-run", # will overwrite any previous spec_results
|
43
|
+
#"--generate-options spec/spec.opts",
|
44
|
+
]
|
48
45
|
end
|
49
46
|
|
50
|
-
|
51
|
-
desc "
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
# at the end of test you will have one extra browser
|
47
|
+
# FIXME fix the spec FileList to only include those that execut for firefox. use taglog lib
|
48
|
+
desc "spec with ff browser"
|
49
|
+
Spec::Rake::SpecTask.new(:spec_ff) do |t|
|
50
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
51
|
+
t.spec_opts = [
|
52
|
+
"--require spec/spec_helper_ff.rb",
|
53
|
+
"--format specdoc",
|
54
|
+
"--format specdoc:spec/firewatir/spec_results.txt",
|
55
|
+
"--format failing_examples:spec/firewatir/spec_results_failed.txt",
|
56
|
+
"--format html:spec/firewatir/spec_results.html",
|
57
|
+
"--loadby mtime" ]
|
63
58
|
end
|
64
59
|
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
#task :default => :spec
|
data/config/locker.yml
ADDED
File without changes
|
data/lib/watirloo.rb
CHANGED
@@ -1,169 +1,16 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
require 'watirloo/
|
5
|
-
require 'watirloo/
|
4
|
+
require 'watirloo/extension/object'
|
5
|
+
require 'watirloo/extension/watir_ducktape'
|
6
|
+
require 'watirloo/extension/watir_reflector'
|
7
|
+
require 'watirloo/browsers'
|
8
|
+
require 'watirloo/desktop'
|
9
|
+
require 'watirloo/locker'
|
10
|
+
require 'watirloo/page'
|
6
11
|
|
7
12
|
module Watirloo
|
13
|
+
VERSION = '0.0.5' # Jul2009
|
8
14
|
|
9
|
-
|
10
|
-
|
11
|
-
# browser. we return IE or Firefox. Safari? Other Browser?
|
12
|
-
class BrowserHerd
|
13
|
-
|
14
|
-
@@target = :ie
|
15
|
-
#targets = [:ie, :firefox]
|
16
|
-
|
17
|
-
class << self
|
18
|
-
|
19
|
-
def target=(indicator)
|
20
|
-
@@target = indicator
|
21
|
-
end
|
22
|
-
|
23
|
-
def target
|
24
|
-
@@target
|
25
|
-
end
|
26
|
-
|
27
|
-
# provides browser instance to client.
|
28
|
-
# attaches to the existing browser on the desktop
|
29
|
-
# By convention the mental model here is that we are working
|
30
|
-
# with one browser on the desktop. This is how a person would typically work
|
31
|
-
# We are not doing any fancy
|
32
|
-
#
|
33
|
-
def browser
|
34
|
-
case @@target
|
35
|
-
when :ie
|
36
|
-
Watir::IE.attach :url, // #this attach is a crutch
|
37
|
-
when :firefox
|
38
|
-
require 'watirloo/firewatir_ducktape'
|
39
|
-
# this is a cruch for quick work with pages.
|
40
|
-
# in reality you want to create a browser and pass it as argument to initialize Page class
|
41
|
-
FireWatir::Firefox.attach #this attach is a crutch
|
42
|
-
else
|
43
|
-
raise ::Watir::Exception::WatirException, "Browser target not supported"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Semantic Page Objects Container
|
50
|
-
# Page containes interfaces to Objects of Interest on the Web Page
|
51
|
-
# Each object defined by key, value pair,
|
52
|
-
# Keys is a friendly name, recognizable name given by the domain object model.
|
53
|
-
# Some name that is meaningful to the customer.
|
54
|
-
# The value of the interface definiton is a Watir object address in the dom container.
|
55
|
-
# The Page class acts as an Adapter between the Business Domain naming of things and Document Object Model naming of elments.
|
56
|
-
# It strives to adapt Human Readable tests to Machine Executable code
|
57
|
-
class Page
|
58
|
-
|
59
|
-
## Page Eigenclass
|
60
|
-
class << self
|
61
|
-
|
62
|
-
# hash key value pairs,
|
63
|
-
# each interface definition is a key as symbol pointing to some code to
|
64
|
-
# exeucte later.
|
65
|
-
def interfaces
|
66
|
-
@interfaces ||= {}
|
67
|
-
end
|
68
|
-
|
69
|
-
# Declares Semantic Interface to the DOM elements on the Page
|
70
|
-
# face :friendlyname => [watirelement, how, what]
|
71
|
-
# Each interface or face is an object of interest that we want to access by its interface name
|
72
|
-
# example:
|
73
|
-
# class GoogleSearch < Watirloo::Page
|
74
|
-
# face :query => [:text_field, :name, 'q]
|
75
|
-
# face :search => [:button, :name, 'btnG']
|
76
|
-
# end
|
77
|
-
# each face is a key declared by a semantic symbol that has human meaning in the context of a usecase
|
78
|
-
# each value is an array defining access to Watir [:elementType, how, what]
|
79
|
-
def interface(definition)
|
80
|
-
if definition.kind_of? Hash
|
81
|
-
self.interfaces.update definition
|
82
|
-
else
|
83
|
-
raise ::Watir::Exception::WatirException, "Wrong arguments for Page Object definition"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
alias face interface
|
87
|
-
|
88
|
-
def inherited(subpage)
|
89
|
-
#puts "#{subpage} inherited #{interfaces.inspect} from #{self}"
|
90
|
-
subpage.interfaces.update self.interfaces #supply parent's interfaces to subclasses in eigenclass
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
attr_accessor :b, :interfaces
|
95
|
-
|
96
|
-
def browser
|
97
|
-
@b
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
def create_interfaces
|
102
|
-
@interfaces = self.class.interfaces.dup # do not pass reference, only values
|
103
|
-
end
|
104
|
-
|
105
|
-
# by convention the Page just attaches to the first available browser.
|
106
|
-
# the smart thing to do is to manage browsers existence on the desktop separately
|
107
|
-
# and supply Page class with the instance of browser you want for your tests.
|
108
|
-
# &block is the convenience at creation time to do some work.
|
109
|
-
# example:
|
110
|
-
# browser = Watir::start("http://mysitetotest")
|
111
|
-
# page = Page.new(browser) # specify browser instance to work with or
|
112
|
-
# page = Page.new # just let the page do lazy thing and attach itself to browser.
|
113
|
-
# part of this page initialization is to provide a convenience while developing tests where
|
114
|
-
# we may have only one browser open and that's the one browser were we want to talk to.
|
115
|
-
# this provides simplicity for those who are just starting with Watirloo
|
116
|
-
def initialize(browser = Watirloo::BrowserHerd.browser , &blk)
|
117
|
-
@b = browser
|
118
|
-
create_interfaces
|
119
|
-
instance_eval(blk) if block_given? # allows the shortcut to do some work at page creation
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
|
-
# enter values on controls idenfied by keys on the page.
|
124
|
-
# data map is a hash, key represents the page object,
|
125
|
-
# value represents its value to be set, either text, array or boolean
|
126
|
-
def spray(dataMap)
|
127
|
-
dataMap.each_pair do |facename, value|
|
128
|
-
get_face(facename).set value #make every element in the dom respond to set to set its value
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# set values on the page given the interface keys
|
133
|
-
alias set spray
|
134
|
-
|
135
|
-
# return Watir object given by its semantic face symbol name
|
136
|
-
def get_face(facename)
|
137
|
-
if self.respond_to? facename # if there is a defined wrapper method for page element provided
|
138
|
-
return self.send(facename)
|
139
|
-
elsif interfaces.member?(facename) # pull element from @interfaces and send to browser
|
140
|
-
method, *args = self.interfaces[facename] # return definition for face consumable by browser
|
141
|
-
return browser.send(method, *args) #returns Watir Element class
|
142
|
-
else
|
143
|
-
raise ::Watir::Exception::WatirException, 'Unknown Semantic Facename'
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
# add face definition to page
|
148
|
-
def interface(definitions)
|
149
|
-
if definitions.kind_of?(Hash)
|
150
|
-
interfaces.update definitions
|
151
|
-
else
|
152
|
-
raise ::Watir::Exception::WatirException, "Wrong arguments for Page Object definition"
|
153
|
-
end
|
154
|
-
end
|
155
|
-
alias face interface
|
156
|
-
|
157
|
-
# Delegate execution to browser if no method or face defined on page class
|
158
|
-
def method_missing method, *args
|
159
|
-
if browser.respond_to?(method.to_sym)
|
160
|
-
return browser.send(method.to_sym, *args)
|
161
|
-
elsif interfaces.member?(method.to_sym)
|
162
|
-
return get_face(method.to_sym)
|
163
|
-
else
|
164
|
-
raise ::Watir::Exception::WatirException, 'I ran out of ideas in Watirloo'
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
15
|
+
end
|
168
16
|
|
169
|
-
end
|