Module: PageObject::Accessors
- Defined in:
- lib/page-object/accessors.rb
Overview
Contains the class level methods that are inserted into your page objects when you include the PageObject module. These methods will generate another set of methods that provide access to the elements on the web pages.
Instance Method Summary collapse
-
#area(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to click the area, another to return the area element, and another to check the area’s existence.
-
#audio(name, identifier = {:index => 0}, &block) ⇒ Object
adds two methods - one to return the audio element and another to check the audio’s existence.
-
#b(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a b element, another to retrieve a b element, and another to check for it’s existence.
-
#button(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to click a button, another to return the button element, and another to check the button’s existence.
-
#canvas(name, identifier = {:index => 0}, &block) ⇒ Object
adds two methods - one to return the canvas element and another to check the canvas’s existence.
-
#cell(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #td)
adds three methods - one to retrieve the text from a table cell, another to return the table cell element, and another to check the cell’s existence.
-
#checkbox(name, identifier = {:index => 0}, &block) ⇒ Object
adds five methods - one to check, another to uncheck, another to return the state of a checkbox, another to return a PageObject::Elements::CheckBox object representing the checkbox, and a final method to check the checkbox’s existence.
-
#date_field(name, identifier = {:index => 0}, &block) ⇒ Object
adds four methods to the page object - one to set value in a date field, another to retrieve value from a date field, another to return the date field element, another to check the date field’s existence.
-
#div(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text from a div, another to return the div element, and another to check the div’s existence.
-
#element(name, tag = :element, identifier = { :index => 0 }, &block) ⇒ Object
adds three methods - one to retrieve the text of an element, another to retrieve an element, and another to check the element’s existence.
-
#elements(name, tag = :element, identifier = {:index => 0}, &block) ⇒ Object
adds a method to return a collection of generic Element objects for a specific tag.
-
#expected_element(element_name, timeout = ::PageObject.default_element_wait) ⇒ boolean
Creates a method that provides a way to initialize a page based upon an expected element.
-
#expected_element_visible(element_name, timeout = ::PageObject.default_element_wait, check_visible = false) ⇒ boolean
Creates a method that provides a way to initialize a page based upon an expected element to become visible.
-
#expected_title(expected_title) ⇒ boolean
Creates a method that compares the expected_title of a page against the actual.
-
#file_field(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to set the file for a file field, another to retrieve the file field element, and another to check it’s existence.
-
#form(name, identifier = {:index => 0}, &block) ⇒ Object
adds two methods - one to retrieve the form element, and another to check the form’s existence.
-
#h1(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h1 element, another to retrieve a h1 element, and another to check for it’s existence.
-
#h2(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h2 element, another to retrieve a h2 element, and another to check for it’s existence.
-
#h3(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h3 element, another to return a h3 element, and another to check for it’s existence.
-
#h4(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h4 element, another to return a h4 element, and another to check for it’s existence.
-
#h5(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h5 element, another to return a h5 element, and another to check for it’s existence.
-
#h6(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h6 element, another to return a h6 element, and another to check for it’s existence.
-
#hidden_field(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #hidden)
adds three methods to the page object - one to get the text from a hidden field, another to retrieve the hidden field element, and another to check the hidden field’s existence.
-
#i(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #icon)
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.
-
#image(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #img)
adds three methods - one to retrieve the image element, another to check the load status of the image, and another to check the image’s existence.
-
#in_frame(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within a frame .
-
#in_iframe(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within an iframe.
-
#indexed_property(name, identifier_list) ⇒ Object
adds a method that will return an indexed property.
-
#label(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text from a label, another to return the label element, and another to check the label’s existence.
-
#link(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #a)
adds three methods - one to select a link, another to return a PageObject::Elements::Link object representing the link, and another that checks the link’s existence.
-
#list_item(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #li)
adds three methods - one to retrieve the text from a list item, another to return the list item element, and another to check the list item’s existence.
-
#ordered_list(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #ol)
adds three methods - one to return the text within the ordered list, one to retrieve the ordered list element, and another to test it’s existence.
-
#page_section(name, section_class, identifier) ⇒ Object
adds a method to return a page object rooted at an element.
-
#page_sections(name, section_class, identifier) ⇒ Object
adds a method to return a collection of page objects rooted at elements.
-
#page_url(url) ⇒ Object
(also: #direct_url)
Specify the url for the page.
-
#paragraph(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #p)
adds three methods - one to retrieve the text of a paragraph, another to retrieve a paragraph element, and another to check the paragraph’s existence.
-
#params ⇒ Object
Return the params that exist on this page class.
-
#params=(the_params) ⇒ Object
Set some values that can be used within the class.
-
#radio_button(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #radio)
adds four methods - one to select, another to return if a radio button is selected, another method to return a PageObject::Elements::RadioButton object representing the radio button element, and another to check the radio button’s existence.
-
#radio_button_group(name, identifier) ⇒ Object
(also: #radio_group)
adds five methods to help interact with a radio button group - a method to select a radio button in the group by given value/text, a method to return the values of all radio buttons in the group, a method to return if a radio button in the group is selected (will return the text of the selected radio button, if true), a method to return an array of PageObject::Elements::RadioButton objects representing the radio button group, and finally a method to check the existence of the radio button group.
-
#row(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text from a table row, another to return the table row element, and another to check the row’s existence.
-
#select_list(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #select)
adds five methods - one to select an item in a drop-down, another to fetch the currently selected item text, another to retrieve the select list element, another to check the drop down’s existence and another to get all the available options to select from.
-
#span(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text from a span, another to return the span element, and another to check the span’s existence.
- #standard_methods(name, identifier, method, &block) ⇒ Object
-
#svg(name, identifier = {:index => 0}, &block) ⇒ Object
adds two methods - one to retrieve a svg, and another to check the svg’s existence.
-
#table(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to return the text for the table, one to retrieve the table element, and another to check the table’s existence.
-
#text_area(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #textarea)
adds four methods to the page object - one to set text in a text area, another to retrieve text from a text area, another to return the text area element, and another to check the text area’s existence.
-
#text_field(name, identifier = {:index => 0}, &block) ⇒ Object
adds four methods to the page object - one to set text in a text field, another to retrieve text from a text field, another to return the text field element, another to check the text field’s existence.
-
#unordered_list(name, identifier = {:index => 0}, &block) ⇒ Object
(also: #ul)
adds three methods - one to return the text within the unordered list, one to retrieve the unordered list element, and another to check it’s existence.
-
#video(name, identifier = {:index => 0}, &block) ⇒ Object
adds two methods - one to return the video element and another to check the video’s existence.
-
#wait_for_expected_title(expected_title, timeout = ::PageObject.default_element_wait) ⇒ boolean
Creates a method that waits the expected_title of a page to match the actual.
Instance Method Details
#area(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to click the area, another to return the area element, and another to check the area’s existence.
869 870 871 872 873 874 875 |
# File 'lib/page-object/accessors.rb', line 869 def area(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'area_for', &block) define_method(name) do return platform.click_area_for identifier.clone unless block_given? self.send("#{name}_element").click end end |
#audio(name, identifier = {:index => 0}, &block) ⇒ Object
adds two methods - one to return the audio element and another to check the audio’s existence.
905 906 907 |
# File 'lib/page-object/accessors.rb', line 905 def audio(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'audio_for', &block) end |
#b(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a b element, another to retrieve a b element, and another to check for it’s existence.
937 938 939 940 941 942 943 |
# File 'lib/page-object/accessors.rb', line 937 def b(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'b_for', &block) define_method(name) do return platform.b_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#button(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to click a button, another to return the button element, and another to check the button’s existence.
458 459 460 461 462 463 464 |
# File 'lib/page-object/accessors.rb', line 458 def (name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'button_for', &block) define_method(name) do return platform. identifier.clone unless block_given? self.send("#{name}_element").click end end |
#canvas(name, identifier = {:index => 0}, &block) ⇒ Object
adds two methods - one to return the canvas element and another to check the canvas’s existence.
889 890 891 |
# File 'lib/page-object/accessors.rb', line 889 def canvas(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'canvas_for', &block) end |
#cell(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: td
adds three methods - one to retrieve the text from a table cell, another to return the table cell element, and another to check the cell’s existence.
540 541 542 543 544 545 546 |
# File 'lib/page-object/accessors.rb', line 540 def cell(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'cell_for', &block) define_method("#{name}") do return platform.cell_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#checkbox(name, identifier = {:index => 0}, &block) ⇒ Object
adds five methods - one to check, another to uncheck, another to return the state of a checkbox, another to return a PageObject::Elements::CheckBox object representing the checkbox, and a final method to check the checkbox’s existence.
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/page-object/accessors.rb', line 352 def checkbox(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'checkbox_for', &block) define_method("check_#{name}") do return platform.check_checkbox(identifier.clone) unless block_given? self.send("#{name}_element").check end define_method("uncheck_#{name}") do return platform.uncheck_checkbox(identifier.clone) unless block_given? self.send("#{name}_element").uncheck end define_method("#{name}_checked?") do return platform.checkbox_checked?(identifier.clone) unless block_given? self.send("#{name}_element").checked? end end |
#date_field(name, identifier = {:index => 0}, &block) ⇒ Object
adds four methods to the page object - one to set value in a date field, another to retrieve value from a date field, another to return the date field element, another to check the date field’s existence.
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/page-object/accessors.rb', line 222 def date_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'date_field_for', &block) define_method(name) do return platform.date_field_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do |value| return platform.date_field_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").value = value end end |
#div(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text from a div, another to return the div element, and another to check the div’s existence.
478 479 480 481 482 483 484 |
# File 'lib/page-object/accessors.rb', line 478 def div(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'div_for', &block) define_method(name) do return platform.div_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#element(name, tag = :element, identifier = { :index => 0 }, &block) ⇒ Object
adds three methods - one to retrieve the text of an element, another to retrieve an element, and another to check the element’s existence.
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 |
# File 'lib/page-object/accessors.rb', line 996 def element(name, tag=:element, identifier={ :index => 0 }, &block) # # sets tag as element if not defined # if tag.is_a?(Hash) identifier = tag tag = :element end standard_methods(name, identifier, 'element_for', &block) define_method("#{name}") do element = self.send("#{name}_element") %w(Button TextField Radio Hidden CheckBox FileField).each do |klass| next unless element.element.class.to_s == "Watir::#{klass}" self.class.send(klass.gsub(/(.)([A-Z])/,'\1_\2').downcase, name, identifier, &block) return self.send name end element.text end define_method("#{name}_element") do return call_block(&block) if block_given? platform.element_for(tag, identifier.clone) end define_method("#{name}?") do self.send("#{name}_element").exists? end define_method("#{name}=") do |value| element = self.send("#{name}_element") klass = case element.element when Watir::TextField 'text_field' when Watir::TextArea 'text_area' when Watir::Select 'select_list' when Watir::FileField 'file_field' else raise "Can not set a #{element.element} element with #=" end self.class.send(klass, name, identifier, &block) self.send("#{name}=", value) end end |
#elements(name, tag = :element, identifier = {:index => 0}, &block) ⇒ Object
adds a method to return a collection of generic Element objects for a specific tag.
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 |
# File 'lib/page-object/accessors.rb', line 1057 def elements(name, tag=:element, identifier={:index => 0}, &block) # # sets tag as element if not defined # if tag.is_a?(Hash) identifier = tag tag = :element end define_method("#{name}_elements") do return call_block(&block) if block_given? platform.elements_for(tag, identifier.clone) end end |
#expected_element(element_name, timeout = ::PageObject.default_element_wait) ⇒ boolean
Creates a method that provides a way to initialize a page based upon an expected element. This is useful for pages that load dynamic content.
109 110 111 112 113 |
# File 'lib/page-object/accessors.rb', line 109 def expected_element(element_name, timeout=::PageObject.default_element_wait) define_method("has_expected_element?") do self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_present timeout end end |
#expected_element_visible(element_name, timeout = ::PageObject.default_element_wait, check_visible = false) ⇒ boolean
Creates a method that provides a way to initialize a page based upon an expected element to become visible. This is useful for pages that load dynamic content and might have hidden elements that are not shown.
127 128 129 130 131 132 |
# File 'lib/page-object/accessors.rb', line 127 def expected_element_visible(element_name, timeout=::PageObject.default_element_wait, check_visible=false) define_method("has_expected_element_visible?") do self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_present timeout self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_visible timeout end end |
#expected_title(expected_title) ⇒ boolean
Creates a method that compares the expected_title of a page against the actual.
89 90 91 92 93 94 95 96 |
# File 'lib/page-object/accessors.rb', line 89 def expected_title(expected_title) define_method("has_expected_title?") do page_title = title has_expected_title = (expected_title === page_title) raise "Expected title '#{expected_title}' instead of '#{page_title}'" unless has_expected_title has_expected_title end end |
#file_field(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to set the file for a file field, another to retrieve the file field element, and another to check it’s existence.
829 830 831 832 833 834 835 |
# File 'lib/page-object/accessors.rb', line 829 def file_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'file_field_for', &block) define_method("#{name}=") do |value| return platform.file_field_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").value = value end end |
#form(name, identifier = {:index => 0}, &block) ⇒ Object
adds two methods - one to retrieve the form element, and another to check the form’s existence.
605 606 607 |
# File 'lib/page-object/accessors.rb', line 605 def form(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'form_for', &block) end |
#h1(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h1 element, another to retrieve a h1 element, and another to check for it’s existence.
688 689 690 691 692 693 694 |
# File 'lib/page-object/accessors.rb', line 688 def h1(name, identifier={:index => 0}, &block) standard_methods(name, identifier,'h1_for', &block) define_method(name) do return platform.h1_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#h2(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h2 element, another to retrieve a h2 element, and another to check for it’s existence.
708 709 710 711 712 713 714 |
# File 'lib/page-object/accessors.rb', line 708 def h2(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h2_for', &block) define_method(name) do return platform.h2_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#h3(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h3 element, another to return a h3 element, and another to check for it’s existence.
728 729 730 731 732 733 734 |
# File 'lib/page-object/accessors.rb', line 728 def h3(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h3_for', &block) define_method(name) do return platform.h3_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#h4(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h4 element, another to return a h4 element, and another to check for it’s existence.
748 749 750 751 752 753 754 |
# File 'lib/page-object/accessors.rb', line 748 def h4(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h4_for', &block) define_method(name) do return platform.h4_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#h5(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h5 element, another to return a h5 element, and another to check for it’s existence.
768 769 770 771 772 773 774 |
# File 'lib/page-object/accessors.rb', line 768 def h5(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h5_for', &block) define_method(name) do return platform.h5_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#h6(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text of a h6 element, another to return a h6 element, and another to check for it’s existence.
788 789 790 791 792 793 794 |
# File 'lib/page-object/accessors.rb', line 788 def h6(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'h6_for', &block) define_method(name) do return platform.h6_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#hidden_field(name, identifier = {:index => 0}, &block) ⇒ Object Also known as:
adds three methods to the page object - one to get the text from a hidden field, another to retrieve the hidden field element, and another to check the hidden field’s existence.
247 248 249 250 251 252 253 |
# File 'lib/page-object/accessors.rb', line 247 def hidden_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'hidden_field_for', &block) define_method(name) do return platform.hidden_field_value_for identifier.clone unless block_given? self.send("#{name}_element").value end end |
#i(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: icon
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.
957 958 959 960 961 962 963 |
# File 'lib/page-object/accessors.rb', line 957 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 |
#image(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: img
adds three methods - one to retrieve the image element, another to check the load status of the image, and another to check the image’s existence.
584 585 586 587 588 589 590 |
# File 'lib/page-object/accessors.rb', line 584 def image(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'image_for', &block) define_method("#{name}_loaded?") do return platform.image_loaded_for identifier.clone unless block_given? self.send("#{name}_element").loaded? end end |
#in_frame(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within a frame . A frame parameter is passed to the block and must be passed to the other calls to PageObject. You can nest calls to in_frame by passing the frame to the next level.
152 153 154 155 156 |
# File 'lib/page-object/accessors.rb', line 152 def in_frame(identifier, frame=nil, &block) frame = frame.nil? ? [] : frame.dup frame << {frame: identifier} block.call(frame) end |
#in_iframe(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within an iframe. A frame parameter is passed to the block and must be passed to the other calls to PageObject. You can nest calls to in_frame by passing the frame to the next level.
176 177 178 179 180 |
# File 'lib/page-object/accessors.rb', line 176 def in_iframe(identifier, frame=nil, &block) frame = frame.nil? ? [] : frame.dup frame << {iframe: identifier} block.call(frame) end |
#indexed_property(name, identifier_list) ⇒ Object
adds a method that will return an indexed property. The property will respond to the [] method with an object that has a set of normal page_object properties that correspond to the definitions included in the identifier_list parameter, with the “what” of the “how and what” substituted based on the index provided to the [] method.
1167 1168 1169 1170 1171 |
# File 'lib/page-object/accessors.rb', line 1167 def indexed_property (name, identifier_list) define_method("#{name}") do IndexedProperties::TableOfElements.new(@browser, identifier_list) end end |
#label(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text from a label, another to return the label element, and another to check the label’s existence.
849 850 851 852 853 854 855 |
# File 'lib/page-object/accessors.rb', line 849 def label(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'label_for', &block) define_method(name) do return platform.label_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#link(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: a
adds three methods - one to select a link, another to return a PageObject::Elements::Link object representing the link, and another that checks the link’s existence.
328 329 330 331 332 333 334 |
# File 'lib/page-object/accessors.rb', line 328 def link(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'link_for', &block) define_method(name) do return platform.click_link_for identifier.clone unless block_given? self.send("#{name}_element").click end end |
#list_item(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: li
adds three methods - one to retrieve the text from a list item, another to return the list item element, and another to check the list item’s existence.
622 623 624 625 626 627 628 |
# File 'lib/page-object/accessors.rb', line 622 def list_item(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'list_item_for', &block) define_method(name) do return platform.list_item_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#ordered_list(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: ol
adds three methods - one to return the text within the ordered list, one to retrieve the ordered list element, and another to test it’s existence.
666 667 668 669 670 671 672 |
# File 'lib/page-object/accessors.rb', line 666 def ordered_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'ordered_list_for', &block) define_method(name) do return platform.ordered_list_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#page_section(name, section_class, identifier) ⇒ Object
adds a method to return a page object rooted at an element
1083 1084 1085 1086 1087 |
# File 'lib/page-object/accessors.rb', line 1083 def page_section(name, section_class, identifier) define_method(name) do platform.page_for(identifier, section_class) end end |
#page_sections(name, section_class, identifier) ⇒ Object
adds a method to return a collection of page objects rooted at elements
1100 1101 1102 1103 1104 |
# File 'lib/page-object/accessors.rb', line 1100 def page_sections(name, section_class, identifier) define_method(name) do platform.pages_for(identifier, section_class) end end |
#page_url(url) ⇒ Object Also known as: direct_url
Specify the url for the page. A call to this method will generate a ‘goto’ method to take you to the page.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/page-object/accessors.rb', line 37 def page_url(url) define_method("goto") do platform.navigate_to self.page_url_value end define_method('page_url_value') do lookup = url.kind_of?(Symbol) ? self.send(url) : url erb = ERB.new(%Q{#{lookup}}) merged_params = self.class.instance_variable_get("@merged_params") params = merged_params ? merged_params : self.class.params erb.result(binding) end end |
#paragraph(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: p
adds three methods - one to retrieve the text of a paragraph, another to retrieve a paragraph element, and another to check the paragraph’s existence.
808 809 810 811 812 813 814 |
# File 'lib/page-object/accessors.rb', line 808 def paragraph(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'paragraph_for', &block) define_method(name) do return platform.paragraph_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#params ⇒ Object
Return the params that exist on this page class
26 27 28 |
# File 'lib/page-object/accessors.rb', line 26 def params @params ||= {} end |
#params=(the_params) ⇒ Object
Set some values that can be used within the class. This is typically used to provide values that help build dynamic urls in the page_url method
19 20 21 |
# File 'lib/page-object/accessors.rb', line 19 def params=(the_params) @params = the_params end |
#radio_button(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: radio
adds four methods - one to select, another to return if a radio button is selected, another method to return a PageObject::Elements::RadioButton object representing the radio button element, and another to check the radio button’s existence.
383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/page-object/accessors.rb', line 383 def (name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'radio_button_for', &block) define_method("select_#{name}") do return platform.select_radio(identifier.clone) unless block_given? self.send("#{name}_element").select end define_method("#{name}_selected?") do return platform.radio_selected?(identifier.clone) unless block_given? self.send("#{name}_element").selected? end end |
#radio_button_group(name, identifier) ⇒ Object Also known as: radio_group
adds five methods to help interact with a radio button group - a method to select a radio button in the group by given value/text, a method to return the values of all radio buttons in the group, a method to return if a radio button in the group is selected (will return the text of the selected radio button, if true), a method to return an array of PageObject::Elements::RadioButton objects representing the radio button group, and finally a method to check the existence of the radio button group.
radio_button_group(:color, :name => “preferred_color”) will generate ‘select_color’, ‘color_values’, ‘color_selected?’, ‘color_elements’, and ‘color?’ methods
The valid keys are:
-
:name
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/page-object/accessors.rb', line 416 def (name, identifier) define_method("select_#{name}") do |value| platform.(identifier.clone).each do |radio_elem| if radio_elem.value == value return radio_elem.select end end end define_method("#{name}_values") do result = [] platform.(identifier.clone).each do |radio_elem| result << radio_elem.value end return result end define_method("#{name}_selected?") do platform.(identifier.clone).each do |radio_elem| return radio_elem.value if radio_elem.selected? end return false end define_method("#{name}_elements") do return platform.(identifier.clone) end define_method("#{name}?") do return platform.(identifier.clone).any? end end |
#row(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text from a table row, another to return the table row element, and another to check the row’s existence.
563 564 565 566 567 568 569 |
# File 'lib/page-object/accessors.rb', line 563 def row(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'row_for', &block) define_method("#{name}") do return platform.row_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#select_list(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: select
adds five methods - one to select an item in a drop-down, another to fetch the currently selected item text, another to retrieve the select list element, another to check the drop down’s existence and another to get all the available options to select from.
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/page-object/accessors.rb', line 298 def select_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'select_list_for', &block) define_method(name) do return platform.select_list_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do |value| return platform.select_list_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").select(value) end define_method("#{name}_options") do element = self.send("#{name}_element") (element && element.) ? element..collect(&:text) : [] end end |
#span(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to retrieve the text from a span, another to return the span element, and another to check the span’s existence.
498 499 500 501 502 503 504 |
# File 'lib/page-object/accessors.rb', line 498 def span(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'span_for', &block) define_method(name) do return platform.span_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#standard_methods(name, identifier, method, &block) ⇒ Object
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 |
# File 'lib/page-object/accessors.rb', line 1132 def standard_methods(name, identifier, method, &block) define_method("#{name}_element") do return call_block(&block) if block_given? platform.send(method, identifier.clone) end define_method("#{name}?") do return call_block(&block).exists? if block_given? platform.send(method, identifier.clone).exists? end end |
#svg(name, identifier = {:index => 0}, &block) ⇒ Object
adds two methods - one to retrieve a svg, and another to check the svg’s existence.
978 979 980 |
# File 'lib/page-object/accessors.rb', line 978 def svg(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'svg_for', &block) end |
#table(name, identifier = {:index => 0}, &block) ⇒ Object
adds three methods - one to return the text for the table, one to retrieve the table element, and another to check the table’s existence.
519 520 521 522 523 524 525 |
# File 'lib/page-object/accessors.rb', line 519 def table(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'table_for', &block) define_method(name) do return platform.table_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#text_area(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: textarea
adds four methods to the page object - one to set text in a text area, another to retrieve text from a text area, another to return the text area element, and another to check the text area’s existence.
270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/page-object/accessors.rb', line 270 def text_area(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'text_area_for', &block) define_method(name) do return platform.text_area_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do |value| return platform.text_area_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").value = value end end |
#text_field(name, identifier = {:index => 0}, &block) ⇒ Object
adds four methods to the page object - one to set text in a text field, another to retrieve text from a text field, another to return the text field element, another to check the text field’s existence.
196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/page-object/accessors.rb', line 196 def text_field(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'text_field_for', &block) define_method(name) do return platform.text_field_value_for identifier.clone unless block_given? self.send("#{name}_element").value end define_method("#{name}=") do |value| return platform.text_field_value_set(identifier.clone, value) unless block_given? self.send("#{name}_element").value = value end end |
#unordered_list(name, identifier = {:index => 0}, &block) ⇒ Object Also known as: ul
adds three methods - one to return the text within the unordered list, one to retrieve the unordered list element, and another to check it’s existence.
644 645 646 647 648 649 650 |
# File 'lib/page-object/accessors.rb', line 644 def unordered_list(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'unordered_list_for', &block) define_method(name) do return platform.unordered_list_text_for identifier.clone unless block_given? self.send("#{name}_element").text end end |
#video(name, identifier = {:index => 0}, &block) ⇒ Object
adds two methods - one to return the video element and another to check the video’s existence.
921 922 923 |
# File 'lib/page-object/accessors.rb', line 921 def video(name, identifier={:index => 0}, &block) standard_methods(name, identifier, 'video_for', &block) end |
#wait_for_expected_title(expected_title, timeout = ::PageObject.default_element_wait) ⇒ boolean
Creates a method that waits the expected_title of a page to match the actual.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/page-object/accessors.rb', line 64 def wait_for_expected_title(expected_title, timeout=::PageObject.default_element_wait) define_method("wait_for_expected_title?") do = lambda { "Expected title '#{expected_title}' instead of '#{title}'" } has_expected_title = (expected_title === title) wait_until(timeout, .call) do has_expected_title = (expected_title === title) end unless has_expected_title raise .call unless has_expected_title has_expected_title end end |