symbiont 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/Gemfile.lock +10 -39
  2. data/HISTORY.md +6 -0
  3. data/lib/symbiont.rb +8 -4
  4. data/lib/symbiont/enclosers.rb +4 -4
  5. data/lib/symbiont/evaluators.rb +22 -29
  6. data/lib/symbiont/generators.rb +82 -317
  7. data/lib/symbiont/platform_selenium.rb +18 -0
  8. data/lib/symbiont/platform_selenium/platform_object.rb +236 -0
  9. data/lib/symbiont/platform_selenium/web_objects/button.rb +13 -0
  10. data/lib/symbiont/platform_selenium/web_objects/checkbox.rb +21 -0
  11. data/lib/symbiont/platform_selenium/web_objects/common.rb +104 -0
  12. data/lib/symbiont/platform_selenium/web_objects/link.rb +13 -0
  13. data/lib/symbiont/platform_selenium/web_objects/radio.rb +21 -0
  14. data/lib/symbiont/platform_selenium/web_objects/select_list.rb +79 -0
  15. data/lib/symbiont/platform_selenium/web_objects/table.rb +40 -0
  16. data/lib/symbiont/platform_selenium/web_objects/table_row.rb +36 -0
  17. data/lib/symbiont/platform_selenium/web_objects/text_field.rb +14 -0
  18. data/lib/symbiont/platform_watir.rb +13 -4
  19. data/lib/symbiont/platform_watir/platform_object.rb +74 -262
  20. data/lib/symbiont/platform_watir/web_objects/checkbox.rb +21 -0
  21. data/lib/symbiont/platform_watir/web_objects/common.rb +82 -0
  22. data/lib/symbiont/platform_watir/web_objects/radio.rb +21 -0
  23. data/lib/symbiont/platform_watir/web_objects/select_list.rb +67 -0
  24. data/lib/symbiont/platform_watir/web_objects/table.rb +31 -0
  25. data/lib/symbiont/platform_watir/web_objects/table_row.rb +31 -0
  26. data/lib/symbiont/platform_watir/web_objects/text_field.rb +13 -0
  27. data/lib/symbiont/platforms.rb +18 -6
  28. data/lib/symbiont/version.rb +1 -1
  29. data/lib/symbiont/web_objects/_common.rb +53 -74
  30. data/lib/symbiont/web_objects/button.rb +23 -4
  31. data/lib/symbiont/web_objects/checkbox.rb +24 -10
  32. data/lib/symbiont/web_objects/div.rb +9 -1
  33. data/lib/symbiont/web_objects/link.rb +25 -4
  34. data/lib/symbiont/web_objects/paragraph.rb +11 -0
  35. data/lib/symbiont/web_objects/radio.rb +27 -1
  36. data/lib/symbiont/web_objects/select_list.rb +20 -56
  37. data/lib/symbiont/web_objects/span.rb +9 -1
  38. data/lib/symbiont/web_objects/table.rb +19 -22
  39. data/lib/symbiont/web_objects/table_cell.rb +17 -1
  40. data/lib/symbiont/web_objects/table_row.rb +18 -25
  41. data/lib/symbiont/web_objects/text_field.rb +27 -11
  42. data/symbiont.gemspec +3 -8
  43. metadata +29 -122
  44. data/app/Gemfile +0 -4
  45. data/app/app.rb +0 -181
  46. data/app/config/database.rb +0 -9
  47. data/app/models/plan.rb +0 -10
  48. data/app/models/product.rb +0 -10
  49. data/app/models/study.rb +0 -11
  50. data/app/models/user.rb +0 -13
  51. data/app/public/css/style.css +0 -138
  52. data/app/views/create_plan.erb +0 -21
  53. data/app/views/create_product.erb +0 -15
  54. data/app/views/create_study.erb +0 -24
  55. data/app/views/create_user.erb +0 -60
  56. data/app/views/db_plans.erb +0 -31
  57. data/app/views/db_products.erb +0 -29
  58. data/app/views/db_studies.erb +0 -33
  59. data/app/views/db_users.erb +0 -23
  60. data/app/views/entity_list.erb +0 -10
  61. data/app/views/index.erb +0 -8
  62. data/app/views/layout.erb +0 -39
  63. data/app/views/login_page.erb +0 -17
  64. data/app/views/success_1.erb +0 -2
  65. data/app/views/success_2.erb +0 -2
  66. data/app/views/test_database.erb +0 -13
  67. data/app/views/test_events.erb +0 -51
  68. data/app/views/test_login.erb +0 -53
  69. data/app/views/test_login_error.erb +0 -22
  70. data/app/views/test_login_success.erb +0 -22
  71. data/app/views/test_page.erb +0 -184
  72. data/specs/button.feature +0 -44
  73. data/specs/checkbox.feature +0 -40
  74. data/specs/data_setter.feature +0 -29
  75. data/specs/definitions/pages.rb +0 -156
  76. data/specs/div.feature +0 -11
  77. data/specs/evaluators.feature +0 -17
  78. data/specs/events.feature +0 -30
  79. data/specs/frame.feature +0 -5
  80. data/specs/link.feature +0 -42
  81. data/specs/locators.feature +0 -17
  82. data/specs/radio.feature +0 -38
  83. data/specs/select_list.feature +0 -50
  84. data/specs/simple_test.feature +0 -13
  85. data/specs/span.feature +0 -11
  86. data/specs/support/env.rb +0 -20
  87. data/specs/support/hooks.rb +0 -11
  88. data/specs/support/test_steps/action_steps_buttons.rb +0 -70
  89. data/specs/support/test_steps/action_steps_checkboxes.rb +0 -75
  90. data/specs/support/test_steps/action_steps_data_setter.rb +0 -56
  91. data/specs/support/test_steps/action_steps_divs.rb +0 -18
  92. data/specs/support/test_steps/action_steps_evaluators.rb +0 -15
  93. data/specs/support/test_steps/action_steps_events.rb +0 -77
  94. data/specs/support/test_steps/action_steps_frames.rb +0 -13
  95. data/specs/support/test_steps/action_steps_links.rb +0 -61
  96. data/specs/support/test_steps/action_steps_locators.rb +0 -44
  97. data/specs/support/test_steps/action_steps_navigate.rb +0 -25
  98. data/specs/support/test_steps/action_steps_radios.rb +0 -75
  99. data/specs/support/test_steps/action_steps_select_lists.rb +0 -106
  100. data/specs/support/test_steps/action_steps_spans.rb +0 -18
  101. data/specs/support/test_steps/action_steps_tables.rb +0 -82
  102. data/specs/support/test_steps/action_steps_text_fields.rb +0 -107
  103. data/specs/support/test_steps/action_steps_webobjects.rb +0 -31
  104. data/specs/support/test_steps/simple_test_steps.rb +0 -8
  105. data/specs/table.feature +0 -39
  106. data/specs/text_field.feature +0 -47
  107. data/specs/web_object.feature +0 -15
