spectest 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/HISTORY.md +12 -0
  2. data/lib/spectest.rb +18 -2
  3. data/lib/spectest/enclosers.rb +19 -0
  4. data/lib/spectest/generators.rb +1 -0
  5. data/lib/spectest/platform_selenium/platform_object.rb +37 -12
  6. data/lib/spectest/platform_selenium/web_objects/all.rb +17 -0
  7. data/lib/spectest/platform_selenium/web_objects/button.rb +13 -0
  8. data/lib/spectest/platform_selenium/web_objects/link.rb +13 -0
  9. data/lib/spectest/platform_selenium/web_objects/text_field.rb +14 -0
  10. data/lib/spectest/platform_watir/platform_object.rb +54 -20
  11. data/lib/spectest/platform_watir/web_objects/all.rb +17 -0
  12. data/lib/spectest/platform_watir/web_objects/text_field.rb +13 -0
  13. data/lib/spectest/version.rb +1 -1
  14. data/lib/spectest/web_objects/all.rb +26 -3
  15. data/lib/spectest/web_objects/button.rb +17 -4
  16. data/lib/spectest/web_objects/link.rb +17 -3
  17. data/lib/spectest/web_objects/text_field.rb +22 -4
  18. data/spec/web_objects/all_spec.rb +5 -0
  19. data/spec/web_objects/button_spec.rb +35 -0
  20. data/spec/web_objects/link_spec.rb +46 -0
  21. data/spec/web_objects/text_field_spec.rb +46 -0
  22. data/spec/webobject_selenium_spec.rb +31 -0
  23. data/spec/webobject_watir_spec.rb +31 -0
  24. data/specs/app/test_static.html +3 -3
  25. data/specs/pages/iframe_examples_page.rb +13 -0
  26. data/specs/pages/landing_page.rb +1 -0
  27. data/specs/steps/button_steps.rb +4 -0
  28. data/specs/steps/link_steps.rb +14 -0
  29. data/specs/steps/object_steps.rb +9 -1
  30. data/specs/steps/page_steps.rb +20 -0
  31. data/specs/steps/text_field_steps.rb +5 -0
  32. data/specs/tests/iframes.feature +20 -0
  33. data/specs/tests/link.feature +14 -0
  34. metadata +27 -12
data/HISTORY.md CHANGED
@@ -1,6 +1,18 @@
1
1
  Change Log and History
2
2
  ======================
3
3
 
4
+ ## Version 0.0.4 / 2011-11-15
5
+
6
+ This updated added the ability to support frames and iframes. This functionality still has to be vetted. This update also extended the web objects mechanism to be platform specific so that each platform can perform certain checks or queries on web objects.
7
+
8
+ * Web Objects Supported:
9
+ * Frames
10
+ * iFrames
11
+
12
+ * Web Object Queries Supported:
13
+ * Check if visible
14
+ * Check if exists
15
+
4
16
 
5
17
  ## Version 0.0.3 / 2011-11-14
6
18
 
@@ -3,6 +3,7 @@ require "spectest/logger"
3
3
  require "spectest/matchers"
4
4
  require "spectest/platforms"
5
5
  require "spectest/generators"
6
+ require "spectest/enclosers"
6
7
 
7
8
  module SpecTest
8
9
  include Matchers
@@ -17,10 +18,11 @@ module SpecTest
17
18
  end
18
19
 
19
20
  # This makes sure that any page classes that include SpecTest will be
20
- # given access to the generator methods based on web objects that are
21
- # declared in the page class.
21
+ # given access to the generator and encloser methods based on web
22
+ # objects that are declared in the page class.
22
23
  def self.included(caller)
23
24
  caller.extend SpecTest::Generators
25
+ caller.extend SpecTest::Enclosers
24
26
  end
25
27
 
26
28
  def initialize(browser, visit=nil)
@@ -51,6 +53,20 @@ module SpecTest
51
53
  @platform.text
52
54
  end
53
55
 
56
+ # Used to identify a web object as existing within an enclosing object
57
+ # like a frame or an iframe. There is a duplicate method in enclosers.rb.
58
+ # This method needs to be here so that test steps can be placed in an
59
+ # enclosed context.
60
+ #
61
+ # @param [String] identifier how an encloser will be referred to
62
+ # @param encloser a parent encloser that is passed from a previous call
63
+ # @param [optional] block that contains calls to web objects within the encloser
64
+ def is_enclosed_by(identifier, encloser=nil, &block)
65
+ encloser = [] if encloser.nil?
66
+ encloser << identifier
67
+ block.call(encloser)
68
+ end
69
+
54
70
  private
55
71
 
56
72
  def establish_platform_driver_for(browser)
@@ -0,0 +1,19 @@
1
+ module SpecTest
2
+ module Enclosers
3
+
4
+ # Used to identify a web object as existing within an enclosing object
5
+ # like a frame or an iframe. There is a duplicate method in spectest.rb.
6
+ # This method needs to be here so that page objects can declare web
7
+ # objects to be in an enclosed context.
8
+ #
9
+ # @param [String] identifier how an encloser will be referred to
10
+ # @param encloser a parent encloser that is passed from a previous call
11
+ # @param [optional] block that contains calls to web objects within the encloser
12
+ def is_enclosed_by(identifier, encloser=nil, &block)
13
+ encloser = [] if encloser.nil?
14
+ encloser << identifier
15
+ block.call(encloser)
16
+ end
17
+
18
+ end
19
+ end
@@ -74,5 +74,6 @@ module SpecTest
74
74
 
