marekj-watirloo 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,10 +1,17 @@
1
- == 0.0.2 2009-02-03
1
+ == 0.0.3 25jan2009
2
+
3
+ * implement inheritable class interfaces
4
+ * subclasses inherit class level interfaces from superclasses
5
+ * initialize makes a set of interfaces to that instance only but inherits class interfaces from entire tree
6
+ * adding interfaces to the instance does not leak into classes
7
+
8
+ == 0.0.2 03jan2009
2
9
 
3
10
  * implement radio_group and checkbox_group for IE and Firefox
4
11
  * Create RadioGroup and CheckboxGroup class for Watir::IE and FireWatir::Firefox
5
12
  * update tests to run for both browsers unchanged.
6
13
 
7
- == 0.0.1 2008-12-22
14
+ == 0.0.1 22dec2008
8
15
 
9
16
  * initial merge with newgem generated structure to make it a gem
10
17
  * Patches to Watir and Firewatir
data/Manifest.txt CHANGED
@@ -2,7 +2,6 @@ History.txt
2
2
  Manifest.txt
3
3
  README.rdoc
4
4
  Rakefile.rb
5
- lib/watirloo
6
5
  lib/watirloo.rb
7
6
  lib/watirloo/firewatir_ducktape.rb
8
7
  lib/watirloo/reflector.rb
@@ -16,19 +15,18 @@ script/generate.cmd
16
15
  script/reflect.rb
17
16
  test/checkbox_group_test.rb
18
17
  test/checkboxes_value_test.rb
19
- test/firewatir
20
18
  test/firewatir/attach_instance_test.rb
21
- test/html
22
19
  test/html/census.html
23
20
  test/html/checkbox_group1.html
24
21
  test/html/labels.html
25
22
  test/html/person.html
26
23
  test/html/radio_group.html
27
24
  test/html/select_lists.html
25
+ test/interfaces_test.rb
28
26
  test/label_test.rb
29
27
  test/person_def_wrappers_test.rb
30
28
  test/radio_group_test.rb
31
- test/select_list_as_face_test.rb
29
+ test/select_list_in_class_test.rb
32
30
  test/select_list_options_test.rb
33
31
  test/select_lists_test.rb
34
32
  test/test_helper.rb
data/README.rdoc CHANGED
@@ -70,11 +70,19 @@ Or pass page cofiguration in the block at page creation
70
70
 
71
71
  === ROADMAP
72
72
 
73
+ Towards version 0.0.3
74
+
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
80
+
73
81
  Towards version 0.0.2
74
82
 
75
- * make Watirloo agnostic to browser IE or Firefox or Safari
76
- * make tests run on IE, Firefox, Safari with the same interface
77
- * create radio_group to behave like select list and checkbox_group like multi select list
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
78
86
  * build UseCase class as template for scenario based execution of tests for exploratory testing
79
87
 
80
88
  == LICENSE:
data/Rakefile.rb CHANGED
@@ -8,8 +8,8 @@ $hoe = Hoe.new('watirloo', Watirloo::VERSION) do |p|
8
8
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
9
  p.rubyforge_name = p.name # TODO this is default value
10
10
  p.extra_deps = [
11
- ['watir','>= 1.6.2'],
12
- ]
11
+ ['watir', '>= 1.6.2'],
12
+ ]
13
13
  p.extra_dev_deps = [
14
14
  ['newgem', ">= #{::Newgem::VERSION}"],
15
15
  ['test/spec', '>=0.9.0']
@@ -18,7 +18,7 @@ $hoe = Hoe.new('watirloo', Watirloo::VERSION) do |p|
18
18
  p.testlib = ['test/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
- p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/, ''), 'rdoc')
22
22
  p.rsync_args = '-av --delete --ignore-errors'
23
23
  end
24
24
 
@@ -27,23 +27,31 @@ Dir['tasks/**/*.rake'].each { |t| load t }
27
27
 
28
28
  desc "run all tests on IE."
29
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
+
30
35
  # all tests use attach method to a browser that exit on the desktop
31
36
  # open new ie browser
32
37
  Watir::Browser.default = 'ie'
33
38
  Watir::Browser.new
34
39
  Watirloo::BrowserHerd.target = :ie
35
- tests = Dir["test/*_test.rb"]
36
- tests.each do |t|
37
- require t
40
+ chdir File.dirname(__FILE__) do
41
+ tests = Dir["test/*_test.rb"]
42
+ tests.each do |t|
43
+ require t
44
+ end
38
45
  end
46
+
39
47
  # at the end of test you will have one extra browser
40
48
  end
41
49
 
42
50
 
43
51
  desc "run all tests on Firefox (config per FireWatir gem)"
44
52
  task :test_ff do
45
- # all tests attach to an existing firefox browser
46
- # start browser with jssh option
53
+ # all tests attach to an existing firefox browser
54
+ # start browser with jssh option
47
55
  Watir::Browser.default='firefox'
48
56
  Watir::Browser.new