@@ -0,0 +1,21 @@
1
+ module Symbiont
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module CheckBox
5
+
6
+ def check
7
+ web_object.set
8
+ end
9
+
10
+ def uncheck
11
+ web_object.clear
12
+ end
13
+
14
+ def checked?
15
+ web_object.set?
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,82 @@
1
+ module Symbiont
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
+ def id
15
+ web_object.id
16
+ end
17
+
18
+ def value
19
+ web_object.value
20
+ end
21
+
22
+ def flash
23
+ web_object.flash
24
+ end
25
+
26
+ def attribute(name)
27
+ web_object.attribute_value(name)
28
+ end
29
+
30
+ def focus
31
+ web_object.focus
32
+ end
33
+
34
+ def parent
35
+ parent = web_object.parent
36
+ type = web_object.type if parent.tag_name.to_sym == :input
37
+ object_class = ::Symbiont::WebObjects.get_class_for(parent.tag_name, type)
38
+ object_class.new(parent, :platform => :watir_webdriver)
39
+ end
40
+
41
+ def wait_until(timeout=::Symbiont.element_level_wait, message=nil, &block)
42
+ Object::Watir::Wait.until(timeout, message, &block)
43
+ end
44
+
45
+ def when_actionable(timeout=::Symbiont.element_level_wait)
46
+ web_object.wait_until_present(timeout)
47
+ self
48
+ end
49
+
50
+ alias_method :when_present, :when_actionable
51
+
52
+ def when_not_actionable(timeout=::Symbiont.element_level_wait)
53
+ web_object.wait_while_present(timeout)
54
+ end
55
+
56
+ alias_method :when_not_present, :when_not_actionable
57
+
58
+ def when_visible(timeout=::Symbiont.element_level_wait)
59
+ Object::Watir::Wait.until(timeout, "Object not visible within #{timeout} seconds.") do
60
+ visible?
61
+ end
62
+ self
63
+ end
64
+
65
+ def when_not_visible(timeout=::Symbiont.element_level_wait)
66
+ Object::Watir::Wait.while(timeout, "Object still visible after #{timeout} seconds.") do
67
+ visible?
68
+ end
69
+ self
70
+ end
71
+
72
+ alias_method :must_be_visible, :when_visible
73
+ alias_method :must_not_be_visible, :when_not_visible
74
+
75
+ def scroll_into_view(wait=2)
76
+ sleep wait
77
+ web_object.wd.location_once_scrolled_into_view
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,21 @@
1
+ module Symbiont
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module Radio
5
+
6
+ def select
7
+ web_object.set
8
+ end
9
+
10
+ def clear
11
+ web_object.clear
12
+ end
13
+
14
+ def selected?
15
+ web_object.set?
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,67 @@
1
+ module Symbiont
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module SelectList
5
+
6
+ # This method is used to return an Option object based on the index provided.
7
+ # @return [Symbiont::WebObjects::Option]
8
+ def [](idx)
9
+ ::Symbiont::WebObjects::Option.new(options[idx], :platform => :watir_webdriver)
10
+ end
11
+
12
+ # Selects an option from the select list.
13
+ def select(value)
14
+ web_object.select(value)
15
+ end
16
+
17
+ # Selects the option whose value attribute matches the provided string.
18
+ def select_value(value)
19
+ web_object.select_value(value)
20
+ end
21
+
22
+ # This method returns an array of Option objects that are contained within
23
+ # a select list object.
24
+ # @return [array of Symbiont::WebObjects::Option]
25
+ def options
26
+ web_objects = []
27
+ options = web_object.wd.find_elements(:xpath, option_xpath)
28
+ options.each do |opt|
29
+ web_objects << ::Symbiont::WebObjects::Option.new(opt, :platform => :watir_webdriver)
30
+ end
31
+ web_objects
32
+ end
33
+
34
+ # This method returns an array of strings that contain the text of the
35
+ # currently selected options in a select list.
36
+ # @return [Array<String>]
37
+ def selected_options
38
+ web_object.selected_options.map { |e| e.text }.compact
39
+ end
40
+
41
+ # This method returns an array of strings that contain the values of the
42
+ # currently selected options in a select list.
43
+ # @return [Array<String>]
44
+ def selected_values
45
+ web_object.selected_options.map { |e| e.value }.compact
46
+ end
47
+
48
+ # This method returns true if any of the text or the lable of any option
49
+ # that is selected matches the provided value.
50
+ # @param [String, Regexp] value A value to check for
51
+ # @return [Boolean]
52
+ def selected?(value)
53
+ web_object.selected? value
54
+ end
55
+
56
+ # This method checks to see if the select list has one or more options
57
+ # where the text or the label matches the provided value.
58
+ # @param [String, Regexp] value A value to check for.
59
+ # @return [Boolean]
60
+ def include?(value)
61
+ web_object.include? value
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,31 @@
1
+ module Symbiont
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module Table
5
+
6
+ # This method is used to return a TableRow object based on the index provided. When
7
+ # the index provided is a string, the text will be matched with the text from the first
8
+ # column.
9
+ # @return [Symbiont::WebObjects::TableRow]
10
+ def [](index)
11
+ index = find_by_title(index) if index.kind_of?(String)
12
+ return nil unless index
13
+ ::Symbiont::WebObjects::TableRow.new(@web_object[index], :platform => :watir_webdriver)
14
+ end
15
+
16
+ # This method will return the number of rows in a table.
17
+ def rows
18
+ web_object.wd.find_elements(:xpath, row_xpath).size
19
+ end
20
+
21
+ def find_by_title(row_text)
22
+ #web_object.rows.find_index {|row| row[0].text == row_text}
23
+ web_object.rows.find_index do |row|
24
+ row.cells.any? { |col| col.text.include? row_text }
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module Symbiont
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module TableRow
5
+
6
+ # This method is used to return a TableCell object based on the index provided. When
7
+ # the index provided is a string, the text will be matched with the text from the
8
+ # columns in the first row.
9
+ # @return [Symbiont::WebObjects::TableCell]
10
+ def [](index)
11
+ index = find_by_title(index) if index.kind_of?(String)
12
+ return nil unless index && columns >= idx + 1
13
+ ::Symbiont::WebObjects::TableCell.new(web_object[index], :platform => :watir_webdriver)
14
+ end
15
+
16
+ # This method returns the number of columns in a table object.
17
+ def columns
18
+ web_object.wd.find_elements(:xpath, cell_xpath).size
19
+ end
20
+
21
+ def find_by_title(column_text)
22
+ table = web_object.parent
23
+ table = table.parent if table.tag_name == 'tbody'
24
+ first_row = table[0]
25
+ first_row.cells.find_index {|column| column.text.include? column_text}
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ module Symbiont
2
+ module Platforms
3
+ module WatirWebDriver
4
+ module TextField
5
+
6
+ def value=(value)
7
+ web_object.set value
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,22 +2,34 @@ module Symbiont
2
2
  module Platforms