75
75
  alias_method "#{identifier}_button".to_sym, "#{identifier}_object".to_sym
76
76
  end
77
+
77
78
  end
78
79
  end
@@ -29,65 +29,80 @@ module SpecTest
29
29
  # Link objects are of type: SpecTest::WebObjects::Link
30
30
  # See SpecTest::Generators#link
31
31
  def get_link_for(locator)
32
- key, value = get_platform_locator_for(locator, WebObjects::Link, 'a')
32
+ key, value, enclosers = get_platform_locator_for(locator, WebObjects::Link, 'a')
33
+ switch_to_encloser(enclosers)
33
34
  web_object = @browser.find_element(key, value)
35
+ @browser.switch_to.default_content unless enclosers.nil?
34
36
  WebObjects::Link.new(web_object, :platform => :selenium_webdriver)
35
37
  end
36
38
 
37
39
  # Platform method to click a link object.
38
40
  # See SpecTest::Generators#link
39
41
  def click_link_for(locator)
40
- key, value = get_platform_locator_for(locator, WebObjects::Link, 'a')
42
+ key, value, enclosers = get_platform_locator_for(locator, WebObjects::Link, 'a')
43
+ switch_to_encloser(enclosers)
41
44
  @browser.find_element(key, value).click
45
+ @browser.switch_to.default_content unless enclosers.nil?
42
46
  end
43
47
 
44
48
  # Platform method to return a text field object.
45
49
  # Text field objects are of type: SpecTest::WebObjects::TextField
46
50
  # See SpecTest::Generators#text_field
47
51
  def get_text_field_for(locator)
48
- key, value = get_platform_locator_for(locator, WebObjects::TextField, 'input', :type => 'text')
52
+ key, value, enclosers = get_platform_locator_for(locator, WebObjects::TextField, 'input', :type => 'text')
53
+ switch_to_encloser(enclosers)
49
54
  web_object = @browser.find_element(key, value)
55
+ @browser.switch_to.default_content unless enclosers.nil?
50
56
  WebObjects::TextField.new(web_object, :platform => :selenium_webdriver)
51
57
  end
52
58
 
53
59
  # Platform method to get the value in a text field object.
54
60
  # See SpecTest::Generators#text_field
55
61
  def get_text_field_value_for(locator)
56
- key, value = get_platform_locator_for(locator, WebObjects::TextField, 'input', :type => 'text')
62
+ key, value, enclosers = get_platform_locator_for(locator, WebObjects::TextField, 'input', :type => 'text')
63
+ switch_to_encloser(enclosers)
57
64
  value = @browser.find_element(key, value).attribute('value')
65
+ @browser.switch_to.default_content unless enclosers.nil?
58
66
  value
59
67
  end
60
68
 
61
69
  # Platform method to set a value in a text field object.
62
70
  # See SpecTest::Generators#text_field
63
71
  def set_text_field_value_for(locator, text)
64
- key, value = get_platform_locator_for(locator, WebObjects::TextField, 'input', :type => 'text')
72
+ key, value, enclosers = get_platform_locator_for(locator, WebObjects::TextField, 'input', :type => 'text')
73
+ switch_to_encloser(enclosers)
65
74
  @browser.find_element(key, value).clear
66
75
  @browser.find_element(key, value).send_keys(text)
76
+ @browser.switch_to.default_content unless enclosers.nil?
67
77
  end
68
78
 
69
79
  # Platform method to return a button object.
70
80
  # Button objects are of type: SpecTest::WebObjects::Button
71
81
  # See SpecTest::Generators#button
72
82
  def get_button_for(locator)
73
- key, value = get_platform_locator_for(locator, WebObjects::Button, 'input', :type => 'submit')
83
+ key, value, enclosers = get_platform_locator_for(locator, WebObjects::Button, 'input', :type => 'submit')
84
+ switch_to_encloser(enclosers)
74
85
  web_object = @browser.find_element(key, value)
86
+ @browser.switch_to.default_content unless enclosers.nil?
75
87
  WebObjects::Button.new(web_object, :platform => :selenium_webdriver)
76
88
  end
77
89
 
78
90
  # Platform method to click a button object.
79
91
  # See SpecTest::Generators#button
80
92
  def click_button_for(locator)
81
- key, value = get_platform_locator_for(locator, WebObjects::Button, 'input', :type => 'submit')
93
+ key, value, enclosers = get_platform_locator_for(locator, WebObjects::Button, 'input', :type => 'submit')
94
+ switch_to_encloser(enclosers)
82
95
  @browser.find_element(key, value).click
96
+ @browser.switch_to.default_content unless enclosers.nil?
83
97
  end
84
98
 
85
99
  protected
86
100
 
87
101
  def get_platform_locator_for(locator, web_object, tag=nil, qualifier=nil)
102
+ enclosers = locator.delete(:frame)
88
103
  locator = qualify_with_tagname_for locator, tag, qualifier if tag
89
104
  key, value = web_object.have_selenium_find_object_with locator
90
- return key, value
105
+ return key, value, enclosers
91
106
  end
92
107
 
93
108
  def qualify_with_tagname_for(locator, tag, qualifier=nil)
