marekj-watirloo 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/History.txt +12 -0
  2. data/Manifest.txt +59 -34
  3. data/README.rdoc +63 -80
  4. data/Rakefile.rb +32 -39
  5. data/config/locker.yml +0 -0
  6. data/lib/watirloo.rb +9 -162
  7. data/lib/watirloo/browsers.rb +73 -0
  8. data/lib/watirloo/desktop.rb +44 -0
  9. data/lib/watirloo/{firewatir_ducktape.rb → extension/firewatir_ducktape.rb} +0 -0
  10. data/lib/watirloo/extension/object.rb +26 -0
  11. data/lib/watirloo/{watir_ducktape.rb → extension/watir_ducktape.rb} +181 -16
  12. data/lib/watirloo/extension/watir_reflector.rb +83 -0
  13. data/lib/watirloo/locker.rb +84 -0
  14. data/lib/watirloo/page.rb +105 -0
  15. data/spec/browser_spec.rb +38 -0
  16. data/spec/browser_threads_spec.rb +45 -0
  17. data/spec/checkbox_group_spec.rb +136 -0
  18. data/spec/checkbox_groups_spec.rb +55 -0
  19. data/spec/checkboxes_value_spec.rb +35 -0
  20. data/spec/desktop_spec.rb +54 -0
  21. data/spec/extra/browser_events_spec.rb +76 -0
  22. data/spec/extra/page_objects_metrics.rb +139 -0
  23. data/spec/face_mixing_spec.rb +55 -0
  24. data/{test → spec}/firewatir/attach_instance_test.rb +0 -0
  25. data/spec/firewatir/spec_results.html +263 -0
  26. data/spec/firewatir/spec_results.txt +23 -0
  27. data/spec/firewatir/spec_results_failed.txt +3 -0
  28. data/{test → spec}/html/census.html +0 -0
  29. data/spec/html/checkbox_group1.html +33 -0
  30. data/spec/html/labels.html +53 -0
  31. data/spec/html/no_title.html +13 -0
  32. data/{test → spec}/html/person.html +0 -0
  33. data/spec/html/radio_group.html +35 -0
  34. data/{test → spec}/html/select_lists.html +0 -0
  35. data/spec/input_element_spec.rb +51 -0
  36. data/spec/label_spec.rb +65 -0
  37. data/spec/locker_spec.rb +49 -0
  38. data/spec/page_spec.rb +53 -0
  39. data/spec/person_def_wrappers_spec.rb +40 -0
  40. data/spec/radio_group_spec.rb +95 -0
  41. data/spec/radio_groups_spec.rb +55 -0
  42. data/spec/reflector_spec.rb +82 -0
  43. data/spec/select_list_options_spec.rb +40 -0
  44. data/spec/select_lists_spec.rb +151 -0
  45. data/{test/test_helper.rb → spec/spec_helper.rb} +6 -4
  46. data/spec/spec_helper_ff.rb +5 -0
  47. data/spec/spec_helper_runner.rb +13 -0
  48. data/spec/spec_results.html +566 -0
  49. data/spec/spec_results.txt +179 -0
  50. data/spec/spec_results_failed.txt +1 -0
  51. data/spec/text_fields_spec.rb +56 -0
  52. data/watirloo.gemspec +44 -44
  53. metadata +80 -39
  54. data/lib/watirloo/reflector.rb +0 -137
  55. data/test/checkbox_group_test.rb +0 -83
  56. data/test/checkboxes_value_test.rb +0 -50
  57. data/test/html/checkbox_group1.html +0 -20
  58. data/test/html/labels.html +0 -32
  59. data/test/html/radio_group.html +0 -41
  60. data/test/interfaces_test.rb +0 -79
  61. data/test/label_test.rb +0 -64
  62. data/test/person_def_wrappers_test.rb +0 -55
  63. data/test/radio_group_test.rb +0 -97
  64. data/test/select_list_in_class_test.rb +0 -39
  65. data/test/select_list_options_test.rb +0 -39
  66. data/test/select_lists_test.rb +0 -145
  67. 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