49
57
  tests = Dir["test/*_test.rb"]
data/lib/watirloo.rb CHANGED
@@ -1,57 +1,107 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  require 'watirloo/watir_ducktape'
5
5
  require 'watirloo/reflector'
6
6
 
7
7
  module Watirloo
8
8
 
9
- VERSION = '0.0.2' # Jan2009
9
+ VERSION = '0.0.3' # Jan2009
10
10
 
11
- # Generic Semantic Test Object
12
- module TestObject
13
- attr_accessor :id, :desc
14
-
15
- end
16
-
17
11
  # browser. we return IE or Firefox. Safari? Other Browser?
18
- class BrowserHerd
19
- include TestObject
12
+ class BrowserHerd
20
13
 
21
- @@target = :ie #default target
22
-
23
- def self.target=(indicator)
24
- @@target = indicator
25
- end
14
+ @@target = :ie
15
+ #targets = [:ie, :firefox]
26
16
 
27
- def self.target
28
- @@target
29
- end
17
+ class << self
18
+
19
+ def target=(indicator)
20
+ @@target = indicator
21
+ end
22
+
23
+ def target
24
+ @@target
25
+ end
30
26
 
31
- #provide browser
32
- def self.browser
33
- case @@target
34
- when :ie
35
- Watir::IE.attach :url, // #this attach is a crutch
36
- when :firefox
37
- require 'watirloo/firewatir_ducktape'
38
- # this is a cruch for quick work with pages.
39
- # in reality you want to create a browser and pass it as argument to initialize Page class
40
- FireWatir::Firefox.attach #this attach is a crutch
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
41
45
  end
42
46
  end
43
47
  end
44
48
 
45
- # Semantic Page Objects Container.
46
- # page objects are defined as faces of a Page.
47
- # Each face (aka Interface of a page) is accessed by page.facename or page.face(:facename) methods
48
- # Pages make Watir fun
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
49
57
  class Page
50
58
 
51
- include TestObject
52
- attr_accessor :b
53
- attr_reader :faces
54
-
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
+
55
105
  # by convention the Page just attaches to the first available browser.
56
106
  # the smart thing to do is to manage browsers existence on the desktop separately
57
107
  # and supply Page class with the instance of browser you want for your tests.
@@ -62,48 +112,54 @@ module Watirloo
62
112
  # page = Page.new # just let the page do lazy thing and attach itself to browser.
63
113
  # part of this page initialization is to provide a convenience while developing tests where
64
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
65
116
  def initialize(browser = Watirloo::BrowserHerd.browser , &blk)
66
117
  @b = browser
67
- @faces = {}
68
- instance_eval(&blk) if block_given? # allows the shortcut to do some work at page creation
118
+ create_interfaces
119
+ instance_eval(blk) if block_given? # allows the shortcut to do some work at page creation
69
120
  end
70
-
121
+
122
+
71
123
  # enter values on controls idenfied by keys on the page.
72
124
  # data map is a hash, key represents the page object,
73
125
  # value represents its value to be set, either text, array or boolean
74
126
  def spray(dataMap)
75
- dataMap.each_pair do |face_symbol, value|
76
- get_face(face_symbol).set value #make every element in the dom respond to set to set its value
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
77
129
  end
78
130
  end
131
+
132
+ # set values on the page given the interface keys
133
+ alias set spray
79
134
 
80
135
  # return Watir object given by its semantic face symbol name
81
- def get_face(face_symbol)
82
- if self.respond_to? face_symbol # if there is a defined wrapper method for page element provided
83
- return self.send(face_symbol)
84
- elsif @faces.member?(face_symbol) # pull element from @faces and send to browser
85
- method, *args = @faces[face_symbol] # return definition for face consumable by browser
86
- return @b.send(method, *args)
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
87
142
  else
88
- #??? I ran out of ideas
89
- raise ::Watir::Exception::WatirException, 'I ran out of ideas in Watirloo'
143
+ raise ::Watir::Exception::WatirException, 'Unknown Semantic Facename'
90
144
  end
91
145
  end
92
- alias face get_face
93
-
146
+
94
147
  # add face definition to page
95
- def add_face(definitions)
148
+ def interface(definitions)
96
149
  if definitions.kind_of?(Hash)
97
- @faces.update definitions
150
+ interfaces.update definitions
151
+ else
152
+ raise ::Watir::Exception::WatirException, "Wrong arguments for Page Object definition"
98
153
  end
99
154
  end
100
-
155
+ alias face interface
156
+
101
157
  # Delegate execution to browser if no method or face defined on page class
102
158
  def method_missing method, *args
103
- if @b.respond_to? method
104
- @b.send method, *args
105
- elsif @faces.member?(method.to_sym)
106
- get_face(method.to_sym)
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)
107
163
  else
108
164
  raise ::Watir::Exception::WatirException, 'I ran out of ideas in Watirloo'
109
165
  end