@@ -110,9 +125,19 @@ module SpecTest
110
125
  return false if locator[:value] and tag == 'input' and qualifier[:type] == 'radio'
111
126
  true
112
127
  end
113
- end
114
- end
115
- end
116
- end
128
+
129
+ def switch_to_encloser(enclosers)
130
+ unless enclosers.nil?
131
+ enclosers.each do |encloser_locator|
132
+ value = encloser_locator.values.first
133
+ @browser.switch_to.frame(value)
134
+ end
135
+ end
136
+ end
137
+
138
+ end # class PlatformObject
139
+ end # module SeleniumWebDriver
140
+ end # module Platforms
141
+ end # module SpecTest
117
142
 
118
143
  Dir["#{File.dirname(__FILE__)}/../web_objects/**/*.rb"].each { |file| require file }
@@ -0,0 +1,17 @@
1
+ module SpecTest
2
+ module Platforms
3
+ module SeleniumWebDriver
4
+ module WebObject
5
+
6
+ def visible?
7
+ @web_object.displayed?
8
+ end
9
+
10
+ def exists?
11
+ nil != @web_object
12
+ end
13
+
14
+ end # module WebObject
15
+ end # module SeleniumWebDriver
16
+ end # module Platforms
17
+ end # module SpecTest
@@ -0,0 +1,13 @@
1
+ module SpecTest
2
+ module Platforms
3
+ module SeleniumWebDriver
4
+ module Button
5
+
6
+ def text
7
+ raise "Returning text from a button element in Selenium is not possible."
8
+ end
9
+
10
+ end # module Button
11
+ end # module SeleniumWebDriver
12
+ end # module Platforms
13
+ end # module SpecTest
@@ -0,0 +1,13 @@
1
+ module SpecTest
2
+ module Platforms
3
+ module SeleniumWebDriver
4
+ module Link
5
+
6
+ def value
7
+ raise "Returning value from a link element in Selenium is not possible."
8
+ end
9
+
10
+ end # module Link
11
+ end # module SeleniumWebDriver
12
+ end # module Platforms
13
+ end # module SpecTest
@@ -0,0 +1,14 @@
1
+ module SpecTest
2
+ module Platforms
3
+ module SeleniumWebDriver
4
+ module TextField
5
+
6
+ def value=(this)
7
+ @web_object.clear
8
+ @web_object.send_keys(this)
9
+ end
10
+
11
+ end # module TextField
12
+ end # module SeleniumWebDriver
13
+ end # module Platforms
14
+ end # module SpecTest
@@ -31,64 +31,74 @@ module SpecTest
31
31
  # Link objects are of type: SpecTest::WebObjects::Link
32
32
  # See SpecTest::Generators#link
33
33
  def get_link_for(locator)
34
- locator = get_platform_locator_for(locator, WebObjects::Link)
35
- web_object = @browser.instance_eval "link(locator)"
34
+ locator, enclosers = get_platform_locator_for(locator, WebObjects::Link)
35
+ web_object = @browser.instance_eval "#{nested_by(enclosers)}link(locator)"
36
+ switch_to_default(enclosers)
36
37
  WebObjects::Link.new(web_object, :platform => :watir_webdriver)
37
38
  end
38
39
 
39
40
  # Platform method to click a link object.
40
41
  # See SpecTest::Generators#link
41
42
  def click_link_for(locator)
42
- locator = get_platform_locator_for(locator, WebObjects::Link)
43
- @browser.instance_eval "link(locator).click if locator"
43
+ locator, enclosers = get_platform_locator_for(locator, WebObjects::Link)
44
+ @browser.instance_eval "#{nested_by(enclosers)}link(locator).click if locator"
45
+ switch_to_default(enclosers)
44
46
  end
45
47
 
46
48
  # Platform method to return a text field object.
47
49
  # Text field objects are of type: SpecTest::WebObjects::TextField
48
50
  # See SpecTest::Generators#text_field
49
51
  def get_text_field_for(locator)
50
- identifier = get_platform_locator_for(locator, WebObjects::TextField)
51
- web_object = @browser.instance_eval "text_field(locator)"
52
+ identifier, enclosers = get_platform_locator_for(locator, WebObjects::TextField)
53
+ web_object = @browser.instance_eval "#{nested_by(enclosers)}text_field(locator)"
54
+ switch_to_default(enclosers)
52
55
  WebObjects::TextField.new(web_object, :platform => :watir_webdriver)
53
56
  end
54
57
 
55
58
  # Platform method to get the value in a text field object.
56
59
  # See SpecTest::Generators#text_field
57
60
  def get_text_field_value_for(locator)
58
- identifier = get_platform_locator_for(locator, WebObjects::TextField)
59
- value = @browser.instance_eval "text_field(locator).value"
61
+ identifier, enclosers = get_platform_locator_for(locator, WebObjects::TextField)
62
+ value = @browser.instance_eval "#{nested_by(enclosers)}text_field(locator).value"
63
+ switch_to_default(enclosers)
60
64
  value
61
65
  end
62
66
 
63
67
  # Platform method to set a value in a text field object.
64
68
  # See SpecTest::Generators#text_field
65
69
  def set_text_field_value_for(locator, text)