- lib/watirloo.rb
6
- lib/watirloo/firewatir_ducktape.rb
7
- lib/watirloo/reflector.rb
8
- lib/watirloo/watir_ducktape.rb
9
- script/console
10
- script/console.cmd
11
- script/destroy
12
- script/destroy.cmd
13
- script/generate
14
- script/generate.cmd
15
- script/reflect.rb
16
- test/checkbox_group_test.rb
17
- test/checkboxes_value_test.rb
18
- test/firewatir/attach_instance_test.rb
19
- test/html/census.html
20
- test/html/checkbox_group1.html
21
- test/html/labels.html
22
- test/html/person.html
23
- test/html/radio_group.html
24
- test/html/select_lists.html
25
- test/interfaces_test.rb
26
- test/label_test.rb
27
- test/person_def_wrappers_test.rb
28
- test/radio_group_test.rb
29
- test/select_list_in_class_test.rb
30
- test/select_list_options_test.rb
31
- test/select_lists_test.rb
32
- test/test_helper.rb
33
- test/text_fields_test.rb
34
- watirloo.gemspec
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.testr.us
3
+ * http://github.com/marekj/watirloo
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- Watir Framework and Helper based on Semantic Page Objects Modeling.
8
- Helps you design tests expressing DOM elements and groups of elements
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
- Give it a try. You will like it.
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
- * Watirloo::Page acts as an adapter with customer facing semantic names for page objects and developer facing implamention talking to the browser.
18
- * Page creates an abstraction adapter: Human Readable and Machine Executable.
19
- * Pages contain faces; page objects that are named with semantic intent
20
- * Best to work with one browser instance on the desktop.
21
- * Patches Watir and Firewatir to ease testing
22
- * groups radios in radio_group and checkboxes in checkbox_group and acts each group as page object
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::Page.new attaches itself to the existing IE browser instance on the desktop.
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: Given a page with text fields for last name and first name we want to enter name 'Kurt Vonnegut'
29
- You can define hash with key as semantic name and value as watir implementation
31
+ Example:
30
32
 
31
- page = Watirloo::Page.new
32
- page.add_face :last => [:text_field, :name, 'l_nm'],
33
- :first => [:text_field, :name, 'f_nm']
34
- page.last.set "Vonnegut"
35
- page.first.set "Kurt"
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 >= 1.6.2 runs on IE by default
63
- * firewatir >= 1.6.2 if you want to use Firefox
64
- * test/spec gem if you want to run tests
65
- * newgem and hoe for dev
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
- * gem install watirloo
70
-
71
- === ROADMAP
75
+ * Run the following if you haven't already:
76
+ gem sources -a http://gems.github.com
72
77
 
73
- Towards version 0.0.3
78
+ * Install the gem(s):
79
+ gem install marekj-watirloo
74
80
 
75
- * DONE: make class level interfaces as base for the class and subclass. remove it from initilize method
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
- Towards version 0.0.2
83
+ === ROADMAP
82
84
 
83
- * DONE: make Watirloo agnostic to browser IE or Firefox or Safari
84
- * DONE: make tests run on IE, Firefox, Safari with the same interface
85
- * DONE: create radio_group to behave like select list and checkbox_group like multi select list
86
- * build UseCase class as template for scenario based execution of tests for exploratory testing
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
- ['test/spec', '>=0.9.0']
15
+ ['rspec', ">= #{::Spec::VERSION::STRING}"]
16
16
  ]
17
- p.test_globs =['test/*_test.rb']
18
- p.testlib = ['test/spec']
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
- # all tests use attach method to a browser that exit on the desktop
36
- # open new ie browser
37
- Watir::Browser.default = 'ie'
38
- Watir::Browser.new
39
- Watirloo::BrowserHerd.target = :ie
40
- chdir File.dirname(__FILE__) do
41
- tests = Dir["test/*_test.rb"]
42
- tests.each do |t|
43
- require t
44
- end
45
- end
46
-
47
- # at the end of test you will have one extra browser
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 "run all tests on Firefox (config per FireWatir gem)"
52
- task :test_ff do
53
- # all tests attach to an existing firefox browser
54
- # start browser with jssh option
55
- Watir::Browser.default='firefox'
56
- Watir::Browser.new
57
- tests = Dir["test/*_test.rb"]
58
- tests.each do |t|
59
- Watirloo::BrowserHerd.target = :firefox
60
- require t
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/watir_ducktape'
5
- require 'watirloo/reflector'
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
- VERSION = '0.0.3' # Jan2009
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