diff --git a/features/html/multi_elements.html b/features/html/multi_elements.html index a9cd4817..12b4e388 100644 --- a/features/html/multi_elements.html +++ b/features/html/multi_elements.html @@ -19,7 +19,7 @@ - + @@ -33,7 +33,7 @@ link 1 link 2 link 3 - + @@ -41,15 +41,15 @@ - +
Div 1
Div 2
Div 3
- + Span 1 Span 2 Span 3 - + @@ -77,7 +77,7 @@ Data 9 - + image 1 image 2 image 3 @@ -115,11 +115,11 @@

H1 Three

H2 One

H2 Two

H2 Three

- +

H3 One

H3 Two

H3 Three

- +

H4 One

H4 Two

H4 Three

@@ -127,7 +127,7 @@

H4 Three

H5 One
H5 Two
H5 Three
- +
H6 One
H6 Two
H6 Three
@@ -135,10 +135,11 @@
H6 Three

Paragraph One

Paragraph Two

Paragraph Three

- + In bold One B and Two B for example text + In italic One I and Two I for example text diff --git a/features/html/static_elements.html b/features/html/static_elements.html index a6c3bb8b..6752aeb5 100755 --- a/features/html/static_elements.html +++ b/features/html/static_elements.html @@ -180,11 +180,12 @@
h6's are cool
The summary The details - +
The Pulpit Rock
This text have some text in bold + This text have some text in italic diff --git a/features/italic.feature b/features/italic.feature new file mode 100644 index 00000000..d6ed2fcb --- /dev/null +++ b/features/italic.feature @@ -0,0 +1,21 @@ +Feature: Italic + + Background: + Given I am on the static elements page + + Scenario: Getting the text of headings + When I get the italic text for the "i" element + Then I should see "some text in italic" in italic + + Scenario Outline: Locating i on the Page + When I search italic text for the i by "" + Then I should see "some text in italic" in italic + + Scenarios: + | search_by | + | id | + | class | + | name | + | xpath | + | index | + | css | diff --git a/features/multi_elements.feature b/features/multi_elements.feature index 882c89f1..254cdf74 100644 --- a/features/multi_elements.feature +++ b/features/multi_elements.feature @@ -9,7 +9,7 @@ Feature: Multi Elements And the value of button 1 should be "Button 1" And the value of button 2 should be "Button 2" And the value of button 3 should be "Button 3" - + Scenario: Selecting buttons using no identifier When I select all buttons using no identifier Then I should have 3 buttons @@ -20,7 +20,7 @@ Feature: Multi Elements And the value of text field 1 should be "text 1" And the value of text field 2 should be "text 2" And the value of text field 3 should be "text 3" - + Scenario: Selecting text fields using no identifier When I select all text fields using no identifier Then I should have 3 text fields @@ -79,7 +79,7 @@ Feature: Multi Elements Scenario: Selecting checkboxes using no identifier When I select checboxes using no identifier Then I should have 3 checkboxes - + Scenario: Selecting radio buttons using an identifier When I select the radio button with class "radio" Then I should have 3 radio buttons @@ -141,7 +141,7 @@ Feature: Multi Elements And the alt for image 1 should be "image 1" And the alt for image 2 should be "image 2" And the alt for image 3 should be "image 3" - + Scenario: Selecting images using no identifier When I select the images using no identifier Then I should have 3 images @@ -152,7 +152,7 @@ Feature: Multi Elements And the action for form 1 should be "form1" And the action for form 2 should be "form2" And the action for form 3 should be "form3" - + Scenario: Selecting forms using no identifier When I select the forms using no identifier Then I should have 3 forms @@ -163,7 +163,7 @@ Feature: Multi Elements And the text for list item 1 should be "Item One" And the text for list item 2 should be "Item Two" And the text for list item 3 should be "Item Three" - + Scenario: Selecting list items using no identifier When I select the list items using no identifier Then I should have 8 list items @@ -174,18 +174,18 @@ Feature: Multi Elements And the text for the first item in unordered list 1 should be "Item One" And the text for the first item in unordered list 2 should be "Item Four" And the text for the first item in unordered list 3 should be "Item Five" - + Scenario: Selecting unordered lists using no identifier When I select the unordered list using no parameter Then I should have 3 unordered lists - + Scenario: Selecting ordered lists using an identifier When I select the ordered lists with class "ol" Then I should have 3 ordered lists And the text for the first item in ordered list 1 should be "Number One" And the text for the first item in ordered list 2 should be "Number Two" And the text for the first item in ordered list 3 should be "Number Three" - + Scenario: Selecting ordered lists using no identifier When I select the ordered lists using no identifier Then I should have 3 ordered lists @@ -196,7 +196,7 @@ Feature: Multi Elements And the text for h1 1 should be "H1 One" And the text for h1 2 should be "H1 Two" And the text for h1 3 should be "H1 Three" - + Scenario: Selecting h1s using no identifier When I select h1s using no identifier Then I should have 3 h1s @@ -207,7 +207,7 @@ Feature: Multi Elements And the text for h2 1 should be "H2 One" And the text for h2 2 should be "H2 Two" And the text for h2 3 should be "H2 Three" - + Scenario: Selecting h2s using no identifier When I select h2s using no identifier Then I should have 3 h2s @@ -218,7 +218,7 @@ Feature: Multi Elements And the text for h3 1 should be "H3 One" And the text for h3 2 should be "H3 Two" And the text for h3 3 should be "H3 Three" - + Scenario: Selecting h3s using no identifier When I select h3s using no identifier Then I should have 3 h3s @@ -229,18 +229,18 @@ Feature: Multi Elements And the text for H4 1 should be "H4 One" And the text for H4 2 should be "H4 Two" And the text for H4 3 should be "H4 Three" - + Scenario: Selecting h4s using no identifier When I select h4s using no identifier Then I should have 3 h4s - + Scenario: Selecting h5s using an identifier When I select the h5s with the class "h5" Then I should have 3 h5s And the text for H5 1 should be "H5 One" And the text for H5 2 should be "H5 Two" And the text for H5 3 should be "H5 Three" - + Scenario: Selecting h5s using no identifier When I select h5s using no identifier Then I should have 3 h5s @@ -251,7 +251,7 @@ Feature: Multi Elements And the text for H6 1 should be "H6 One" And the text for H6 2 should be "H6 Two" And the text for H6 3 should be "H6 Three" - + Scenario: Selecting h6s using no identifier When I select h6s using no identifier Then I should have 3 h6s @@ -295,7 +295,7 @@ Feature: Multi Elements And the text of div 1 should be "Div 1" And the text of div 2 should be "Div 2" And the text of div 3 should be "Div 3" - + Scenario: Selecting all divs using a block instead of an identifier When I select the divs using a block Then I should have 3 divs @@ -421,35 +421,35 @@ Feature: Multi Elements And the text for h1 1 should be "H1 One" And the text for h1 2 should be "H1 Two" And the text for h1 3 should be "H1 Three" - + Scenario: Selecting h2s based on a class declaration When I select the h2s using the generated method Then I should have 3 h2s And the text for h2 1 should be "H2 One" And the text for h2 2 should be "H2 Two" And the text for h2 3 should be "H2 Three" - + Scenario: Selecting h3s based on a class declaration When I select the h3s using the generated method Then I should have 3 h3s And the text for h3 1 should be "H3 One" And the text for h3 2 should be "H3 Two" And the text for h3 3 should be "H3 Three" - + Scenario: Selecting h4s based on a class declaration When I select the h4s using the generated method Then I should have 3 h4s And the text for H4 1 should be "H4 One" And the text for H4 2 should be "H4 Two" And the text for H4 3 should be "H4 Three" - + Scenario: Selecting h5s based on a class declaration When I select the h5s using the generated method Then I should have 3 h5s And the text for H5 1 should be "H5 One" And the text for H5 2 should be "H5 Two" And the text for H5 3 should be "H5 Three" - + Scenario: Selecting h6s based on a class declaration When I select the h6s using the generated method Then I should have 3 h6s @@ -490,3 +490,9 @@ Feature: Multi Elements Then I should have 2 bs And the text for b 1 should be "One B" And the text for b 2 should be "Two B" + + Scenario: Selecting is using an identifier + When I select the is + Then I should have 2 is + And the text for i 1 should be "One I" + And the text for i 2 should be "Two I" \ No newline at end of file diff --git a/features/step_definitions/italic_steps.rb b/features/step_definitions/italic_steps.rb new file mode 100644 index 00000000..1e39b896 --- /dev/null +++ b/features/step_definitions/italic_steps.rb @@ -0,0 +1,12 @@ +When /^I get the italic text for the "([^\"]*)" element$/ do |el| + @i = @page.send "#{el}_id" +end + +Then /^I should see "([^\"]*)" in italic$/ do |text| + @i.should == text +end + +When /^I search italic text for the (\w+) by "([^"]*)"$/ do |text_decorator, type| + @i = @page.send "#{text_decorator}_#{type}" +end + diff --git a/features/step_definitions/multi_elements_steps.rb b/features/step_definitions/multi_elements_steps.rb index a724f468..e1226e92 100644 --- a/features/step_definitions/multi_elements_steps.rb +++ b/features/step_definitions/multi_elements_steps.rb @@ -32,6 +32,7 @@ class MultiElementsPage file_fields(:the_file_fields, :class => 'file_field_class') elements(:generic_label, :label, :class => 'label') b(:bs) + i(:is) end @@ -539,3 +540,15 @@ class MultiElementsPage Then /^the text for b (\d+) should be "([^\"]*)"$/ do |b_num, text| @elements[b_num.to_i - 1].text.should == text end + +When /^I select the is$/ do + @elements = @page.i_elements +end + +Then /^I should have (\d+) is$/ do |num_is| + @elements.size.should == num_is.to_i +end + +Then /^the text for i (\d+) should be "([^\"]*)"$/ do |i_num, text| + @elements[i_num.to_i - 1].text.should == text +end diff --git a/features/support/page.rb b/features/support/page.rb index 4bb0dac3..6134208f 100644 --- a/features/support/page.rb +++ b/features/support/page.rb @@ -109,7 +109,7 @@ class Page div(:div_title, :title => 'div_title') div(:div_class_index, :class => "div_class", :index => 0) div(:div_name_index, :name => "div_name", :index => 0) - + div(:div_data_entity, :data_entity => "test") span(:span_id, :id => 'span_id') @@ -349,7 +349,7 @@ class Page element(:details_id, :details, :id => 'details_id') figure(:figure_id, :id => 'figure_id') - + svg(:svg_id, :id => 'the_svg') b(:b_id, :id => 'b_id') @@ -360,5 +360,14 @@ class Page b(:b_xpath, :xpath => '//b') b(:b_class_index, :class => 'b_class', :index => 0) b(:b_name_index, :name => 'b_name', :index => 0) + + i(:i_id, :id => 'i_id') + i(:i_class, :class => 'i_class') + i(:i_css, :css => '.i_class') + i(:i_name, :name => 'i_name') + i(:i_index, :index => 0) + i(:i_xpath, :xpath => '//i') + i(:i_class_index, :class => 'i_class', :index => 0) + i(:i_name_index, :name => 'i_name', :index => 0) end diff --git a/lib/page-object/accessors.rb b/lib/page-object/accessors.rb index 60785038..973f8ecd 100644 --- a/lib/page-object/accessors.rb +++ b/lib/page-object/accessors.rb @@ -1175,6 +1175,34 @@ def b(name, identifier={:index => 0}, &block) end end + # + # adds three methods - one to retrieve the text of a i element, another to + # retrieve a i element, and another to check for it's existence. + # + # @example + # i(:italic, :id => 'title') + # # will generate 'italic', 'italic_element', and 'italic?' methods + # + # @param [Symbol] the name used for the generated methods + # @param [Hash] identifier how we find a i. You can use a multiple parameters + # by combining of any of the following except xpath. The valid keys are: + # * :class => Watir and Selenium + # * :css => Watir and Selenium + # * :id => Watir and Selenium + # * :index => Watir and Selenium + # * :name => Watir and Selenium + # * :xpath => Watir and Selenium + # @param optional block to be invoked when element method is called + # + def i(name, identifier={:index => 0}, &block) + standard_methods(name, identifier,'i_for', &block) + define_method(name) do + return platform.i_text_for identifier.clone unless block_given? + self.send("#{name}_element").text + end + end + alias_method :icon, :i + # # adds two methods - one to retrieve a svg, and another to check # the svg's existence. diff --git a/lib/page-object/elements.rb b/lib/page-object/elements.rb index 1ce271da..4e8df6fc 100644 --- a/lib/page-object/elements.rb +++ b/lib/page-object/elements.rb @@ -20,7 +20,7 @@ def element_class_for(tag_name, type=nil) return type_to_class[type.to_sym] if type tag_to_class[tag_name.to_sym] || ::PageObject::Elements::Element end - + end end end @@ -56,5 +56,6 @@ def element_class_for(tag_name, type=nil) require 'page-object/elements/audio' require 'page-object/elements/video' require 'page-object/elements/bold' +require 'page-object/elements/italic' diff --git a/lib/page-object/elements/element.rb b/lib/page-object/elements/element.rb index 64047a90..f402c33b 100644 --- a/lib/page-object/elements/element.rb +++ b/lib/page-object/elements/element.rb @@ -10,7 +10,7 @@ module Elements # class Element include ::PageObject::NestedElements - + attr_reader :element def initialize(element, platform) @@ -40,14 +40,14 @@ def enabled? def disabled? not enabled? end - + # # get the value of the given CSS property # def style(property) element.style property end - + def inspect element.inspect end @@ -97,7 +97,7 @@ def self.selenium_identifier_for identifier return how, what end end - + # @private # delegate calls to driver element def method_missing(*args, &block) @@ -118,7 +118,7 @@ def method_missing(*args, &block) protected def self.should_build_watir_xpath identifier - ['table', 'span', 'div', 'td', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'label', 'area', 'canvas', 'audio', 'video', 'b'].include? identifier[:tag_name] and identifier[:name] + ['table', 'span', 'div', 'td', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'label', 'area', 'canvas', 'audio', 'video', 'b', 'i'].include? identifier[:tag_name] and identifier[:name] end def self.build_xpath_for identifier diff --git a/lib/page-object/elements/italic.rb b/lib/page-object/elements/italic.rb new file mode 100644 index 00000000..997063f2 --- /dev/null +++ b/lib/page-object/elements/italic.rb @@ -0,0 +1,11 @@ +module PageObject + module Elements + class Italic < Element + + end + + ::PageObject::Elements.tag_to_class[:i] = ::PageObject::Elements::Italic + + + end +end diff --git a/lib/page-object/locator_generator.rb b/lib/page-object/locator_generator.rb index a8e9d459..da346617 100644 --- a/lib/page-object/locator_generator.rb +++ b/lib/page-object/locator_generator.rb @@ -103,6 +103,7 @@ module LocatorGenerator :audio, :video, :b, + :i, :svg] def self.generate_locators(target) diff --git a/lib/page-object/platforms/selenium_webdriver/page_object.rb b/lib/page-object/platforms/selenium_webdriver/page_object.rb index db80cff2..2f805419 100644 --- a/lib/page-object/platforms/selenium_webdriver/page_object.rb +++ b/lib/page-object/platforms/selenium_webdriver/page_object.rb @@ -1055,7 +1055,7 @@ def b_text_for(identifier) end # - # platform method to retrieve the h1 element + # platform method to retrieve the b element # See PageObject::Accessors#b # def b_for(identifier) @@ -1069,6 +1069,31 @@ def bs_for(identifier) find_selenium_elements(identifier, Elements::Bold, 'b') end + # + # platform method to retrieve the text from a i + # See PageObject::Accessors#i + # + def i_text_for(identifier) + process_selenium_call(identifier, Elements::Italic, 'i') do |how, what| + @browser.find_element(how, what).text + end + end + + # + # platform method to retrieve the i element + # See PageObject::Accessors#i + # + def i_for(identifier) + find_selenium_element(identifier, Elements::Italic, 'i') + end + + # + # platform method to retrieve all i elements + # + def is_for(identifier) + find_selenium_elements(identifier, Elements::Italic, 'i') + end + private def process_selenium_call(identifier, type, tag, other=nil) diff --git a/lib/page-object/platforms/watir_webdriver/page_object.rb b/lib/page-object/platforms/watir_webdriver/page_object.rb index 1a2e0cac..60541f79 100644 --- a/lib/page-object/platforms/watir_webdriver/page_object.rb +++ b/lib/page-object/platforms/watir_webdriver/page_object.rb @@ -25,7 +25,7 @@ def initialize(browser) def navigate_to(url) @browser.goto url end - + # # platform method to get the current url # See PageObject#current_url @@ -118,7 +118,7 @@ def prompt(answer, frame=nil, &block) def execute_script(script, *args) @browser.execute_script(script, *args) end - + # # platform method to handle attaching to a running window # See PageObject#attach_to_window @@ -132,7 +132,7 @@ def element_with_focus element = browser.execute_script("return document.activeElement") type = element.type.to_sym if element.tag_name.to_sym == :input cls = ::PageObject::Elements.element_class_for(element.tag_name, type) - cls.new(element, :platform => :watir_webdriver) + cls.new(element, :platform => :watir_webdriver) end # @@ -144,7 +144,7 @@ def in_frame(identifier, frame=nil, &block) frame << {frame: identifier} block.call(frame) end - + # # platform method to switch to an iframe and execute a block # See PageObject#in_frame @@ -154,7 +154,7 @@ def in_iframe(identifier, frame=nil, &block) frame << {iframe: identifier} block.call(frame) end - + # # platform method to refresh the page # See PageObject#refresh @@ -162,7 +162,7 @@ def in_iframe(identifier, frame=nil, &block) def refresh @browser.refresh end - + # # platform method to go back to the previous page # See PageObject#back @@ -170,7 +170,7 @@ def refresh def back @browser.back end - + # # platform method to go forward to the next page # See PageObject#forward @@ -178,7 +178,7 @@ def back def forward @browser.forward end - + # # platform method to clear the cookies from the browser # See PageObject#clear_cookies @@ -210,7 +210,7 @@ def text_field_value_for(identifier) def text_field_value_set(identifier, value) process_watir_call("text_field(identifier).set(value)", Elements::TextField, identifier, value) end - + # # platform method to retrieve a text field element # See PageObject::Accessors#text_field @@ -645,7 +645,7 @@ def ordered_list_text_for(identifier) def ordered_list_for(identifier) find_watir_element("ol(identifier)", Elements::OrderedList, identifier, 'ol') end - + # # platform method to retrieve an array of ordered lists # @@ -660,14 +660,14 @@ def ordered_lists_for(identifier) def h1_text_for(identifier) process_watir_call("h1(identifier).text", Elements::Heading, identifier, nil, 'h1') end - + # # platform method to retrieve the h1 element # See PageObject::Accessors#h1 # def h1_for(identifier) find_watir_element("h1(identifier)", Elements::Heading, identifier, 'h1') - end + end # # platform method to retrieve an array of h1s @@ -683,14 +683,14 @@ def h1s_for(identifier) def h2_text_for(identifier) process_watir_call("h2(identifier).text", Elements::Heading, identifier, nil, 'h2') end - + # # platform method to retrieve the h2 element # See PageObject::Accessors#h2 # def h2_for(identifier) find_watir_element("h2(identifier)", Elements::Heading, identifier, 'h2') - end + end # # platform method to retrieve an array of h2s @@ -706,14 +706,14 @@ def h2s_for(identifier) def h3_text_for(identifier) process_watir_call("h3(identifier).text", Elements::Heading, identifier, nil, 'h3') end - + # # platform method to retrieve the h3 element # See PageObject::Accessors#h3 # def h3_for(identifier) find_watir_element("h3(identifier)", Elements::Heading, identifier, 'h3') - end + end # # platform method to retrieve an array of h3s @@ -729,14 +729,14 @@ def h3s_for(identifier) def h4_text_for(identifier) process_watir_call("h4(identifier).text", Elements::Heading, identifier, nil, 'h4') end - + # # platform method to retrieve the h4 element # See PageObject::Accessors#h4 # def h4_for(identifier) find_watir_element("h4(identifier)", Elements::Heading, identifier, 'h4') - end + end # # platform method to retrieve an array of h4s @@ -752,14 +752,14 @@ def h4s_for(identifier) def h5_text_for(identifier) process_watir_call("h5(identifier).text", Elements::Heading, identifier, nil, 'h5') end - + # # platform method to retrieve the h5 element # See PageObject::Accessors#h5 # def h5_for(identifier) find_watir_element("h5(identifier)", Elements::Heading, identifier, 'h5') - end + end # # platform method to retrieve an array of h5s @@ -775,14 +775,14 @@ def h5s_for(identifier) def h6_text_for(identifier) process_watir_call("h6(identifier).text", Elements::Heading, identifier, nil, 'h6') end - + # # platform method to retrieve the h6 element # See PageObject::Accessors#h6 # def h6_for(identifier) find_watir_element("h6(identifier)", Elements::Heading, identifier, 'h6') - end + end # # platform method to retrieve an array of h6s @@ -798,7 +798,7 @@ def h6s_for(identifier) def paragraph_text_for(identifier) process_watir_call("p(identifier).text", Elements::Paragraph, identifier, nil, 'p') end - + # # platform method to retrieve the paragraph element # See PageObject::Accessors#paragraph @@ -963,7 +963,7 @@ def pages_for(identifier, page_class) def svg_for(identifier) find_watir_element("element(identifier)", Elements::Element, identifier) end - + # # platform method to return an array of svg elements # @@ -981,7 +981,7 @@ def b_text_for(identifier) # # platform method to retrieve the b element - # See PageObject::Accessors#h1 + # See PageObject::Accessors#b # def b_for(identifier) find_watir_element("b(identifier)", Elements::Bold, identifier, 'b') @@ -993,7 +993,30 @@ def b_for(identifier) def bs_for(identifier) find_watir_elements("bs(identifier)", Elements::Bold, identifier, 'b') end - + + # + # platform method to retrieve the text for a i + # See PageObject::Accessors#i + # + def i_text_for(identifier) + process_watir_call("i(identifier).text", Elements::Italic, identifier, nil, 'i') + end + + # + # platform method to retrieve the i element + # See PageObject::Accessors#i + # + def i_for(identifier) + find_watir_element("i(identifier)", Elements::Italic, identifier, 'i') + end + + # + # platform method to retrieve an array of is + # + def is_for(identifier) + find_watir_elements("is(identifier)", Elements::Italic, identifier, 'i') + end + private def find_watir_elements(the_call, type, identifier, tag_name=nil) @@ -1064,7 +1087,7 @@ def nested_frames(frame_identifiers) end def switch_to_default_content(frame_identifiers) - @browser.wd.switch_to.default_content unless frame_identifiers.nil? + @browser.wd.switch_to.default_content unless frame_identifiers.nil? end def switch_to_frame(frame_identifiers) @@ -1074,7 +1097,7 @@ def switch_to_frame(frame_identifiers) value = frame_id.values.first @browser.wd.switch_to.frame(value) end - end + end end end end diff --git a/spec/page-object/element_locators_spec.rb b/spec/page-object/element_locators_spec.rb index 6be57a7e..86b36d22 100644 --- a/spec/page-object/element_locators_spec.rb +++ b/spec/page-object/element_locators_spec.rb @@ -10,7 +10,7 @@ class ElementLocatorsTestPageObject context "when using Watir" do let(:watir_browser) { mock_watir_browser } let(:watir_page_object) { ElementLocatorsTestPageObject.new(watir_browser) } - + it "should find a button element" do expect(watir_browser).to receive(:button).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.button_element(:id => 'blah') @@ -32,7 +32,7 @@ class ElementLocatorsTestPageObject expect(watir_browser).to receive(:buttons).with({}).and_return([watir_browser]) watir_page_object.button_elements end - + it "should find a text field element" do expect(watir_browser).to receive(:text_field).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.text_field_element(:id => 'blah') @@ -56,7 +56,7 @@ class ElementLocatorsTestPageObject expect(watir_browser).to receive(:tag_name).and_return('input') watir_page_object.text_field_elements end - + it "should find a hidden field element" do expect(watir_browser).to receive(:hidden).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.hidden_field_element(:id => 'blah') @@ -78,7 +78,7 @@ class ElementLocatorsTestPageObject expect(watir_browser).to receive(:hiddens).with({}).and_return([watir_browser]) watir_page_object.hidden_field_elements end - + it "should find a text area element" do expect(watir_browser).to receive(:textarea).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.text_area_element(:id => 'blah') @@ -93,14 +93,14 @@ class ElementLocatorsTestPageObject it "should find all text area elements" do expect(watir_browser).to receive(:textareas).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.text_area_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::TextArea + expect(elements[0]).to be_instance_of PageObject::Elements::TextArea end it "should find all text area elements using no identifier" do expect(watir_browser).to receive(:textareas).with({}).and_return([watir_browser]) watir_page_object.text_area_elements end - + it "should find a select list element" do expect(watir_browser).to receive(:select_list).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.select_list_element(:id => 'blah') @@ -115,14 +115,14 @@ class ElementLocatorsTestPageObject it "should find all select list elements" do expect(watir_browser).to receive(:select_lists).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.select_list_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::SelectList + expect(elements[0]).to be_instance_of PageObject::Elements::SelectList end it "should find all select list elements using no identifier" do expect(watir_browser).to receive(:select_lists).with({}).and_return([watir_browser]) watir_page_object.select_list_elements end - + it "should find a link element" do expect(watir_browser).to receive(:link).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.link_element(:id => 'blah') @@ -137,14 +137,14 @@ class ElementLocatorsTestPageObject it "should find all link elements" do expect(watir_browser).to receive(:links).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.link_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Link + expect(elements[0]).to be_instance_of PageObject::Elements::Link end it "should find all links using no identifier" do expect(watir_browser).to receive(:links).with({}).and_return([watir_browser]) watir_page_object.link_elements end - + it "should find a check box" do expect(watir_browser).to receive(:checkbox).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.checkbox_element(:id => 'blah') @@ -159,14 +159,14 @@ class ElementLocatorsTestPageObject it "should find all check box elements" do expect(watir_browser).to receive(:checkboxes).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.checkbox_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::CheckBox + expect(elements[0]).to be_instance_of PageObject::Elements::CheckBox end it "should find all check box elements using no identifier" do expect(watir_browser).to receive(:checkboxes).with({}).and_return([watir_browser]) watir_page_object.checkbox_elements end - + it "should find a radio button" do expect(watir_browser).to receive(:radio).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.radio_button_element(:id => 'blah') @@ -181,14 +181,14 @@ class ElementLocatorsTestPageObject it "should find all radio buttons" do expect(watir_browser).to receive(:radios).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.radio_button_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::RadioButton + expect(elements[0]).to be_instance_of PageObject::Elements::RadioButton end it "should find all radio buttons using no identifier" do expect(watir_browser).to receive(:radios).with({}).and_return([watir_browser]) watir_page_object.radio_button_elements end - + it "should find a div" do expect(watir_browser).to receive(:div).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.div_element(:id => 'blah') @@ -203,14 +203,14 @@ class ElementLocatorsTestPageObject it "should find all div elements" do expect(watir_browser).to receive(:divs).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.div_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Div + expect(elements[0]).to be_instance_of PageObject::Elements::Div end it "should find all div elements using no identifier" do expect(watir_browser).to receive(:divs).with({}).and_return([watir_browser]) watir_page_object.div_elements end - + it "should find a span" do expect(watir_browser).to receive(:span).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.span_element(:id => 'blah') @@ -225,14 +225,14 @@ class ElementLocatorsTestPageObject it "should find all span elements" do expect(watir_browser).to receive(:spans).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.span_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Span + expect(elements[0]).to be_instance_of PageObject::Elements::Span end it "should find all span elements using no identifier" do expect(watir_browser).to receive(:spans).with({}).and_return([watir_browser]) watir_page_object.span_elements end - + it "should find a table" do expect(watir_browser).to receive(:table).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.table_element(:id => 'blah') @@ -247,7 +247,7 @@ class ElementLocatorsTestPageObject it "should find all table elements" do expect(watir_browser).to receive(:tables).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.table_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Table + expect(elements[0]).to be_instance_of PageObject::Elements::Table end it "should find all table elements using no identifier" do @@ -298,7 +298,7 @@ class ElementLocatorsTestPageObject expect(watir_browser).to receive(:trs).with({}).and_return([watir_browser]) watir_page_object.row_elements end - + it "should find an image" do expect(watir_browser).to receive(:image).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.image_element(:id => 'blah') @@ -320,7 +320,7 @@ class ElementLocatorsTestPageObject expect(watir_browser).to receive(:images).with({}).and_return([watir_browser]) watir_page_object.image_elements end - + it "should find a form" do expect(watir_browser).to receive(:form).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.form_element(:id => 'blah') @@ -342,7 +342,7 @@ class ElementLocatorsTestPageObject expect(watir_browser).to receive(:forms).with({}).and_return([watir_browser]) watir_page_object.form_elements end - + it "should find a list item" do expect(watir_browser).to receive(:li).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.list_item_element(:id => 'blah') @@ -357,14 +357,14 @@ class ElementLocatorsTestPageObject it "should find all list items" do expect(watir_browser).to receive(:lis).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.list_item_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::ListItem + expect(elements[0]).to be_instance_of PageObject::Elements::ListItem end it "should find all list items using no parameter" do expect(watir_browser).to receive(:lis).with({}).and_return([watir_browser]) watir_page_object.list_item_elements end - + it "should find an unordered list" do expect(watir_browser).to receive(:ul).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.unordered_list_element(:id => 'blah') @@ -379,14 +379,14 @@ class ElementLocatorsTestPageObject it "should find all unordered lists" do expect(watir_browser).to receive(:uls).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.unordered_list_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::UnorderedList + expect(elements[0]).to be_instance_of PageObject::Elements::UnorderedList end it "should find all unordered lists using no parameters" do expect(watir_browser).to receive(:uls).with({}).and_return([watir_browser]) watir_page_object.unordered_list_elements end - + it "should find an ordered list" do expect(watir_browser).to receive(:ol).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.ordered_list_element(:id => 'blah') @@ -401,14 +401,14 @@ class ElementLocatorsTestPageObject it "should find all ordered lists" do expect(watir_browser).to receive(:ols).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.ordered_list_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::OrderedList + expect(elements[0]).to be_instance_of PageObject::Elements::OrderedList end it "should find all orderd lists using no parameters" do expect(watir_browser).to receive(:ols).with({}).and_return([watir_browser]) watir_page_object.ordered_list_elements end - + it "should find a h1 element" do expect(watir_browser).to receive(:h1).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.h1_element(:id => 'blah') @@ -423,7 +423,7 @@ class ElementLocatorsTestPageObject it "should find all h1 elements" do expect(watir_browser).to receive(:h1s).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.h1_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find all h1 elements using no parameters" do @@ -445,7 +445,7 @@ class ElementLocatorsTestPageObject it "should find all h2 elements" do expect(watir_browser).to receive(:h2s).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.h2_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find all h2 elements using no identifier" do @@ -467,7 +467,7 @@ class ElementLocatorsTestPageObject it "should find all h3 elements" do expect(watir_browser).to receive(:h3s).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.h3_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find all h3 elements using no identifiers" do @@ -489,7 +489,7 @@ class ElementLocatorsTestPageObject it "should find all h4 elements" do expect(watir_browser).to receive(:h4s).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.h4_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find all h4 elements using no identifier" do @@ -511,7 +511,7 @@ class ElementLocatorsTestPageObject it "should find all h5 elements" do expect(watir_browser).to receive(:h5s).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.h5_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find all h5 elements using no identifier" do @@ -533,7 +533,7 @@ class ElementLocatorsTestPageObject it "should find all h6 elements" do expect(watir_browser).to receive(:h6s).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.h6_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find all h6 elements using no identifier" do @@ -555,7 +555,7 @@ class ElementLocatorsTestPageObject it "should find all paragraph elements" do expect(watir_browser).to receive(:ps).with(:id => 'blah').and_return([watir_browser]) elements = watir_page_object.paragraph_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Paragraph + expect(elements[0]).to be_instance_of PageObject::Elements::Paragraph end it "should find all paragraph elements using no identifier" do @@ -628,7 +628,7 @@ class ElementLocatorsTestPageObject expect(watir_browser).to receive(:areas).with({}).and_return([watir_browser]) watir_page_object.area_elements end - + it "should find a canvas element" do expect(watir_browser).to receive(:canvas).with(:id => 'blah').and_return(watir_browser) element = watir_page_object.canvas_element(:id => 'blah') @@ -727,12 +727,34 @@ class ElementLocatorsTestPageObject expect(watir_browser).to receive(:bs).with({}).and_return([watir_browser]) watir_page_object.b_elements end + + it "should find an i element" do + expect(watir_browser).to receive(:i).with(:id => 'blah').and_return(watir_browser) + element = watir_page_object.i_element(:id => 'blah') + expect(element).to be_instance_of PageObject::Elements::Italic + end + + it "should find an i element using a default identifier" do + expect(watir_browser).to receive(:i).with(:index => 0).and_return(watir_browser) + watir_page_object.i_element + end + + it "should find all i elements" do + expect(watir_browser).to receive(:is).with(:id => 'blah').and_return([watir_browser]) + elements = watir_page_object.i_elements(:id => 'blah') + expect(elements[0]).to be_instance_of PageObject::Elements::Italic + end + + it "should find all i elements using no parameters" do + expect(watir_browser).to receive(:is).with({}).and_return([watir_browser]) + watir_page_object.i_elements + end end context "when using Selenium" do let(:selenium_browser) { mock_selenium_browser } let(:selenium_page_object) { ElementLocatorsTestPageObject.new(selenium_browser) } - + it "should find a button element" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.button_element(:id => 'blah') @@ -766,10 +788,10 @@ class ElementLocatorsTestPageObject it "should find all hidden field elements" do expect(selenium_browser).to receive(:find_elements).with(:id, "blah").and_return([selenium_browser]) elements = selenium_page_object.hidden_field_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::HiddenField + expect(elements[0]).to be_instance_of PageObject::Elements::HiddenField end - + it "should find a text area element" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.text_area_element(:id => 'blah') @@ -779,9 +801,9 @@ class ElementLocatorsTestPageObject it "should find all text area elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.text_area_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::TextArea + expect(elements[0]).to be_instance_of PageObject::Elements::TextArea end - + it "should find a select list element" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.select_list_element(:id => 'blah') @@ -791,9 +813,9 @@ class ElementLocatorsTestPageObject it "should find all select list elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.select_list_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::SelectList + expect(elements[0]).to be_instance_of PageObject::Elements::SelectList end - + it "should find a link element" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.link_element(:id => 'blah') @@ -803,9 +825,9 @@ class ElementLocatorsTestPageObject it "should find all link elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.link_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Link + expect(elements[0]).to be_instance_of PageObject::Elements::Link end - + it "should find a check box" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.checkbox_element(:id => 'blah') @@ -815,9 +837,9 @@ class ElementLocatorsTestPageObject it "should find all checkbox elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.checkbox_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::CheckBox + expect(elements[0]).to be_instance_of PageObject::Elements::CheckBox end - + it "should find a radio button" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.radio_button_element(:id => 'blah') @@ -827,9 +849,9 @@ class ElementLocatorsTestPageObject it "should find all radio button elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.radio_button_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::RadioButton + expect(elements[0]).to be_instance_of PageObject::Elements::RadioButton end - + it "should find a div" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.div_element(:id => 'blah') @@ -839,9 +861,9 @@ class ElementLocatorsTestPageObject it "should find all div elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.div_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Div + expect(elements[0]).to be_instance_of PageObject::Elements::Div end - + it "should find a span" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.span_element(:id => 'blah') @@ -851,21 +873,21 @@ class ElementLocatorsTestPageObject it "should find all span elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.span_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Span + expect(elements[0]).to be_instance_of PageObject::Elements::Span end - + it "should find a table" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.table_element(:id => 'blah') expect(element).to be_instance_of PageObject::Elements::Table end - + it "should find all table elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.table_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Table + expect(elements[0]).to be_instance_of PageObject::Elements::Table end - + it "should find a table cell" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.cell_element(:id => 'blah') @@ -875,7 +897,7 @@ class ElementLocatorsTestPageObject it "should find all table cell elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.cell_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::TableCell + expect(elements[0]).to be_instance_of PageObject::Elements::TableCell end it "should find an image" do @@ -889,13 +911,13 @@ class ElementLocatorsTestPageObject elements = selenium_page_object.image_elements(:id => 'blah') expect(elements[0]).to be_instance_of PageObject::Elements::Image end - + it "should find a form" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.form_element(:id => 'blah') expect(element).to be_instance_of PageObject::Elements::Form end - + it "should find all forms" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.form_elements(:id => 'blah') @@ -911,9 +933,9 @@ class ElementLocatorsTestPageObject it "should find all list items" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) element = selenium_page_object.list_item_elements(:id => 'blah') - expect(element[0]).to be_instance_of PageObject::Elements::ListItem + expect(element[0]).to be_instance_of PageObject::Elements::ListItem end - + it "should find an unordered list" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.unordered_list_element(:id => 'blah') @@ -923,9 +945,9 @@ class ElementLocatorsTestPageObject it "should find all unordered lists" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.unordered_list_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::UnorderedList + expect(elements[0]).to be_instance_of PageObject::Elements::UnorderedList end - + it "should find an ordered list" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.ordered_list_element(:id => 'blah') @@ -935,9 +957,9 @@ class ElementLocatorsTestPageObject it "should find all orderd list elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.ordered_list_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::OrderedList + expect(elements[0]).to be_instance_of PageObject::Elements::OrderedList end - + it "should find a h1 element" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) element = selenium_page_object.h1_element(:id => 'blah') @@ -947,7 +969,7 @@ class ElementLocatorsTestPageObject it "should find all h1 elements" do expect(selenium_browser).to receive(:find_elements).with(:id, "blah").and_return([selenium_browser]) elements = selenium_page_object.h1_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find a h2 element" do @@ -959,7 +981,7 @@ class ElementLocatorsTestPageObject it "should find all h2 elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.h2_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find a h3 element" do @@ -971,7 +993,7 @@ class ElementLocatorsTestPageObject it "should find all h3 elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.h3_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find a h4 element" do @@ -995,7 +1017,7 @@ class ElementLocatorsTestPageObject it "should find all h5 elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.h5_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find a h6 element" do @@ -1007,7 +1029,7 @@ class ElementLocatorsTestPageObject it "should find all h6 elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.h6_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Heading + expect(elements[0]).to be_instance_of PageObject::Elements::Heading end it "should find a paragraph element" do @@ -1019,7 +1041,7 @@ class ElementLocatorsTestPageObject it "should find all paragraph elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.paragraph_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Paragraph + expect(elements[0]).to be_instance_of PageObject::Elements::Paragraph end it "should find a label" do @@ -1032,7 +1054,7 @@ class ElementLocatorsTestPageObject expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) elements = selenium_page_object.label_elements(:id => 'blah') expect(elements[0]).to be_instance_of PageObject::Elements::Label - end + end it "should find a file field element" do expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser) @@ -1105,17 +1127,17 @@ class ElementLocatorsTestPageObject expect(selenium_browser).to receive(:find_elements).with(:tag_name, 'audio').and_return([selenium_browser]) selenium_page_object.audio_elements end - it "should find a b element" do + it "should find an i element" do expect(selenium_browser).to receive(:find_element).with(:id,'blah').and_return(selenium_browser) - element = selenium_page_object.b_element(:id => 'blah') - expect(element).to be_instance_of PageObject::Elements::Bold + element = selenium_page_object.i_element(:id => 'blah') + expect(element).to be_instance_of PageObject::Elements::Italic end - it "should find all b elements" do + it "should find all i elements" do expect(selenium_browser).to receive(:find_elements).with(:id, 'blah').and_return([selenium_browser]) - elements = selenium_page_object.b_elements(:id => 'blah') - expect(elements[0]).to be_instance_of PageObject::Elements::Bold + elements = selenium_page_object.i_elements(:id => 'blah') + expect(elements[0]).to be_instance_of PageObject::Elements::Italic end end diff --git a/spec/page-object/elements/italic_spec.rb b/spec/page-object/elements/italic_spec.rb new file mode 100644 index 00000000..954dbd56 --- /dev/null +++ b/spec/page-object/elements/italic_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' +require 'page-object/elements' + +describe PageObject::Elements::Italic do + let(:italic) { PageObject::Elements::Italic } + + describe "when mapping how to find an element" do + it "should map watir types to same" do + [:class, :id, :index, :name, :xpath].each do |t| + identifier = italic.watir_identifier_for t => 'value' + expect(identifier.keys.first).to eql t + end + end + + it "should map selenium types to same" do + [:class, :id, :index, :name, :xpath].each do |t| + key, value = italic.selenium_identifier_for t => 'value' + expect(key).to eql t + end + end + end + + describe "interface" do + + it "should register with tag :i" do + expect(::PageObject::Elements.element_class_for(:i)).to eql ::PageObject::Elements::Italic + end + end +end diff --git a/spec/page-object/selenium_accessors_spec.rb b/spec/page-object/selenium_accessors_spec.rb index 188f80f4..9bebeef4 100644 --- a/spec/page-object/selenium_accessors_spec.rb +++ b/spec/page-object/selenium_accessors_spec.rb @@ -35,7 +35,8 @@ class SeleniumAccessorsTestPageObject canvas(:my_canvas, :id => 'canvas') audio(:acdc, :id => 'audio_id') video(:movie, :id => 'movie_id') - b(:bold, :id=>'bold') + b(:bold, :id => 'bold') + i(:italic, :id => 'italic') end class SeleniumBlockPageObject @@ -134,13 +135,17 @@ class SeleniumBlockPageObject b :bold do |element| 'b' end + + i :italic do |element| + 'i' + end end describe PageObject::Accessors do let(:selenium_browser) { mock_selenium_browser } let(:selenium_page_object) { SeleniumAccessorsTestPageObject.new(selenium_browser) } let(:block_page_object) { SeleniumBlockPageObject.new(selenium_browser) } - + before(:each) do allow(selenium_browser).to receive(:switch_to).and_return(selenium_browser) allow(selenium_browser).to receive(:default_content) @@ -241,7 +246,7 @@ class SeleniumBlockPageObject element = selenium_page_object.state_element expect(element).to be_instance_of PageObject::Elements::SelectList end - + it "should return list of selection options" do option1 = double('option') option2 = double('option') @@ -251,10 +256,10 @@ class SeleniumBlockPageObject select_element = double("select") expect(select_element).to receive(:options).twice.and_return([option1, option2]) expect(selenium_page_object).to receive(:state_element).and_return(select_element) - + expect(selenium_page_object.state_options).to eql ["CA","OH"] end - + end @@ -417,21 +422,21 @@ class SeleniumBlockPageObject expect(element).to be_instance_of PageObject::Elements::OrderedList end end - + describe "h1 accessors" do it "should retrieve the text from the h1" do expect(selenium_browser).to receive(:find_element).and_return(selenium_browser) expect(selenium_browser).to receive(:text).and_return("value") expect(selenium_page_object.heading1).to eql "value" end - + it "should retrieve the element from the page" do expect(selenium_browser).to receive(:find_element).and_return(selenium_browser) element = selenium_page_object.heading1_element expect(element).to be_instance_of PageObject::Elements::Heading end end - + describe "h2 accessors" do it "should retrieve the text from the h2" do expect(selenium_browser).to receive(:find_element).and_return(selenium_browser) @@ -567,7 +572,7 @@ class SeleniumBlockPageObject end end end - + describe "audio accessors" do context "when called on a page object" do it "should generate accessor methods" do @@ -606,4 +611,18 @@ class SeleniumBlockPageObject end end + describe "i accessors" do + it "should retrieve the text from the i" do + expect(selenium_browser).to receive(:find_element).and_return(selenium_browser) + expect(selenium_browser).to receive(:text).and_return("value") + expect(selenium_page_object.italic).to eql "value" + end + + it "should retrieve the element from the page" do + expect(selenium_browser).to receive(:find_element).and_return(selenium_browser) + element = selenium_page_object.italic_element + expect(element).to be_instance_of PageObject::Elements::Italic + end + end + end diff --git a/spec/page-object/watir_accessors_spec.rb b/spec/page-object/watir_accessors_spec.rb index 5a742a75..f8c38b02 100644 --- a/spec/page-object/watir_accessors_spec.rb +++ b/spec/page-object/watir_accessors_spec.rb @@ -35,7 +35,8 @@ class WatirAccessorsTestPageObject canvas(:my_canvas, :id => 'canvas_id') audio(:acdc, :id => 'audio_id') video(:movie, :id => 'video_id') - b(:bold,:id=>'bold') + b(:bold, :id => 'bold') + i(:italic, :id => 'italic') end class WatirBlockPageObject @@ -133,6 +134,9 @@ class WatirBlockPageObject b :bold do |element| "b" end + i :italic do |element| + "i" + end end describe PageObject::Accessors do @@ -1158,4 +1162,29 @@ def mock_driver_for(tag) end end + describe "i accessors" do + context "when called on a page object" do + it "should generate accessor methods" do + expect(watir_page_object).to respond_to(:italic) + expect(watir_page_object).to respond_to(:italic_element) + end + + it "should call a block on the element method when present" do + expect(block_page_object.italic_element).to eql "i" + end + end + + it "should retrieve the text from the i" do + expect(watir_browser).to receive(:i).and_return(watir_browser) + expect(watir_browser).to receive(:text).and_return("value") + expect(watir_page_object.italic).to eql "value" + end + + it "should retrieve the element from the page" do + expect(watir_browser).to receive(:i).and_return(watir_browser) + element = watir_page_object.italic_element + expect(element).to be_instance_of PageObject::Elements::Italic + end + end + end