66
- identifier = get_platform_locator_for(locator, WebObjects::TextField)
67
- @browser.instance_eval "text_field(locator).set(text)"
70
+ identifier, enclosers = get_platform_locator_for(locator, WebObjects::TextField)
71
+ SpecTest::trace("set_text_field_value_for: #{identifier}, #{enclosers}")
72
+ @browser.instance_eval "#{nested_by(enclosers)}text_field(locator).set(text)"
73
+ switch_to_default(enclosers)
68
74
  end
69
75
 
70
76
  # Platform method to return a button object.
71
77
  # Button objects are of type: SpecTest::WebObjects::Button
72
78
  # See SpecTest::Generators#button
73
79
  def get_button_for(locator)
74
- identifier = get_platform_locator_for(locator, WebObjects::Button)
75
- web_object = @browser.instance_eval "button(locator)"
80
+ identifier, enclosers = get_platform_locator_for(locator, WebObjects::Button)
81
+ web_object = @browser.instance_eval "#{nested_by(enclosers)}button(locator)"
82
+ switch_to_default(enclosers)
76
83
  WebObjects::Button.new(web_object, :platform => :watir_webdriver)
77
84
  end
78
85
 
79
86
  # Platform method to click a button object.
80
87
  # See SpecTest::Generators#button
81
88
  def click_button_for(locator)
82
- identifier = get_platform_locator_for(locator, WebObjects::Button)
83
- @browser.instance_eval "button(locator).click"
89
+ identifier, enclosers = get_platform_locator_for(locator, WebObjects::Button)
90
+ @browser.instance_eval "#{nested_by(enclosers)}button(locator).click"
91
+ switch_to_default(enclosers)
84
92
  end
85
93
 
86
94
  protected
87
95
 
88
96
  def get_platform_locator_for(locator, web_object, tag=nil)
97
+ enclosers = locator.delete(:frame)
98
+ SpecTest::trace("get_platform_locator_for (enclosers): #{enclosers}")
89
99
  locator = qualify_with_tagname_for locator, tag if tag
90
100
  locator = web_object.have_watir_find_object_with locator
91
- return locator
101
+ return locator, enclosers
92
102
  end
93
103
 
94
104
  def qualify_with_tagname_for(locator, tag)
@@ -96,9 +106,33 @@ module SpecTest
96
106
  locator[:tag_name] = tag if locator[:name]
97
107
  locator
98
108
  end
99
- end
100
- end
101
- end
102
- end
103
109
 
104
- Dir["#{File.dirname(__FILE__)}/../web_objects/**/*.rb"].each { |file| require file }
110
+ def nested_by(enclosers)
111
+ return if enclosers.nil?
112
+
113
+ encloser_locator = ''
114
+
115
+ enclosers.each do |id|
116
+ value = id.values.first
117
+ encloser_locator += "frame(:#{id.keys.first} => #{value})." if value.to_s.is_integer?
118
+ encloser_locator += "frame(:#{id.keys.first} => '#{value}')." unless value.to_s.is_integer?
119
+ end
120
+ encloser_locator
121
+ end
122
+
123
+ def switch_to_default(enclosers)
124
+ @browser.wd.switch_to.default_content unless enclosers.nil?
125
+ end
126
+
127
+ end # class PlatformObject
128
+ end # module WatirWebDriver
129
+ end # module Platforms
130
+ end # module SpecTest
131
+
132
+ Dir["#{File.dirname(__FILE__)}/../web_objects/**/*.rb"].each { |file| require file }
133
+
134
+ class String
135
+ def is_integer?
136
+ true if Integer(self) rescue false
137
+ end
138
+ end
@@ -0,0 +1,17 @@
1
+ module SpecTest
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module WebObject
5
+
6
+ def visible?
7
+ @web_object.present?
8
+ end
9
+
10
+ def exists?
11
+ @web_object.exists?
12
+ end
13
+
14
+ end # module WebObject
15
+ end # module WatirWebDriver
16
+ end # module Platforms
17
+ end # module SpecTest
@@ -0,0 +1,13 @@
1
+ module SpecTest
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module TextField
5
+
6
+ def value=(this)
7
+ @web_object.set(this)
8
+ end
9
+
10
+ end # module TextField
11
+ end # module WatirWebDriver
12
+ end # module Platforms
13
+ end # module SpecTest
@@ -1,3 +1,3 @@
1
1
  module SpecTest
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,6 +1,12 @@
1
1
  module SpecTest
2
2
  module WebObjects
3
3
  class WebObject
4
+
5
+ def initialize(web_object, platform)
6
+ @web_object = web_object
7
+ mixin_web_objects_for platform
8
+ end
9
+
4
10
  def self.have_watir_find_object_with(locator)
5
11
  locator_list = {}
6
12
 
@@ -48,6 +54,23 @@ module SpecTest
48
54
  def self.mappings_for_selenium
49
55
  {}
50
56
  end