@@ -1,14 +1,29 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- class CheckboxGroupPage < Watirloo::Page
4
- # semantic wrapper for the radio group object
5
- def pets
6
- @b.checkbox_group('pets')
3
+ describe 'checkbox_group access for browser' do
4
+ before :each do
5
+ page = Watirloo::Page.new
6
+ @browser = page.browser
7
+ @browser.goto testfile('checkbox_group1.html')
8
+ end
9
+
10
+ it 'browser responds to checkbox_group' do
11
+ @browser.respond_to?(:checkbox_group).should == true
12
+ end
13
+
14
+ it 'returns group object and its values from the page' do
15
+ cbg = @browser.checkbox_group('pets')
16
+ cbg.size.should == 5
17
+ cbg.values.should == %w[cat dog zook zebra wumpa]
7
18
  end
8
19
  end
9
20
 
21
+ describe 'CheckboxGroup class access with page interface' do
10
22
 
11
- describe 'CheckboxGroup class' do
23
+ class CheckboxGroupPage < Watirloo::Page
24
+ # semantic wrapper for the radio group object
25
+ face :pets => [:checkbox_group, 'pets']
26
+ end
12
27
 
13
28
  before do
14
29
  @page = CheckboxGroupPage.new
@@ -4,8 +4,13 @@ describe 'setting and getting values for individual checkboxes with value attrib
4
4
 
5
5
  before do
6
6
  @page = Watirloo::Page.new
