lib/symbiont/generators.rb in symbiont-0.1.8 vs lib/symbiont/generators.rb in symbiont-0.1.9

- old
+ new

@@ -14,13 +14,13 @@ end def title_is(title) define_method('has_title?') do sleep 1 - valid_title = title =~ browser.title if title.kind_of?(Regexp) - valid_title = title == browser.title if title.kind_of?(String) - raise "\n\nExpected title: '#{title}'; Actual title: '#{browser.title}'" unless valid_title + valid_title = title =~ @browser.title if title.kind_of?(Regexp) + valid_title = title == @browser.title if title.kind_of?(String) + raise "\n\nExpected title: '#{title}'; Actual title: '#{@browser.title}'" unless valid_title valid_title end end def look_for(widget, timeout=5) @@ -135,74 +135,39 @@ - # Definition method for tables. Methods for the following actions will be created: - # * reference a table (identifier_object, identifier_table) - # * check for existence (identifier?, identifier_exists?) - # * check for visibility (identifier_?, identifier_visible?) - # @param [Symbol] identifier the friendly name of the web object - # @param [optional, Hash] locator the key/values that identify the object - # @return [Object] instance of Symbiont::WebObjects::Table def table(identifier, locator) - define_method("#{identifier}_object") do - @platform.get_table_for(locator.clone) + define_method(identifier) do + platform.table_text_for(locator.clone) end - - alias_method "#{identifier}_table".to_sym, "#{identifier}_object".to_sym - - define_method("#{identifier}_exists?") do - @platform.check_table_for_existence(locator.clone) - end - - alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym - - define_method("#{identifier}_visible?") do - @platform.check_table_for_visibility(locator.clone) - end - - alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym + + common_definition_methods(identifier, locator, 'table_element') end - # Definition method for table cells. Methods for the following actions will be created: - # * reference a table cell (identifier_object, identifier_cell) - # * check for existence (identifier?, identifier_exists?) - # * check for visibility (identifier_?, identifier_visible?) - # * get text from cell (identifier) - # @param [Symbol] identifier the friendly name of the web object - # @param [optional, Hash] locator the key/values that identify the object - # @return [Object] instance of Symbiont::WebObjects::TableCell def cell(identifier, locator) - define_method("#{identifier}_object") do - @platform.get_table_cell_for(locator.clone) + define_method(identifier) do + platform.get_table_cell_text_for(locator.clone) end - - alias_method "#{identifier}_cell".to_sym, "#{identifier}_object".to_sym - - define_method("#{identifier}_exists?") do - @platform.check_table_cell_for_existence(locator.clone) - end - - alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym - - define_method("#{identifier}_visible?") do - @platform.check_table_cell_for_visibility(locator.clone) - end - - alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym - - define_method("#{identifier}") do - @platform.get_table_cell_text_for(locator.clone) - end + + common_definition_methods(identifier, locator, 'cell_element') end - + def div(identifier, locator) + define_method(identifier) do + platform.div_text_for(locator.clone) + end + common_definition_methods(identifier, locator, 'div_element') end def span(identifier, locator) + define_method(identifier) do + platform.span_text_for(locator.clone) + end + common_definition_methods(identifier, locator, 'span_element') end def common_definition_methods(identifier, locator, method) define_method("#{identifier}_object") do @@ -223,10 +188,11 @@ define_method("#{identifier}_text") do platform.send(method, locator.clone).text end - element = method[0..method.index("_") - 1] + element = method[0..method.rindex("_") - 1] if method.count("_") == 2 + element = method[0..method.index("_") - 1] if method.count("_") == 1 alias_method "#{identifier}_#{element}".to_sym, "#{identifier}_object".to_sym alias_method "#{identifier}?".to_sym, "#{identifier}_exists?".to_sym alias_method "#{identifier}_?".to_sym, "#{identifier}_visible?".to_sym alias_method "#{identifier}!".to_sym, "#{identifier}_enabled?".to_sym