51
- end
52
- end
53
- end
57
+
58
+ def mixin_web_objects_for(platform)
59
+ if platform[:platform] == :watir_webdriver
60
+ require "spectest/platform_watir/web_objects/all"
61
+ require "spectest/platform_watir/platform_object"
62
+ self.class.send :include, SpecTest::Platforms::WatirWebDriver::WebObject
63
+ @platform = SpecTest::Platforms::WatirWebDriver::PlatformObject.new(@web_object)
64
+ elsif platform[:platform] == :selenium_webdriver
65
+ require "spectest/platform_selenium/web_objects/all"
66
+ require "spectest/platform_selenium/platform_object"
67
+ self.class.send :include, SpecTest::Platforms::SeleniumWebDriver::WebObject
68
+ @platform = SpecTest::Platforms::SeleniumWebDriver::PlatformObject.new(@web_object)
69
+ else
70
+ raise ArgumentError, "Unable to mixin web objects for the specified platform."
71
+ end
72
+ end
73
+
74
+ end # class WebObject
75
+ end # module WebObjects
76
+ end # module SpecTest
@@ -2,6 +2,11 @@ module SpecTest
2
2
  module WebObjects
3
3
  class Button < WebObject
4
4
 
5
+ def initialize(web_object, platform)
6
+ @web_object = web_object
7
+ mixin_web_objects_for platform
8
+ end
9
+
5
10
  protected
6
11
 
7
12
  def self.locators_for_watir
@@ -11,7 +16,15 @@ module SpecTest
11
16
  def self.locators_for_selenium
12
17
  super + [:value]
13
18
  end
14
-
15
- end
16
- end
17
- end
19
+
20
+ def mixin_web_objects_for(platform)
21
+ super
22
+ if platform[:platform] == :selenium_webdriver
23
+ require "spectest/platform_selenium/web_objects/button"
24
+ self.class.send :include, SpecTest::Platforms::SeleniumWebDriver::Button
25
+ end
26
+ end
27
+
28
+ end # class Button
29
+ end # module WebObjects
30
+ end # module SpecTest
@@ -2,6 +2,11 @@ module SpecTest
2
2
  module WebObjects
3
3
  class Link < WebObject
4
4
 
5
+ def initialize(web_object, platform)
6
+ @web_object = web_object
7
+ mixin_web_objects_for platform
8
+ end
9
+
5
10
  protected
6
11
 
7
12
  def self.locators_for_watir
@@ -19,6 +24,15 @@ module SpecTest
19
24
  def self.mappings_for_selenium
20
25
  super.merge(:text => :link_text)
21
26
  end
22
- end
23
- end
24
- end
27
+
28
+ def mixin_web_objects_for(platform)
29
+ super
30
+ if platform[:platform] == :selenium_webdriver
31
+ require "spectest/platform_selenium/web_objects/link"
32
+ self.class.send :include, SpecTest::Platforms::SeleniumWebDriver::Link
33
+ end
34
+ end
35
+
36
+ end # class Link
37
+ end # module WebObjects
38
+ end # module SpecTest
@@ -2,6 +2,11 @@ module SpecTest
2
2
  module WebObjects
3
3
  class TextField < WebObject
4
4
 
5
+ def initialize(web_object, platform)
6
+ @web_object = web_object
7
+ mixin_web_objects_for platform
8
+ end
9
+
5
10
  protected
6
11
 
7
12
  def self.locators_for_watir
@@ -19,7 +24,20 @@ module SpecTest
19
24
  def self.mappings_for_selenium
20
25
  super.merge({:tag_name => :css})
21
26
  end