3
3
 
4
4
  require 'watir-webdriver'
5
+ require 'selenium-webdriver'
6
+
7
+ @@drivers = {}
8
+
9
+ def self.list
10
+ @@drivers
11
+ end
12
+
13
+ def self.register(driver, platform_object)
14
+ @@drivers[driver] = platform_object
15
+ end
5
16
 
6
17
  # This module determines what execution platform Symbiont will use.
7
18
  # The decision is based on the browser that has been established for
8
19
  # the execution profile.
9
20
  #
10
21
  # @param [Object] browser the browser to establish the platform for
22
+ # @param [Hash] drivers the list of registered browser drivers
11
23
  # @returns [Object] a platform object to execute tests against
12
- def get_platform_for(browser)
13
- if browser.is_a?(Watir::Browser)
14
- return @platform = Symbiont::Platforms::WatirWebDriver::PlatformObject.new(@browser)
15
- else
16
- raise "Unable to create a platform object for #{browser}"
17
- end
24
+ def get_platform_for(browser, drivers)
25
+ drivers.each_value { |driver|
26
+ return driver.create_platform_object_for(browser) if driver.works_with(browser)
27
+ }
28
+ raise "Unable to create a platform object for #{browser}"
18
29
  end
19
30
 
20
31
  end # module: Platforms
