Module: WatirPageHelper::ClassMethods
- Defined in:
- lib/watir-page-helper.rb,
lib/watir-page-helper/generated.rb
Overview
A collection of class methods that generate helper methods that are mixed into a calling class.
Instance Method Summary collapse
-
#button(name, identifier = nil, &block) ⇒ Nil
Generates two button methods to: * click a button; * return the button element.
-
#cell(name, identifier = nil, &block) ⇒ Nil
Generates two row methods to: * return the text from a table cell; * return the cell element.
-
#checkbox(name, identifier = nil, &block) ⇒ Nil
Generates four checkbox methods to: * check the checkbox; * uncheck the checkbox; * see whether a the checkbox is checked; and * return the checkbox element.
-
#dd(name, identifier = nil, &block) ⇒ Nil
Generates two dd methods to: * return the text from a dd; * return the dd element.
-
#direct_url(url) ⇒ Nil
Provides a way to define a direct URL for a page, and creates a method for the page to go to that URL.
-
#div(name, identifier = nil, &block) ⇒ Nil
Generates two div methods to: * return the text from a div; * return the div element.
-
#dl(name, identifier = nil, &block) ⇒ Nil
Generates two dl methods to: * return the text from a dl; * return the dl element.
-
#dt(name, identifier = nil, &block) ⇒ Nil
Generates two dt methods to: * return the text from a dt; * return the dt element.
-
#expected_element(type, identifier, timeout = 30) ⇒ Nil
Creates a method that provides a way to initialize a page based upon an expected element.
-
#expected_title(expected_title) ⇒ Nil
Creates a method that compares the expected_title of a page against the actual.
-
#file_field(name, identifier = nil, &block) ⇒ Nil
Generates two file_field methods to: * return the text from a file field; * set a file field.
-
#form(name, identifier = nil, &block) ⇒ Nil
Generates two form methods to: * return the text from a form; * return the form element.
-
#frame(name, identifier = nil, &block) ⇒ Nil
Generates a frame method to return a frame element.
-
#h1(name, identifier = nil, &block) ⇒ Nil
Generates two h1 methods to: * return the text from a h1; * return the h1 element.
-
#h2(name, identifier = nil, &block) ⇒ Nil
Generates two h2 methods to: * return the text from a h2; * return the h2 element.
-
#h3(name, identifier = nil, &block) ⇒ Nil
Generates two h3 methods to: * return the text from a h3; * return the h3 element.
-
#h4(name, identifier = nil, &block) ⇒ Nil
Generates two h4 methods to: * return the text from a h4; * return the h4 element.
-
#h5(name, identifier = nil, &block) ⇒ Nil
Generates two h5 methods to: * return the text from a h5; * return the h5 element.
-
#h6(name, identifier = nil, &block) ⇒ Nil
Generates two h6 methods to: * return the text from a h6; * return the h6 element.
-
#image(name, identifier = nil, &block) ⇒ Nil
Generates a image method to return a image element.
-
#li(name, identifier = nil, &block) ⇒ Nil
Generates two li methods to: * return the text from a li; * return the li element.
-
#link(name, identifier = nil, &block) ⇒ Nil
Generates two link methods to: * click a link; * return the link element.
-
#p(name, identifier = nil, &block) ⇒ Nil
Generates two p methods to: * return the text from a p; * return the p element.
-
#radio(name, identifier = nil, &block) ⇒ Nil
Generates three radio methods to: * select a radio; * see whether a radio is selected; and * return the radio element.
- #radio_button(name, identifier = nil, &block) ⇒ Object
-
#row(name, identifier = nil, &block) ⇒ Nil
Generates two row methods to: * return the text from a table row; * return the row element.
-
#select_list(name, identifier = nil, &block) ⇒ Nil
Generates four select_list methods to: * get the value specified in a select_list * select a value in a select list; * see whether a value is selected; and * return the select_list element.
-
#span(name, identifier = nil, &block) ⇒ Nil
Generates two span methods to: * return the text from a span; * return the span element.
-
#table(name, identifier = nil, &block) ⇒ Nil
Generates a table method to return a table element.
-
#text_field(name, identifier = nil, &block) ⇒ Nil
Generates three text_field methods to: * set a text_field; * get a text_field’s value; and * return the text_field element.
Instance Method Details
#button(name, identifier = nil, &block) ⇒ Nil
Generates two button methods to:
-
click a button;
-
return the button element.
button :info, :text => “Information” page.info page.info_button.exist?.should be_true
317 318 319 320 321 322 |
# File 'lib/watir-page-helper/generated.rb', line 317 def name, identifier=nil, &block define_method(name) do self.send("#{name}_button").click end create_element_getter "#{name}_button", identifier, __method__, block end |
#cell(name, identifier = nil, &block) ⇒ Nil
Generates two row methods to:
-
return the text from a table cell;
-
return the cell element.
187 188 189 190 191 192 |
# File 'lib/watir-page-helper.rb', line 187 def cell name, identifier=nil, &block define_method(name) do self.send("#{name}_cell").text end create_element_getter "#{name}_cell", identifier, 'td', block end |
#checkbox(name, identifier = nil, &block) ⇒ Nil
Generates four checkbox methods to:
-
check the checkbox;
-
uncheck the checkbox;
-
see whether a the checkbox is checked; and
-
return the checkbox element.
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/watir-page-helper.rb', line 110 def checkbox name, identifier=nil, &block define_method("check_#{name}") do self.send("#{name}_checkbox").set end define_method("uncheck_#{name}") do self.send("#{name}_checkbox").clear end define_method("#{name}?") do self.send("#{name}_checkbox").set? end create_element_getter "#{name}_checkbox", identifier, __method__, block end |
#dd(name, identifier = nil, &block) ⇒ Nil
Generates two dd methods to:
-
return the text from a dd;
-
return the dd element.
dd :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_dd.exist?.should be_true
217 218 219 220 221 222 |
# File 'lib/watir-page-helper/generated.rb', line 217 def dd name, identifier=nil, &block define_method(name) do self.send("#{name}_dd").text end create_element_getter "#{name}_dd", identifier, __method__, block end |
#direct_url(url) ⇒ Nil
Provides a way to define a direct URL for a page, and creates a method for the page to go to that URL.
56 57 58 59 60 |
# File 'lib/watir-page-helper.rb', line 56 def direct_url url define_method("goto") do @browser.goto url end end |
#div(name, identifier = nil, &block) ⇒ Nil
Generates two div methods to:
-
return the text from a div;
-
return the div element.
div :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_div.exist?.should be_true
137 138 139 140 141 142 |
# File 'lib/watir-page-helper/generated.rb', line 137 def div name, identifier=nil, &block define_method(name) do self.send("#{name}_div").text end create_element_getter "#{name}_div", identifier, __method__, block end |
#dl(name, identifier = nil, &block) ⇒ Nil
Generates two dl methods to:
-
return the text from a dl;
-
return the dl element.
dl :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_dl.exist?.should be_true
197 198 199 200 201 202 |
# File 'lib/watir-page-helper/generated.rb', line 197 def dl name, identifier=nil, &block define_method(name) do self.send("#{name}_dl").text end create_element_getter "#{name}_dl", identifier, __method__, block end |
#dt(name, identifier = nil, &block) ⇒ Nil
Generates two dt methods to:
-
return the text from a dt;
-
return the dt element.
dt :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_dt.exist?.should be_true
237 238 239 240 241 242 |
# File 'lib/watir-page-helper/generated.rb', line 237 def dt name, identifier=nil, &block define_method(name) do self.send("#{name}_dt").text end create_element_getter "#{name}_dt", identifier, __method__, block end |
#expected_element(type, identifier, timeout = 30) ⇒ Nil
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.
43 44 45 46 47 |
# File 'lib/watir-page-helper.rb', line 43 def expected_element type, identifier, timeout=30 define_method("expected_element") do @browser.send("#{type.to_s}", identifier).wait_until_present timeout end end |
#expected_title(expected_title) ⇒ Nil
Creates a method that compares the expected_title of a page against the actual.
26 27 28 29 30 31 |
# File 'lib/watir-page-helper.rb', line 26 def expected_title expected_title define_method("has_expected_title?") do has_expected_title = expected_title.kind_of?(Regexp) ? expected_title =~ @browser.title : expected_title == @browser.title raise "Expected title '#{expected_title}' instead of '#{@browser.title}'" unless has_expected_title end end |
#file_field(name, identifier = nil, &block) ⇒ Nil
Generates two file_field methods to:
-
return the text from a file field;
-
set a file field
file_field :upload, :id => ‘upload’
page.upload = image_path #set
page.upload.should == image_path #check
208 209 210 211 212 213 214 215 216 |
# File 'lib/watir-page-helper.rb', line 208 def file_field name, identifier=nil, &block define_method(name) do self.send("#{name}_file_field").value end define_method("#{name}=") do |value| self.send("#{name}_file_field").set value end create_element_getter "#{name}_file_field", identifier, __method__, block end |
#form(name, identifier = nil, &block) ⇒ Nil
Generates two form methods to:
-
return the text from a form;
-
return the form element.
form :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_form.exist?.should be_true
257 258 259 260 261 262 |
# File 'lib/watir-page-helper/generated.rb', line 257 def form name, identifier=nil, &block define_method(name) do self.send("#{name}_form").text end create_element_getter "#{name}_form", identifier, __method__, block end |
#frame(name, identifier = nil, &block) ⇒ Nil
Generates a frame method to return a frame element.
384 385 386 |
# File 'lib/watir-page-helper/generated.rb', line 384 def frame name, identifier=nil, &block create_element_getter "#{name}", identifier, __method__, block end |
#h1(name, identifier = nil, &block) ⇒ Nil
Generates two h1 methods to:
-
return the text from a h1;
-
return the h1 element.
h1 :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_h1.exist?.should be_true
17 18 19 20 21 22 |
# File 'lib/watir-page-helper/generated.rb', line 17 def h1 name, identifier=nil, &block define_method(name) do self.send("#{name}_h1").text end create_element_getter "#{name}_h1", identifier, __method__, block end |
#h2(name, identifier = nil, &block) ⇒ Nil
Generates two h2 methods to:
-
return the text from a h2;
-
return the h2 element.
h2 :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_h2.exist?.should be_true
37 38 39 40 41 42 |
# File 'lib/watir-page-helper/generated.rb', line 37 def h2 name, identifier=nil, &block define_method(name) do self.send("#{name}_h2").text end create_element_getter "#{name}_h2", identifier, __method__, block end |
#h3(name, identifier = nil, &block) ⇒ Nil
Generates two h3 methods to:
-
return the text from a h3;
-
return the h3 element.
h3 :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_h3.exist?.should be_true
57 58 59 60 61 62 |
# File 'lib/watir-page-helper/generated.rb', line 57 def h3 name, identifier=nil, &block define_method(name) do self.send("#{name}_h3").text end create_element_getter "#{name}_h3", identifier, __method__, block end |
#h4(name, identifier = nil, &block) ⇒ Nil
Generates two h4 methods to:
-
return the text from a h4;
-
return the h4 element.
h4 :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_h4.exist?.should be_true
77 78 79 80 81 82 |
# File 'lib/watir-page-helper/generated.rb', line 77 def h4 name, identifier=nil, &block define_method(name) do self.send("#{name}_h4").text end create_element_getter "#{name}_h4", identifier, __method__, block end |
#h5(name, identifier = nil, &block) ⇒ Nil
Generates two h5 methods to:
-
return the text from a h5;
-
return the h5 element.
h5 :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_h5.exist?.should be_true
97 98 99 100 101 102 |
# File 'lib/watir-page-helper/generated.rb', line 97 def h5 name, identifier=nil, &block define_method(name) do self.send("#{name}_h5").text end create_element_getter "#{name}_h5", identifier, __method__, block end |
#h6(name, identifier = nil, &block) ⇒ Nil
Generates two h6 methods to:
-
return the text from a h6;
-
return the h6 element.
h6 :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_h6.exist?.should be_true
117 118 119 120 121 122 |
# File 'lib/watir-page-helper/generated.rb', line 117 def h6 name, identifier=nil, &block define_method(name) do self.send("#{name}_h6").text end create_element_getter "#{name}_h6", identifier, __method__, block end |
#image(name, identifier = nil, &block) ⇒ Nil
Generates a image method to return a image element.
371 372 373 |
# File 'lib/watir-page-helper/generated.rb', line 371 def image name, identifier=nil, &block create_element_getter "#{name}", identifier, __method__, block end |
#li(name, identifier = nil, &block) ⇒ Nil
Generates two li methods to:
-
return the text from a li;
-
return the li element.
li :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_li.exist?.should be_true
277 278 279 280 281 282 |
# File 'lib/watir-page-helper/generated.rb', line 277 def li name, identifier=nil, &block define_method(name) do self.send("#{name}_li").text end create_element_getter "#{name}_li", identifier, __method__, block end |
#link(name, identifier = nil, &block) ⇒ Nil
Generates two link methods to:
-
click a link;
-
return the link element.
link :info, :text => “Information” page.info page.info_link.exist?.should be_true
297 298 299 300 301 302 |
# File 'lib/watir-page-helper/generated.rb', line 297 def link name, identifier=nil, &block define_method(name) do self.send("#{name}_link").click end create_element_getter "#{name}_link", identifier, __method__, block end |
#p(name, identifier = nil, &block) ⇒ Nil
Generates two p methods to:
-
return the text from a p;
-
return the p element.
p :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_p.exist?.should be_true
177 178 179 180 181 182 |
# File 'lib/watir-page-helper/generated.rb', line 177 def p name, identifier=nil, &block define_method(name) do self.send("#{name}_p").text end create_element_getter "#{name}_p", identifier, __method__, block end |
#radio(name, identifier = nil, &block) ⇒ Nil
Generates three radio methods to:
-
select a radio;
-
see whether a radio is selected; and
-
return the radio element.
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/watir-page-helper.rb', line 138 def radio name, identifier=nil, &block define_method("select_#{name}") do self.send("#{name}_radio").set end define_method("#{name}_set?") do self.send("#{name}_radio").set? end create_element_getter "#{name}_radio", identifier, __method__, block create_element_getter "#{name}_radio_button", identifier, __method__, block end |
#radio_button(name, identifier = nil, &block) ⇒ Object
149 150 151 152 |
# File 'lib/watir-page-helper.rb', line 149 def name, identifier=nil, &block warn 'radio_button is a deprecated method in the watir-page-helper gem, and will be removed in future versions.' radio name, identifier, &block end |
#row(name, identifier = nil, &block) ⇒ Nil
Generates two row methods to:
-
return the text from a table row;
-
return the row element.
167 168 169 170 171 172 |
# File 'lib/watir-page-helper.rb', line 167 def row name, identifier=nil, &block define_method(name) do self.send("#{name}_row").text end create_element_getter "#{name}_row", identifier, 'tr', block end |
#select_list(name, identifier = nil, &block) ⇒ Nil
Generates four select_list methods to:
-
get the value specified in a select_list
-
select a value in a select list;
-
see whether a value is selected; and
-
return the select_list element.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/watir-page-helper.rb', line 79 def select_list name, identifier=nil, &block define_method(name) do self.send("#{name}_select_list").value end define_method("#{name}=") do |value| self.send("#{name}_select_list").select(value) end define_method("#{name}_selected?") do |value| self.send("#{name}_select_list").selected?(value) end create_element_getter "#{name}_select_list", identifier, __method__, block end |
#span(name, identifier = nil, &block) ⇒ Nil
Generates two span methods to:
-
return the text from a span;
-
return the span element.
span :my_element, :id => “my_element” page.my_element.should == “My Element Text” page.my_element_span.exist?.should be_true
157 158 159 160 161 162 |
# File 'lib/watir-page-helper/generated.rb', line 157 def span name, identifier=nil, &block define_method(name) do self.send("#{name}_span").text end create_element_getter "#{name}_span", identifier, __method__, block end |
#table(name, identifier = nil, &block) ⇒ Nil
Generates a table method to return a table element.
358 359 360 |
# File 'lib/watir-page-helper/generated.rb', line 358 def table name, identifier=nil, &block create_element_getter "#{name}", identifier, __method__, block end |
#text_field(name, identifier = nil, &block) ⇒ Nil
Generates three text_field methods to:
-
set a text_field;
-
get a text_field’s value; and
-
return the text_field element.
text_field first_name, :name => “firstname” page.first_name = “Finley” #set page.first_name.should == “Finley” #check page.first_name_text_field.exists?.should be_true #object
339 340 341 342 343 344 345 346 347 |
# File 'lib/watir-page-helper/generated.rb', line 339 def text_field name, identifier=nil, &block define_method(name) do self.send("#{name}_text_field").value end define_method("#{name}=") do |value| self.send("#{name}_text_field").set value end create_element_getter "#{name}_text_field", identifier, __method__, block end |