22
-
23
- end
24
- end
25
- end
27
+
28
+ def mixin_web_objects_for(platform)
29
+ super
30
+ if platform[:platform] == :watir_webdriver
31
+ require "spectest/platform_watir/web_objects/text_field"
32
+ self.class.send :include, SpecTest::Platforms::WatirWebDriver::TextField
33
+ elsif platform[:platform] == :selenium_webdriver
34
+ require "spectest/platform_selenium/web_objects/text_field"
35
+ self.class.send :include, SpecTest::Platforms::SeleniumWebDriver::TextField
36
+ else
37
+ raise ArgumentError, "Unable to mixin web objects for the specified platform."
38
+ end
39
+ end
40
+
41
+ end # class TextField
42
+ end # module WebObjects
43
+ end # module SpecTest
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+ require "spectest/web_objects/all"
3
+
4
+ #describe "there are common methods for all web objects" do
5
+ #end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+ require "spectest/web_objects/all"
3
+ require "spectest/web_objects/button"
4
+
5
+ describe SpecTest::WebObjects::Button do
6
+ let(:button) { SpecTest::WebObjects::Button }
7
+
8
+ describe "when mapping how to identify a web object" do
9
+ it "it should be able to map watir locators" do
10
+ [:class, :id, :index, :name, :value, :xpath].each do |type|
11
+ locator = button.have_watir_find_object_with type => 'value'
12
+ locator.keys.first.should == type
13
+ end
14
+ end
15
+
16
+ it "it should be able to map selenium locators" do
17
+ [:class, :id, :index, :name, :value, :xpath].each do |type|
18
+ key, value = button.have_selenium_find_object_with type => 'value'
19
+ key.should == type
20
+ end
21
+ end
22
+ end
23
+
24
+ describe "when performing an action on a web object" do
25
+ let(:button_object) { double('button_object') }
26
+
27
+ context "and when selenium is the driver" do
28
+ it "then it should return an error when asked for text" do
29
+ button = SpecTest::WebObjects::Button.new(button_object, :platform => :selenium_webdriver)
30
+ lambda { button.text }.should raise_error
31
+ end
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require "spectest/web_objects/all"
3
+ require "spectest/web_objects/link"
4
+
5
+ describe SpecTest::WebObjects::Link do
6
+ let(:link) { SpecTest::WebObjects::Link }
7
+
8
+ describe "when mapping how to identify a web object" do
9
+ it "it should be able to map watir locators" do
10
+ [:class, :href, :id, :index, :name, :text, :xpath].each do |type|
11
+ locator = link.have_watir_find_object_with type => 'value'
12
+ locator.keys.first.should == type
13
+ end
14
+ end
15
+
16
+ it "it should be able to map selenium locators" do
17
+ [:class, :id, :link, :link_text, :name, :xpath, :index].each do |type|
18
+ key, value = link.have_selenium_find_object_with type => 'value'
19
+ key.should == type
20
+ end
21
+ end
22
+
23
+ it "it should be able to map watir selectors to selenium locators" do
24
+ key, value = link.have_selenium_find_object_with :text => 'value'
25
+ key.should == :link_text
26
+ end
27
+
28
+ it "it should be able to map selenium selectors to watir locators" do
29
+ [:link, :link_text].each do |type|
30
+ locator = link.have_watir_find_object_with type => 'value'
31
+ locator.keys.first.should == :text
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "when performing an action on a web object" do
37
+ let(:link_object) { double('link_object') }
38
+
39
+ context "and when selenium is the driver" do
40
+ it "then it should return an error when asked for a value" do
41
+ link = SpecTest::WebObjects::Link.new(link_object, :platform => :selenium_webdriver)
42
+ lambda { link.value }.should raise_error
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+ require "spectest/web_objects/all"
3
+ require "spectest/web_objects/text_field"
4
+
5
+ describe SpecTest::WebObjects::TextField do
6
+ let(:textfield) { SpecTest::WebObjects::TextField }
7
+
8
+ describe "when mapping how to identify a web object" do
9
+ it "it should be able to map watir locators" do
10
+ [:class, :id, :index, :name, :tag_name, :xpath].each do |type|
11
+ locator = textfield.have_watir_find_object_with type => 'value'
12
+ locator.keys.first.should == type
13
+ end
14
+ end
15
+
16
+ it "it should be able to map selenium locators" do
17
+ [:class, :css, :id, :name, :xpath, :index].each do |type|
18
+ key, value = textfield.have_selenium_find_object_with type => 'value'
19
+ key.should == type
20
+ end
21
+ end
22
+
23
+ it "it should be able to map watir selectors to selenium locators" do
24
+ key, value = textfield.have_selenium_find_object_with :tag_name => 'value'
25
+ key.should == :css
26
+ end
27
+
28
+ it "it should be able to map selenium selectors to watir locators" do
29
+ locator = textfield.have_watir_find_object_with :css => 'value'
30
+ locator.keys.first.should == :tag_name
31
+ end
32
+ end
33
+
34
+ describe "when performing an action on a web object" do
35
+ context "and when selenium is the driver" do
36
+ it "it should be able to set the value of the object" do
37
+ text_field_object = double('selenium_text_field')
38
+ selenium_text_field = SpecTest::WebObjects::TextField.new(text_field_object, :platform => :selenium_webdriver)
39
+ text_field_object.should_receive(:clear)
40
+ text_field_object.should_receive(:send_keys).with('Testing')
41
+ selenium_text_field.value = 'Testing'
42
+ end
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe "web objects can be used by the selenium platform" do
4
+ let(:selenium_browser) { double('selenium_browser') }
5
+ let(:web_object) { SpecTest::WebObjects::WebObject.new(selenium_browser, :platform => :selenium_webdriver) }
6
+
7
+ context "and that means" do
8
+ it "it should be possible to tell when an object is visible" do
9
+ selenium_browser.stub(:displayed?).and_return(true)
10
+ web_object.visible?.should == true
11
+ end
12
+
13
+ it "it should be possible to tell when an object exists" do
14
+ selenium_browser.stub(:exists?).and_return(true)
15
+ web_object.exists?.should == true
16
+ end
17
+
18
+ it "it should be possible to tell when an object is not visible" do
19
+ selenium_browser.should_receive(:displayed?).and_return(false)
20
+ web_object.visible?.should == false
21
+ end
22
+
23
+ it "it should be possible to tell when an object does not exist" do
24
+ web_object = SpecTest::WebObjects::WebObject.new(nil, :platform => :selenium_webdriver)
25
+ selenium_browser.stub(:exists?).and_return(false)
26
+ selenium_browser.stub(:nil?).and_return(true)
27
+ web_object.exists?.should == false
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe "web objects can be used by the watir platform" do
4
+ let(:watir_browser) { double('watir_browser') }
5
+ let(:web_object) { SpecTest::WebObjects::WebObject.new(watir_browser, :platform => :watir_webdriver) }
6
+
7
+ context "and that means" do
8
+ it "it should be possible to tell when an object is visible" do
9
+ watir_browser.stub(:present?).and_return(true)
10
+ watir_browser.stub(:displayed?).and_return(true)
11
+ web_object.visible?.should == true
12
+ end
13
+
14
+ it "it should be possible to tell when an object exists" do
15
+ watir_browser.stub(:exists?).and_return(true)
16
+ web_object.exists?.should == true
17
+ end
18
+
19
+ it "it should be possible to tell when an object is not visible" do
20
+ watir_browser.stub(:present?).and_return(false)
21
+ watir_browser.stub(:displayed?).and_return(false)
22
+ web_object.visible?.should == false
23
+ end
24
+
25
+ it "it should be possible to tell when an object does not exist" do
26
+ watir_browser.stub(:exists?).and_return(false)
27
+ watir_browser.stub(:nil?).and_return(true)
28
+ web_object.exists?.should == false
29
+ end
30
+ end
31
+ end
@@ -13,10 +13,10 @@
13
13
 