21
32
  end # module: Symbiont
22
33
 
23
34
  require_relative 'platform_watir'
35
+ require_relative 'platform_selenium'
@@ -1,3 +1,3 @@
1
1
  module Symbiont
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -7,108 +7,87 @@ module Symbiont
7
7
  # platform).
8
8
 
9
9
  class WebObject
10
- def initialize(web_object)
10
+ attr_reader :web_object
11
+
12
+ def initialize(web_object, platform)
11
13
  @web_object = web_object
14
+ include_platform_specifics_for(platform)
12
15
  end
13
16
 
14
17
  def enabled?
15
- @web_object.enabled?
18
+ web_object.enabled?
16
19
  end
17
20
 
18
21
  def disabled?
19
22
  not enabled?
20
23
  end
21
-
22
- def exists?
23
- @web_object.exists?
24
- end
25
-
26
- def visible?
27
- @web_object.present?
28
- end
29
-
24
+
30
25
  def text
31
- @web_object.text
26
+ web_object.text
32
27
  end
33
28
 
34
29
  def click
35
- @web_object.click
36
- end
37
-
38
- def clear
39
- @web_object.clear
40
- end
41
-
42
- def attribute(name)
43
- @web_object.attribute_value(name)
30
+ web_object.click
44
31
  end
45
-
46
- def style(property)
47
- @web_object.style(property)
48
- end
49
-
32
+
50
33
  def tag