7
- @page.goto testfile('checkbox_group1.html')
8
- @page.add_face(
7
+ @page.browser.goto testfile('checkbox_group1.html')
8
+
9
+ # instance method page.face adds defintion but only to the current instance of the page
10
+ # in watir you have to access each checkbox.
11
+ # in Watirloo you can access CheckboxGroup as shortcut using
12
+ # :pets => [:checkbox_group, 'pets']
13
+ @page.face(
9
14
  :pets_cat => [:checkbox, :name, 'pets', 'cat'],
10
15
  :pets_dog => [:checkbox, :name, 'pets', 'dog'],
11
16
  :pets_zook => [:checkbox, :name, 'pets', 'zook'],
@@ -15,32 +20,31 @@ describe 'setting and getting values for individual checkboxes with value attrib
15
20
 
16
21
  it 'semantic name accesses individual CheckBox' do
17
22
  if @page.b.kind_of?(FireWatir::Firefox)
18
- @page.face(:pets_cat).kind_of?(FireWatir::CheckBox).should == true
23
+ @page.pets_cat.kind_of?(FireWatir::CheckBox).should == true
19
24
 
20
25
  elsif @page.b.kind_of?(Watir::IE)
21
- @page.face(:pets_cat).kind_of?(Watir::CheckBox).should == true
26
+ @page.pets_cat.kind_of?(Watir::CheckBox).should == true
22
27
  end
23
28
  end
24
29
 
25
30
  it 'set individual checkbox does not set other checkboxes sharing the same name' do
26
- @page.face(:pets_dog).checked?.should == false
27
- @page.face(:pets_dog).set
28
- @page.face(:pets_dog).checked?.should == true
29
- @page.face(:pets_cat).checked?.should == false
31
+ @page.pets_dog.checked?.should == false
32
+ @page.pets_dog.set
33
+ @page.pets_dog.checked?.should == true
34
+ @page.pets_cat.checked?.should == false
30
35
  end
31
36
 
32
37
  it 'by default all are false. set each unchecked checkbox should have checked? true' do
33
- @page.faces.keys.each do |key|
34
- @page.face(key).checked?.should == false
38
+ @page.interfaces.keys.each do |key|
39
+ @page.get_face(key).checked?.should == false
35
40
  end
36
41
 
37
- @page.faces.keys.each do |key|
38
- @page.face(key).set
42
+ @page.interfaces.keys.each do |key|
43
+ @page.get_face(key).set
39
44
  end
40
45
 
41
- @page.faces.keys.each do |key|
42
- @page.face(key).checked?.should.be true
46
+ @page.interfaces.keys.each do |key|
47
+ @page.get_face(key).checked?.should.be true
43
48
  end
44
49
  end
45
-
46
50
  end
@@ -1,7 +1,7 @@
1
1
  <!--
2
2
  Document : checbox_group
3
3
  -->
4
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4
+ <!DOCtype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5
5
  <html>
6
6
  <head>
7
7
  <title></title>
@@ -9,12 +9,12 @@
9
9
  </head>
10
10
  <body>
11
11
  <h3>Pets CheckboxGroup. Each has value. Acts like MultiSelectList. none, one ore more items can be checked.</h3>
12
- <INPUT NAME="pets" TYPE="CHECKBOX" VALUE="cat">cat<br />
13
- <INPUT NAME="pets" TYPE="CHECKBOX" VALUE="dog">dog<br />
14
- <INPUT NAME="pets" TYPE="CHECKBOX" VALUE="zook">zook<br />
15
- <INPUT NAME="pets" TYPE="CHECKBOX" VALUE="zebra">zebra<br />
16
- <INPUT NAME="pets" TYPE="CHECKBOX" VALUE="wumpa">wumpa<br />
12
+ <input name="pets" type="checkbox" value="cat">cat<br />
13
+ <input name="pets" type="checkbox" value="dog">dog<br />
14
+ <input name="pets" type="checkbox" value="zook">zook<br />
15
+ <input name="pets" type="checkbox" value="zebra">zebra<br />
16
+ <input name="pets" type="checkbox" value="wumpa">wumpa<br />
17
17
  <h3>Single CheckboxToggle Only. Acts like RadioGroup on/off switch.</h3>
18
- <INPUT NAME="singleIndicator" TYPE="checkbox">ToggleMe<br />
18
+ <input name="singleIndicator" type="checkbox">ToggleMe<br />
19
19
  </body>
20
20
  </html>
@@ -0,0 +1,79 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+
4
+ describe "SuperPage" do
5
+
6
+ class SuperPage < Watirloo::Page
7
+ face 'name' => 'vname'
8
+ end
9
+
10
+ it 'class interface' do
11
+ SuperPage.interfaces.keys.should == ['name']
12
+ end
13
+
14
+ it 'instance initialized from class interface' do
15
+ SuperPage.new.interfaces.keys.should == ['name']
16
+ end
17
+
18
+ it 'adding interface to instance adds interface to initialize' do
19
+ page = SuperPage.new
20
+ page.face 'sub' => 'sub' # add new face to instance
21
+ page.interfaces.keys.sort.should == %w[name sub] # instnace has now two
22
+ end
23
+
24
+ it 'but not to class' do
25
+ page = SuperPage.new
26
+ page.face 'sub' => 'sub'
27
+ page.interfaces.keys.sort.should == %w[name sub]
28
+ SuperPage.interfaces.keys.should == ['name'] # but the class has still only one
29
+ end
30
+
31
+ it 'class interface can be updated' do
32
+ SuperPage.interfaces.update 'update' => 'vupdate'
33
+ SuperPage.interfaces.keys.sort.should == %w[name update]
34
+ end
35
+
36
+ it 'instance gets interfaces from class but does not get them after updating class' do
37
+ page = SuperPage.new
38
+ page.interfaces.keys.sort.should == %w[name update] #previous example altered it
39
+ SuperPage.interfaces.update 'muddy' => 'vmuddy'
40
+ page.interfaces.keys.sort.should == %w[name update] #previous example altered it
41
+ end
42
+ end
43
+
44
+ describe "SuperPage and SubPage" do
45
+
46
+ class Page0 < Watirloo::Page
47
+ face 'higher' => 'vhigher'
48
+ end
49
+ class Page1 < Page0
50
+ face 'lower' => 'vlower'
51
+ end
52
+ class Page2 < Page1
53
+ face 'lowest' => 'vlowest'
54
+ end
55
+
56
+ it 'Subpage inherits from Super its interfaces' do
57
+ p1 = Page1.new
58
+ p1.interfaces.keys.sort.should == %w[higher lower]
59
+ end
60
+
61
+ it "Super retains its interfaces and is not affected by Subpages" do
62
+ p0 = Page0.new
63
+ p0.face 'supinst' => 'vsupinst'
64
+ p0.interfaces.keys.sort.should == %w[higher supinst]
65
+ Page0.interfaces.keys.sort.should == ['higher']
66
+
67
+ p1 = Page1.new
68
+ p1.face 'subinst' => 'vsubinst'
69
+ p1.interfaces.keys.sort.should == %w[higher lower subinst]
70
+ Page1.interfaces.keys.sort.should == %w[higher lower]
71
+
72
+ # extra checks
73
+ p0.interfaces.keys.sort.should == %w[higher supinst] #super not affected by Sub
74
+ Page0.interfaces.keys.sort.should == ['higher'] #not affected by P1.instance face
75
+ Page2.interfaces.keys.sort.should == %w[higher lower lowest]
76
+ end
77
+
78
+
79
+ end
data/test/label_test.rb CHANGED
@@ -3,8 +3,8 @@ describe 'label wrapping text field' do
3
3
 
4
4
  before do
5
5
  @page = Watirloo::Page.new
6
- @page.goto testfile('labels.html')
7
- @page.add_face(
6
+ @page.browser.goto testfile('labels.html')
7
+ @page.face(
8
8
  :first => [:text_field, :name, 'fn'],
9
9
  :last => [:text_field, :name, 'ln']
10
10
  )
@@ -47,7 +47,7 @@ describe 'label for text field' do
47
47
  before do
48
48
  @page = Watirloo::Page.new
49
49
  @page.goto testfile('labels.html')
50
- @page.add_face(
50
+ @page.face(
51
51
  :first => [:text_field, :id, 'first_nm'],
52
52
  :last => [:text_field, :id, 'last_nm'],
53
53
  :first_label => [:label, :for, 'first_nm'],
@@ -1,50 +1,51 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- # def wrappers with suggested semantic names for elements
3
+ # There are 3 ways of defining an interface
4
+ # 1. class level face hash definition
5
+ # 2 def semanticname wrapper created for element
6
+ # 3 or just delegate to the browsing with familiar watir api
4
7
  class Person < Watirloo::Page
5
-
8
+
9
+ # class level interfaces as definitions for Browser
10
+ face :first => [:text_field, :name, 'first_nm']
11
+ face :street => [:text_field, :name, 'addr1']
12
+
13
+ # def wrapper with suggested semantic name returns dom element
14
+ # these wrappers can provide specialized behavior on the page
6
15
  def last
7
16
  @b.text_field(:name, 'last_nm')
8
17
  end
9
18
 
10
- def first
11
- @b.text_field(:name, 'first_nm')
12
- end
13
-
14
19
  def dob
15
20
  @b.text_field(:name, 'dob')
16
21
  end
17
22
 
18
- def street
19
- @b.text_field(:name, 'addr1')
20
- end
21
-
22
- def gender
23
- @b.select_list(:name, 'sex_cd')
24
- end
25
-
26
23
  end
27
24
 
28
25
 
29
- describe "Person Page with def wrapper methods" do
26
+ describe "Person Page interfaces defined by def wrappers and class definitions" do
30
27
 
31
28
  before :each do
32
29
  @page = Person.new
33
- @page.b.goto testfile('person.html')
30
+ @page.browser.goto testfile('person.html')
34
31
  end
35
32
 
36
33
  it 'calling face when there is wrapper method' do
37
-
38
34
  @page.last.set 'Wonkatonka'
39
35
  @page.last.value.should == 'Wonkatonka'
40
- @page.face(:last).value.should == 'Wonkatonka'
41
-
42
- @page.face(:last).set 'Oompaloompa'
43
- @page.last.value.should == 'Oompaloompa'
44
-
45
36
  end
46
37
 
47
- it 'spray using methods wrappers for watir elements' do
38
+ it 'calling interface when there is definition and no method' do
39
+ @page.first.set 'Oompaloompa'
40
+ @page.first.value.should == 'Oompaloompa'
41
+ end
42
+
43
+ it 'delegating to browser when there is no definition' do
44
+ @page.select_list(:name, 'sex_cd').set 'F'
45
+ @page.select_list(:name, 'sex_cd').selected.should == 'F'
46
+ end
47
+
48
+ it 'spray method by convetion has keys correspondig to interface names for watir elements' do
48
49
  mapping = {:street => '13 Sad Enchiladas Lane', :dob => '02/03/1977'}
49
50
  @page.spray mapping
50
51
  @page.street.value.should == mapping[:street]
@@ -52,5 +53,3 @@ describe "Person Page with def wrapper methods" do
52
53
  end
53
54
 
54
55
  end
55
-
56
-
@@ -1,17 +1,32 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- class RadioGroupPage < Watirloo::Page
4
- # RadioGroup Class refers to collection of radios sharing the same name
5
- def meals_to_go
6
- @b.radio_group('food')
3
+ describe 'RadioGroup class access in watir browser' do
4
+ before :each do
5
+ @browser = Watirloo::Page.new.browser
6
+ @browser.goto testfile('radio_group.html')
7
+ end
8
+
9
+ it 'browser responds to radio_group' do
10
+ @browser.respond_to?(:radio_group).should == true
11
+ end
12
+
13
+ it 'finds radio group on the page' do
14
+ rg = @browser.radio_group('food')
15
+ rg.size.should == 3
16
+ rg.values.should == %w[hotdog burger tofu]
7
17
  end
8
18
  end
9
19
 
10
- describe 'RadioGroup class' do
20
+
21
+ describe 'RadioGroup class interface in watirloo' do
22
+
23
+ class RadioGroupPage < Watirloo::Page
24
+ face :meals_to_go => [:radio_group, 'food']
25
+ end
11
26
 
12
27
  before do
13
28
  @page = RadioGroupPage.new
14
- @page.b.goto testfile('radio_group.html')
29
+ @page.browser.goto testfile('radio_group.html')
15
30
  end
16
31
 
17
32
  it 'container radio_group method returns RadioGroup class' do
@@ -78,5 +93,5 @@ describe 'RadioGroup class' do
78
93
  @page.meals_to_go.set :yes
79
94
  end
80
95
  end
81
-
96
+
82
97
  end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ describe "select lists defining in class, instance and subclass" do
4
+
5
+ class SelectListPage < Watirloo::Page
6
+ face :pets => [:select_list, :name, 'animals']
7
+ end
8
+
9
+ before do
10
+ @page = SelectListPage.new
11
+ @page.face :gender => [:select_list, :name, 'sex_cd']
12
+ @page.browser.goto testfile('select_lists.html')
13
+ end
14
+
15
+ it 'face method with key parameter to construct SelectList per browser implementation' do
16
+ if @page.browser.kind_of?(FireWatir::Firefox)
17
+ @page.pets.kind_of?(FireWatir::SelectList).should == true
18
+ @page.gender.kind_of?(FireWatir::SelectList).should == true
19
+
20
+ elsif @page.browser.kind_of? Watir::IE
21
+ @page.pets.kind_of?(Watir::SelectList).should == true
22
+ @page.gender.kind_of?(Watir::SelectList).should == true
23
+ end
24
+ end
25
+
26
+ it 'face(:facename) and browser.select_list access the same control' do
27
+ @page.select_list(:name, 'sex_cd').values.should == @page.gender.values
28
+ @page.select_list(:name, 'animals').values.should == @page.pets.values
29
+ end
30
+
31
+ it 'subclassing the page and adding new interface gets previous ' do
32
+ class SelectListSub < SelectListPage
33
+ face :toys => [:select_list, :name, 'bubel']
34
+ end
35
+ page = SelectListSub.new
36
+ page.interfaces.keys.should == [:toys, :pets]
37
+ end
38
+
39
+ end
@@ -5,17 +5,12 @@ describe "SelectList options as visible items and values as hidden to the user a
5
5
  before do
6
6
  @page = Watirloo::Page.new
7
7
  @page.b.goto testfile('select_lists.html')
8
- @page.add_face(
8
+ @page.face(
9
9
  :pets => [:select_list, :name, 'animals'],
10
10
  :gender => [:select_list, :name, 'sex_cd'],
11
11
  :toys => [:select_list, :name, 'bubel'])
12
12
  end
13
13
 
14
- it 'values of options by face(:facename) method' do
15
- @page.face(:gender).values.should == ['', 'm', 'f']
16
- @page.face(:pets).values.should == ['o1', 'o2', 'o3', 'o4', 'o5']
17
- end
18
-
19
14
  it 'values of options by facename method' do
20
15
  @page.gender.values.should == ['', 'm', 'f']
21
16
  @page.pets.values.should == ['o1', 'o2', 'o3', 'o4', 'o5']
@@ -31,11 +26,11 @@ describe "SelectList options as visible items and values as hidden to the user a
31
26
  end
32
27
  end
33
28
 
34
- it 'options method returns visible contents as array of text items' do
29
+ it 'items method returns visible contents as array of text items' do
35
30
  @page.toys.items.should == ["", "foobel", "barbel", "bazbel", "chuchu"]
36
31
  end
37
32
 
38
- it 'options returns visible text items as array' do
33
+ it 'items returns visible text items as array' do
39
34
  @page.pets.items.should == ['cat', 'dog', 'zook', 'zebra', 'wumpa']
40
35
  @page.gender.items.should == ["", "M", "F"]
41
36
  end
@@ -6,7 +6,7 @@ describe "SelectList selections" do
6
6
  before do
7
7
  @page = Watirloo::Page.new
8
8
  @page.b.goto testfile('select_lists.html')
9
- @page.add_face(
9
+ @page.face(
10
10
  :pets => [:select_list, :name, 'animals'],
11
11
  :gender => [:select_list, :name, 'sex_cd'])
12
12
  end
@@ -7,23 +7,23 @@ describe "add faces text fields page objects" do
7
7
  @page.b.goto testfile('person.html')
8
8
  end
9
9
 
10
- it 'faces initially is an empty Hash' do
11
- @page.faces.should == {}
10
+ it 'interfaces initially is an empty Hash' do
11
+ @page.interfaces.should == {}
12
12
  end
13
13
 
14
- it 'add_face accepts keys as semantic faces and values as definitions to construct Watir Elements' do
15
- @page.add_face(
14
+ it 'instance method face accepts keys as semantic faces and values as definitions to construct Watir Elements' do
15
+ @page.face(
16
16
  :last => [:text_field, :name, 'last_nm'],
17
17
  :first => [:text_field, :name, 'first_nm'])
18
- @page.faces.size.should == 2
19
- #TODO TextField should be Watir and independent of Browser IE, FireFox or others.
20
- if @page.b.kind_of? FireWatir::Firefox
21
- @page.face(:first).kind_of?(FireWatir::TextField).should == true
22
- @page.face(:last).kind_of?(FireWatir::TextField).should == true
18
+ @page.interfaces.size.should == 2
19
+
20
+ if @page.browser.kind_of? FireWatir::Firefox
21
+ @page.first.kind_of?(FireWatir::TextField).should == true
22
+ @page.last.kind_of?(FireWatir::TextField).should == true
23
23
 
24
24
  elsif @page.b.kind_of? Watir::IE
25
- @page.face(:first).kind_of?(Watir::TextField).should == true
26
- @page.face(:last).kind_of?(Watir::TextField).should == true
25
+ @page.first.kind_of?(Watir::TextField).should == true
26
+ @page.last.kind_of?(Watir::TextField).should == true
27
27
  end
28
28
  end
29
29
  end
@@ -33,30 +33,17 @@ describe "text fields page objects setting and getting values" do
33
33
  before do
34
34
  @page = Watirloo::Page.new
35
35
  @page.goto testfile('person.html')
36
- @page.add_face(
36
+ @page.face(
37
37
  :last => [:text_field, :name, 'last_nm'],
38
38
  :first => [:text_field, :name, 'first_nm']
39
39
  )
40
40
  end
41
-
42
- it "face name keyword and value returns current text" do
43
- @page.face(:first).value.should == 'Joanney'
44
- @page.face(:last).value.should == 'Begoodnuffski'
45
- end
46
41
 
47
42
  it 'face name method and value returns current text' do
48
43
  @page.first.value.should == 'Joanney'
49
44
  @page.last.value.should == 'Begoodnuffski'
50
45
  end
51
46
 
52
- it "face name kewords and set enters value into field" do
53
- params = {:first => 'Grzegorz',:last => 'Brzeczyszczykiewicz'}
54
- @page.face(:first).set params[:first]
55
- @page.face(:last).set params[:last]
56
- @page.face(:first).value.should == params[:first]
57
- @page.face(:last).value.should == params[:last]
58
- end
59
-
60
47
  it "face name method and set enters value into field" do
61
48
  params = {:first => 'Grzegorz',:last => 'Brzeczyszczykiewicz'}
62
49
  @page.first.set params[:first]
@@ -65,10 +52,17 @@ describe "text fields page objects setting and getting values" do
65
52
  @page.last.value.should == params[:last]
66
53
  end
67
54
 
55
+ it 'spray method matches keys to semantic values and sets values' do
56
+ params = {:first => 'Grzegorz',:last => 'Brzeczyszczykiewicz'}
57
+ @page.spray params
58
+ @page.first.value.should == params[:first]
59
+ @page.last.value.should == params[:last]
60
+
61
+ end
68
62
  it 'spray values match semantic keys to faces and set their values' do
69
63
  @page.spray :first => 'Hermenegilda', :last => 'Kociubinska'
70
- @page.face(:first).value.should == 'Hermenegilda'
71
- @page.face(:last).value.should == 'Kociubinska'
64
+ @page.first.value.should == 'Hermenegilda'
65
+ @page.last.value.should == 'Kociubinska'
72
66
  end
73
67
  end
74
68
 
data/watirloo.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{watirloo}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["marekj"]
9
- s.date = %q{2009-01-07}
9
+ s.date = %q{2009-01-25}
10
10
  s.description = %q{Watir Framework and Helper based on Semantic Page Objects Modeling. Helps you design tests expressing DOM elements and groups of elements on the page as Semantic Page Objects rather than their DOM implementations. It is not a DSL but it helps you write human readable tests and hooks them up to Watir browsers for implementation Give it a try. You will like it.}
11
11
  s.email = ["marekj.com@gmail.com"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
13
- s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile.rb", "lib/watirloo", "lib/watirloo.rb", "lib/watirloo/firewatir_ducktape.rb", "lib/watirloo/reflector.rb", "lib/watirloo/watir_ducktape.rb", "script/console", "script/console.cmd", "script/destroy", "script/destroy.cmd", "script/generate", "script/generate.cmd", "script/reflect.rb", "test/checkbox_group_test.rb", "test/checkboxes_value_test.rb", "test/firewatir", "test/firewatir/attach_instance_test.rb", "test/html", "test/html/census.html", "test/html/checkbox_group1.html", "test/html/labels.html", "test/html/person.html", "test/html/radio_group.html", "test/html/select_lists.html", "test/label_test.rb", "test/person_def_wrappers_test.rb", "test/radio_group_test.rb", "test/select_list_as_face_test.rb", "test/select_list_options_test.rb", "test/select_lists_test.rb", "test/test_helper.rb", "test/text_fields_test.rb", "watirloo.gemspec"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile.rb", "lib/watirloo.rb", "lib/watirloo/firewatir_ducktape.rb", "lib/watirloo/reflector.rb", "lib/watirloo/watir_ducktape.rb", "script/console", "script/console.cmd", "script/destroy", "script/destroy.cmd", "script/generate", "script/generate.cmd", "script/reflect.rb", "test/checkbox_group_test.rb", "test/checkboxes_value_test.rb", "test/firewatir/attach_instance_test.rb", "test/html/census.html", "test/html/checkbox_group1.html", "test/html/labels.html", "test/html/person.html", "test/html/radio_group.html", "test/html/select_lists.html", "test/interfaces_test.rb", "test/label_test.rb", "test/person_def_wrappers_test.rb", "test/radio_group_test.rb", "test/select_list_in_class_test.rb", "test/select_list_options_test.rb", "test/select_lists_test.rb", "test/test_helper.rb", "test/text_fields_test.rb", "watirloo.gemspec"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://watirloo.testr.us}
16
16
  s.rdoc_options = ["--main", "README.rdoc"]
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.rubyforge_project = %q{watirloo}
19
19
  s.rubygems_version = %q{1.3.1}
20
20
  s.summary = %q{Watir Framework and Helper based on Semantic Page Objects Modeling}
21
- s.test_files = ["test/checkboxes_value_test.rb", "test/checkbox_group_test.rb", "test/label_test.rb", "test/person_def_wrappers_test.rb", "test/radio_group_test.rb", "test/select_lists_test.rb", "test/select_list_as_face_test.rb", "test/select_list_options_test.rb", "test/text_fields_test.rb"]
21
+ s.test_files = ["test/checkboxes_value_test.rb", "test/checkbox_group_test.rb", "test/interfaces_test.rb", "test/label_test.rb", "test/person_def_wrappers_test.rb", "test/radio_group_test.rb", "test/select_lists_test.rb", "test/select_list_in_class_test.rb", "test/select_list_options_test.rb", "test/text_fields_test.rb"]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marekj-watirloo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - marekj
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-07 00:00:00 -08:00
12
+ date: 2009-01-25 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -64,7 +64,6 @@ files:
64
64
  - Manifest.txt
65
65
  - README.rdoc
66
66
  - Rakefile.rb
67
- - lib/watirloo
68
67
  - lib/watirloo.rb
69
68
  - lib/watirloo/firewatir_ducktape.rb
70
69
  - lib/watirloo/reflector.rb
@@ -78,19 +77,18 @@ files:
78
77
  - script/reflect.rb
79
78
  - test/checkbox_group_test.rb
80
79
  - test/checkboxes_value_test.rb
81
- - test/firewatir
82
80
  - test/firewatir/attach_instance_test.rb
83
- - test/html
84
81
  - test/html/census.html
85
82
  - test/html/checkbox_group1.html
86
83
  - test/html/labels.html
87
84
  - test/html/person.html
88
85
  - test/html/radio_group.html
89
86
  - test/html/select_lists.html
87
+ - test/interfaces_test.rb
90
88
  - test/label_test.rb
91
89
  - test/person_def_wrappers_test.rb
92
90
  - test/radio_group_test.rb
93
- - test/select_list_as_face_test.rb
91
+ - test/select_list_in_class_test.rb
94
92
  - test/select_list_options_test.rb
95
93
  - test/select_lists_test.rb
96
94
  - test/test_helper.rb
@@ -126,10 +124,11 @@ summary: Watir Framework and Helper based on Semantic Page Objects Modeling
126
124
  test_files:
127
125
  - test/checkboxes_value_test.rb
128
126
  - test/checkbox_group_test.rb
127
+ - test/interfaces_test.rb
129
128
  - test/label_test.rb
130
129
  - test/person_def_wrappers_test.rb
131
130
  - test/radio_group_test.rb
132
131
  - test/select_lists_test.rb
133
- - test/select_list_as_face_test.rb
132
+ - test/select_list_in_class_test.rb
134
133
  - test/select_list_options_test.rb
135
134
  - test/text_fields_test.rb
@@ -1,46 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- describe "select list as semantic face object on a page" do
4
-
5
- before do
6
- @page = Watirloo::Page.new
7
- @page.b.goto testfile('select_lists.html')
8
- @page.add_face(
9
- :pets => [:select_list, :name, 'animals'],
10
- :gender => [:select_list, :name, 'sex_cd'])
11
- end
12
-
13
- it 'face method with key parameter to construct SelectList per browser implementation' do
14
- if @page.b.kind_of?(FireWatir::Firefox)
15
- @page.face(:pets).kind_of?(FireWatir::SelectList).should == true
16
- @page.face(:gender).kind_of?(FireWatir::SelectList).should == true
17
-
18
- elsif @page.b.kind_of? Watir::IE
19
- @page.face(:pets).kind_of?(Watir::SelectList).should == true
20
- @page.face(:gender).kind_of?(Watir::SelectList).should == true
21
- end
22
- end
23
-
24
- it 'face(:facename) and browser.select_list access the same control' do
25
- @page.b.select_list(:name, 'sex_cd').values.should == @page.gender.values
26
- @page.b.select_list(:name, 'animals').values.should == @page.pets.values
27
- end
28
-
29
-
30
- it 'face(:facename) and facename access the same control' do
31
- @page.face(:gender).items.should == @page.gender.items
32
- @page.face(:pets).items.should == @page.pets.items
33
- end
34
-
35
- it 'facename method matching modeling semantic object accessor' do
36
- if @page.b.kind_of?(FireWatir::Firefox)
37
- @page.pets.kind_of?(FireWatir::SelectList).should == true
38
- @page.gender.kind_of?(FireWatir::SelectList).should == true
39
-
40
- elsif @page.b.kind_of?(Watir::IE)
41
- @page.pets.kind_of?(Watir::SelectList).should == true
42
- @page.gender.kind_of?(Watir::SelectList).should == true
43
- end
44
-
45
- end
46
- end