14
14
  <h3>Links</h3>
15
15
 
16
- <p><a id="avengers_unite_id" name="avengers_unite_name" class="avengers_unite_class" href="success_1.html">Avengers Unite</a></p>
16
+ <p><a id="avengers_assemble_id" name="avengers_assemble_name" class="avengers_assemble_class" href="success_1.html">Avengers Assemble</a></p>
17
17
 
18
- <p><a href="success_1.html">Justice League Assemble</a></p>
19
- <p><a href="success_2.html">Justice League Assemble</a></p>
18
+ <p><a href="success_1.html">Justice League Unite</a></p>
19
+ <p><a href="success_2.html">Justice League Unite</a></p>
20
20
 
21
21
  <p><a id="oath" href="success_1.html">"...in the brightest day and in the darkest night..."</a></p>
22
22
 
@@ -0,0 +1,13 @@
1
+ class IFrameExamplesPage
2
+ include SpecTest
3
+
4
+ is_enclosed_by(:id => "static") do |encloser|
5
+ link(:avengers_assemble, :text => "Avengers Assemble", :frame => encloser)
6
+ end
7
+
8
+ is_enclosed_by(:id => "form") do |encloser|
9
+ text_field(:customer_code, :id => "customerCode", :frame => encloser)
10
+ button(:login, :id => "btnSubmit", :frame => encloser)
11
+ end
12
+
13
+ end
@@ -4,4 +4,5 @@ class LandingPage
4
4
  url_is "http://localhost:1234"
5
5
  link :static_text_examples, :text => "Static Text Examples"
6
6
  link :form_examples, :text => "Form Examples"
7
+ link :iframe_examples, :text => "IFrame Examples"
7
8
  end
@@ -1,3 +1,7 @@
1
1
  When /^I click the log in button$/ do
2
2
  @page.login
3
+ end
4
+
5
+ When /^I click the framed log in button$/ do
6
+ @page.login
3
7
  end
@@ -1,3 +1,17 @@
1
1
  When /^I select the static text examples link$/ do
2
2
  @page.static_text_examples
3
3
  end
4
+
5
+ When /^I select the framed avengers assemble link$/ do
6
+ @page.avengers_assemble
7
+ end
8
+
9
+ When /^I select the "([^"]*)" link$/ do |text|
10
+ actual_text = text.gsub(" ", "_").downcase
11
+ @link = @page.send "#{actual_text}"
12
+ end
13
+
14
+ When(/^I look for the "([^"]*)" link$/) do |text|
15
+ actual_text = text.gsub(" ", "_").downcase
16
+ @link = @page.send "#{actual_text}_object"
17
+ end
@@ -1,3 +1,11 @@
1
1
  Then /^I should see the text "([^"]*)"$/ do |text|
2
2
  @text.should == text
3
- end
3
+ end
4
+
5
+ Then(/^I should find that the link exists$/) do
6
+ @link.should exist
7
+ end
8
+
9
+ Then(/^I should find that the link is visible$/) do
10
+ @link.should be_visible
11
+ end
@@ -13,6 +13,12 @@ Given /^I am on the form examples page$/ do
13
13
  @page = FormExamplesPage.new(@browser)
14
14
  end
15
15
 
16
+ Given /^I am on the iframe elements page$/ do
17
+ step %{I have gone to the test app site}
18
+ @page.iframe_examples
19
+ @page = IFrameExamplesPage.new(@browser)
20
+ end
21
+
16
22
  Then /^I should be on the landing page$/ do
17
23
  #@page.text.should match(/^Landing Page$/)
18
24
  #@page.title.should match(/^Test App$/)
@@ -29,4 +35,18 @@ end
29
35
  Then /^I should be taken to the first success page$/ do
30
36
  @page = Success1Page.new(@browser)
31
37
  @page.text.should contain("first success page")
38
+ end
39
+
40
+ Then /^I should be taken to the first success page within the static frame$/ do
41
+ @page.is_enclosed_by(:id => "static") do |frame|
42
+ @page = Success1Page.new(@browser)
43
+ @page.text.should contain("first success page")
44
+ end
45
+ end
46
+
47
+ Then /^I should be taken to the first success page within the form frame$/ do
48
+ @page.is_enclosed_by(:id => "form") do |frame|
49
+ @page = Success1Page.new(@browser)
50
+ @page.text.should contain("first success page")
51
+ end
32
52
  end
@@ -5,4 +5,9 @@ end
5
5
  When /^I enter "([^"]*)" in the customer code text field$/ do |text|
6
6
  @page.customer_code = text
7
7
  @text = @page.customer_code
8
+ end
9
+
10
+ When /^I enter "([^"]*)" in the framed customer code text field$/ do |text|
11
+ @page.customer_code = text
12
+ @text = @page.customer_code
8
13
  end