51
- @web_object.tag_name
34
+ web_object.tag_name
52
35
  end
53
-
54
- def id
55
- @web_object.id
36
+
37
+ def clear
38
+ web_object.clear
56
39
  end
57
-
58
- def value
59
- @web_object.value
40
+
41
+ def style(property)
42
+ web_object.style(property)
60
43
  end
61
-
44
+
62
45
  def inspect
63
- @web_object.inspect
46
+ web_object.inspect
64
47
  end
65
-
66
- def flash
67
- @web_object.flash
48
+
49
+ def self.usable_selectors_for_watir
50
+ [:id, :name, :xpath, :class, :index]
68
51
  end
69
-
70
- def when_actionable(timeout=5)
71
- @web_object.wait_until_present(timeout)
72
- self
52
+
53
+ def self.usable_selectors_for_selenium
54
+ [:id, :name, :xpath, :class, :index, :css]
73
55
  end
74
-
75
- alias :when_present :when_actionable
76
-
77
- def when_visible(timeout=5)
78
- Object::Watir::Wait.until(timeout, "object not visible within #{timeout} seconds.") do
79
- visible?
80
- end
81
- self
56
+
57
+ def self.selector_mapping_for_watir
58
+ {}
82
59
  end
83
-
84
- def when_not_visible(timeout=5)
85
- Object::Watir::Wait.while(timeout, "object still visible after #{timeout} seconds.") do
86
- visible?
87
- end
88
- self
60
+
61
+ def self.selector_mapping_for_selenium
62
+ {}
89
63
  end
90
64
 
91
- alias :must_be_visible :when_visible
92
- alias :must_not_be_visible :when_not_visible
93
-
94
- def wait_until(timeout, message=nil, &block)
95
- Object::Watir::Wait.until(timeout, message, &block)
65
+ def self.provide_watir_locator_for(locator)
66
+ locator = locator_for(locator, usable_selectors_for_watir, selector_mapping_for_watir)
67
+ return {locator.keys.first => locator.values.first}
96
68
  end
97
-
98
- def self.usable_selectors
99
- [:id, :name, :xpath, :class, :index]
69
+
70
+ def self.provide_selenium_locator_for(locator)
71
+ locator = locator_for(locator, usable_selectors_for_selenium, selector_mapping_for_selenium)
72
+ return locator.keys.first, locator.values.first
100
73
  end
101
-
102
- def self.selector_mapping
103
- {}
74
+
75
+ def self.locator_for(locator, selectors, mappings)
76
+ how, what = locator.keys.first, locator.values.first
77
+ return how => what if selectors.include? how
78
+ return mappings[how] => what if mappings[how]
79
+ return nil => what
104
80
  end
105
-
106
- def self.provide_locator_for(locator)
107
- locator.each do |key, value|
108
- how, what = locator.keys.first, locator.values.first
109
- return how => what if usable_selectors.include? how
110
- return selector_mapping[how] => what if selector_mapping[how]
111
- return nil => what
81
+
82
+ def include_platform_specifics_for(platform)
83
+ if platform[:platform] == :watir_webdriver
84
+ require 'symbiont/platform_watir/web_objects/common'
85
+ self.class.send :include, ::Symbiont::Platforms::WatirWebDriver::WebObject
86
+ elsif platform[:platform] == :selenium_webdriver
87
+ require 'symbiont/platform_selenium/web_objects/common'
88
+ self.class.send :include, ::Symbiont::Platforms::SeleniumWebDriver::WebObject
89
+ else
90
+ raise ArgumentError, "The platform #{platform[:platform]} appears to be unsupported."
112
91
  end
113
92
  end
114
93
  end # class: WebObject