@@ -0,0 +1,20 @@
1
+ Feature: Ability to handle iframes.
2
+
3
+ As a test writer
4
+ I need the ability to look within iframes
5
+ so that I can manipulate objects that are enclosed within them.
6
+
7
+ Background:
8
+ Given I am on the iframe elements page
9
+
10
+ Scenario: Accessing text fields within an iframe
11
+ When I enter "QA" in the framed customer code text field
12
+ Then I should see the text "QA"
13
+
14
+ Scenario: Accessing links within an iframe
15
+ When I select the framed avengers assemble link
16
+ #Then I should be taken to the first success page within the static frame
17
+
18
+ Scenario: Accessing buttons within an iframe
19
+ When I click the framed log in button
20
+ #Then I should be taken to the first success page within the form frame
@@ -4,9 +4,23 @@ Feature: Ability to support links.
4
4
  I need the ability to click on links
5
5
  so that I can use link-based navigation while testing.
6
6
 
7
+ As a test writer
8
+ I need to locate links on a page with different selectors
9
+ so that I can trawl a page to find needed links
10
+ and so that I can handle changes to links when they occur.
11
+
7
12
  Background:
8
13
  Given I am on the landing page
9
14
 
10
15
  Scenario: Selecting a link. (Specific test step.)
11
16
  When I select the static text examples link
12
17
  Then I should be on the static text examples page
18
+
19
+ Scenario: Selecting a link. (Generic test step.)
20
+ When I select the "Static Text Examples" link
21
+ Then I should be on the static text examples page
22
+
23
+ Scenario: Finding a link (with a single parameter).
24
+ When I look for the "Form Examples" link
25
+ Then I should find that the link exists
26
+ And I should find that the link is visible
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spectest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-14 00:00:00.000000000Z
12
+ date: 2011-11-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
16
- requirement: &16039692 !ruby/object:Gem::Requirement
16
+ requirement: &20625144 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.3.9
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16039692
24
+ version_requirements: *20625144
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: selenium-webdriver
27
- requirement: &16038840 !ruby/object:Gem::Requirement
27
+ requirement: &20624472 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.12.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *16038840
35
+ version_requirements: *20624472
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &16038348 !ruby/object:Gem::Requirement
38
+ requirement: &20623140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.7.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *16038348
46
+ version_requirements: *20623140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: cucumber
49
- requirement: &16037904 !ruby/object:Gem::Requirement
49
+ requirement: &20619588 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.1.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *16037904
57
+ version_requirements: *20619588
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &16037172 !ruby/object:Gem::Requirement
60
+ requirement: &20616636 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.5.4
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *16037172
68
+ version_requirements: *20616636
69
69
  description: Test framework for specifying tests and executing tests.
70
70
  email:
71
71
  - jeffnyman@gmail.com
@@ -82,13 +82,20 @@ files:
82
82
  - Rakefile
83
83
  - cucumber.yml
84
84
  - lib/spectest.rb
85
+ - lib/spectest/enclosers.rb
85
86
  - lib/spectest/generators.rb
86
87
  - lib/spectest/logger.rb
87
88
  - lib/spectest/matchers.rb
88
89
  - lib/spectest/platform_selenium.rb
89
90
  - lib/spectest/platform_selenium/platform_object.rb
91
+ - lib/spectest/platform_selenium/web_objects/all.rb
92
+ - lib/spectest/platform_selenium/web_objects/button.rb
93
+ - lib/spectest/platform_selenium/web_objects/link.rb
94
+ - lib/spectest/platform_selenium/web_objects/text_field.rb
90
95
  - lib/spectest/platform_watir.rb
91
96
  - lib/spectest/platform_watir/platform_object.rb
97
+ - lib/spectest/platform_watir/web_objects/all.rb
98
+ - lib/spectest/platform_watir/web_objects/text_field.rb
92
99
  - lib/spectest/platforms.rb
93
100
  - lib/spectest/version.rb
94
101
  - lib/spectest/web_objects/all.rb
@@ -104,6 +111,12 @@ files:
104
111
  - spec/platforms_spec.rb
105
112
  - spec/spec_helper.rb
106
113
  - spec/spectest_spec.rb
114
+ - spec/web_objects/all_spec.rb
115
+ - spec/web_objects/button_spec.rb
116
+ - spec/web_objects/link_spec.rb
117
+ - spec/web_objects/text_field_spec.rb
118
+ - spec/webobject_selenium_spec.rb
119
+ - spec/webobject_watir_spec.rb
107
120
  - specs/app/favicon.ico
108
121
  - specs/app/images/mass_extinction.jpg
109
122
  - specs/app/index.html
@@ -121,6 +134,7 @@ files:
121
134
  - specs/engine/borg.rb
122
135
  - specs/engine/hooks.rb
123
136
  - specs/pages/form_examples_page.rb
137
+ - specs/pages/iframe_examples_page.rb
124
138
  - specs/pages/landing_page.rb
125
139
  - specs/pages/static_examples_page.rb
126
140
  - specs/pages/success_1_page.rb
@@ -130,6 +144,7 @@ files:
130
144
  - specs/steps/page_steps.rb
131
145
  - specs/steps/text_field_steps.rb
132
146
  - specs/tests/button.feature
147
+ - specs/tests/iframes.feature
133
148
  - specs/tests/link.feature
134
149
  - specs/tests/page.feature
135
150
  - specs/tests/text_field.feature