Module: FireWatir::Container
- Includes:
- FireWatir, JsshSocket, Watir::Exception
- Defined in:
- lib/firewatir/container.rb,
lib/firewatir/element_collections.rb
Constant Summary collapse
- MACHINE_IP =
IP Address of the machine where the script is to be executed. Default to localhost.
"127.0.0.1"
- DEFAULT_HIGHLIGHT_COLOR =
The default color for highlighting objects as they are accessed.
"yellow"
Instance Method Summary collapse
-
#button(how, what = nil) ⇒ Object
Description: Used to access a button element.
-
#cell(how, what = nil) ⇒ Object
Description: Used to access a table cell.
-
#checkbox(how, what = nil, value = nil) ⇒ Object
Description: Used to access checkbox element.
-
#dd(how, what = nil) ⇒ Object
Description: Used to access a definition description element - a <dd> HTML tag.
-
#dl(how, what = nil) ⇒ Object
Description: Used to access a definition list element - a <dl> HTML tag.
-
#dt(how, what = nil) ⇒ Object
Description: Used to access a definition term element - a <dt> HTML tag.
-
#file_field(how, what = nil) ⇒ Object
Description: Used for accessing a file field.
-
#form(how, what = nil) ⇒ Object
Description: Used to access a form element.
-
#frame(how, what = nil) ⇒ Object
Description: Used to access a frame element.
-
#hidden(how, what = nil) ⇒ Object
Description: Used to access hidden field element.
-
#image(how, what = nil) ⇒ Object
Description: Used to access image element.
-
#link(how, what = nil) ⇒ Object
Description: Used to access link element.
-
#radio(how, what = nil, value = nil) ⇒ Object
Description: Used to access radio button element.
-
#row(how, what = nil) ⇒ Object
Description: Used to access a table row.
-
#select_list(how, what = nil) ⇒ Object
Description: Used to access select list element.
-
#show_all_objects ⇒ Object
Description: This method shows the available objects on the current page.
-
#table(how, what = nil) ⇒ Object
Description: Used to access a table.
-
#text_field(how, what = nil) ⇒ Object
Description: Used for accessing a text field.
Methods included from JsshSocket
#js_eval, #js_eval_method, #jssh_socket, #read_socket
Instance Method Details
#button(how, what = nil) ⇒ Object
Description:
Used to access a button element. Usually an <input type = "button"> HTML tag.
Input:
- how - The attribute used to identify the row.
- what - The value of that attribute.
Typical Usage:
ff.button(:id, 'b_1') # access the button with an ID of b_1
ff.button(:name, 'verify_data') # access the button with a name of verify_data
if only a single parameter is supplied, then :value is used as 'how' and parameter supplied is used as what.
ff.button('Click Me') # access the button with a value of Click Me
Output:
Button element.
191 192 193 194 195 196 197 198 |
# File 'lib/firewatir/container.rb', line 191 def (how, what=nil) locate if respond_to?(:locate) if what.nil? && String === how what = how how = :value end Button.new(self, how, what) end |
#cell(how, what = nil) ⇒ Object
Description:
Used to access a table cell. Usually an <td> HTML tag.
Input:
- how - The attribute used to identify the cell.
- what - The value of that attribute.
Typical Usage:
ff.cell(:id, 'tb_cell')
ff.cell(:index, 1)
Output:
TableCell Object
147 148 149 150 |
# File 'lib/firewatir/container.rb', line 147 def cell(how, what=nil) locate if respond_to?(:locate) TableCell.new(self, how, what) end |
#checkbox(how, what = nil, value = nil) ⇒ Object
Description:
Used to access checkbox element. Usually an <input type = checkbox> HTML tag.
Input:
- how - Attribute used to identify the check box element.
- what - Value of that attribute.
Typical Usage:
ff.checkbox(:id, 'user_name') # access the checkbox element with an ID of user_name
ff.checkbox(:name, 'address') # access the checkbox element with a name of address
In many instances, checkboxes on an html page have the same name, but are identified by different values. An example is shown next.
<input type = checkbox name = email_frequency value = 'daily' > Daily Email
<input type = checkbox name = email_frequency value = 'Weekly'> Weekly Email
<input type = checkbox name = email_frequency value = 'monthly'>Monthly Email
FireWatir can access these using the following:
ff.checkbox(:id, 'day_to_send' , 'monday' ) # access the check box with an id of day_to_send and a value of monday
ff.checkbox(:name ,'email_frequency', 'weekly') # access the check box with a name of email_frequency and a value of 'weekly'
Output:
Checkbox object.
309 310 311 312 |
# File 'lib/firewatir/container.rb', line 309 def checkbox(how, what=nil, value = nil) locate if respond_to?(:locate) return CheckBox.new(self, how, what, value) end |
#dd(how, what = nil) ⇒ Object
Description:
Used to access a definition description element - a <dd> HTML tag.
Input:
- how - Attribute used to identify the image element.
- what - Value of that attribute.
Typical Usage:
ff.dd(:id, 'user_name') # access the dd element with an ID of user_name
ff.dd(:title, 'address') # access the dd element with a title of address
Returns:
Dd object.
446 447 448 449 |
# File 'lib/firewatir/container.rb', line 446 def dd(how, what = nil) locate if respond_to?(:locate) Dd.new(self, how, what) end |
#dl(how, what = nil) ⇒ Object
Description:
Used to access a definition list element - a <dl> HTML tag.
Input:
- how - Attribute used to identify the definition list element.
- what - Value of that attribute.
Typical Usage:
ff.dl(:id, 'user_name') # access the dl element with an ID of user_name
ff.dl(:title, 'address') # access the dl element with a title of address
Returns:
Dl object.
404 405 406 407 |
# File 'lib/firewatir/container.rb', line 404 def dl(how, what = nil) locate if respond_to?(:locate) Dl.new(self, how, what) end |
#dt(how, what = nil) ⇒ Object
Description:
Used to access a definition term element - a <dt> HTML tag.
Input:
- how - Attribute used to identify the image element.
- what - Value of that attribute.
Typical Usage:
ff.dt(:id, 'user_name') # access the dt element with an ID of user_name
ff.dt(:title, 'address') # access the dt element with a title of address
Returns:
Dt object.
425 426 427 428 |
# File 'lib/firewatir/container.rb', line 425 def dt(how, what = nil) locate if respond_to?(:locate) Dt.new(self, how, what) end |
#file_field(how, what = nil) ⇒ Object
Description:
Used for accessing a file field. Usually an <input type = file> HTML tag.
Input:
- how - Attribute used to identify the file field element
- what - Value of that attribute.
Typical Usage:
ff.file_field(:id, 'up_1') # access the file upload fff.d with an ID of up_1
ff.file_field(:name, 'upload') # access the file upload fff.d with a name of upload
Output:
FileField object
215 216 217 218 |
# File 'lib/firewatir/container.rb', line 215 def file_field(how, what = nil) locate if respond_to?(:locate) FileField.new(self, how, what) end |
#form(how, what = nil) ⇒ Object
Description:
Used to access a form element. Usually an <form> HTML tag.
Input:
- how - The attribute used to identify the form.
- what - The value of that attribute.
If only one parameter is supplied, "how" is by default taken as name and the
parameter supplied becomes the value of the name attribute.
Typical usage:
ff.form(:index, 1)
ff.form(:name , 'main_form')
ff.form('main_form') # in this case, just a name is supplied.
Output:
Form object.
102 103 104 105 106 107 108 109 |
# File 'lib/firewatir/container.rb', line 102 def form(how, what=nil) locate if respond_to?(:locate) if(what == nil) what = how how = :name end Form.new(self, how, what) end |
#frame(how, what = nil) ⇒ Object
Description:
Used to access a frame element. Usually an <frame> or <iframe> HTML tag.
Input:
- how - The attribute used to identify the framet.
- what - The value of that attribute.
If only one parameter is supplied, "how" is by default taken as name and the
parameter supplied becomes the value of the name attribute.
Typical usage:
ff.frame(:index, 1)
ff.frame(:name , 'main_frame')
ff.frame('main_frame') # in this case, just a name is supplied.
Output:
Frame object.
74 75 76 77 78 79 80 81 |
# File 'lib/firewatir/container.rb', line 74 def frame(how, what = nil) locate if respond_to?(:locate) if(what == nil) what = how how = :name end Frame.new(self, how, what) end |
#hidden(how, what = nil) ⇒ Object
Description:
Used to access hidden field element. Usually an <input type = hidden> HTML tag
Input:
- how - Attribute used to identify the hidden element.
- what - Value of that attribute.
Typical Usage:
ff.hidden(:id, 'user_name') # access the hidden element with an ID of user_name
ff.hidden(:name, 'address') # access the hidden element with a name of address
Output:
Hidden object.
257 258 259 260 |
# File 'lib/firewatir/container.rb', line 257 def hidden(how, what=nil) locate if respond_to?(:locate) return Hidden.new(self, how, what) end |
#image(how, what = nil) ⇒ Object
Description:
Used to access image element. Usually an <img> HTML tag.
Input:
- how - Attribute used to identify the image element.
- what - Value of that attribute.
Typical Usage:
ff.image(:id, 'user_name') # access the image element with an ID of user_name
ff.image(:name, 'address') # access the image element with a name of address
Output:
Image object.
382 383 384 385 |
# File 'lib/firewatir/container.rb', line 382 def image(how, what = nil) locate if respond_to?(:locate) Image.new(self, how, what) end |
#link(how, what = nil) ⇒ Object
Description:
Used to access link element. Usually an <a> HTML tag.
Input:
- how - Attribute used to identify the link element.
- what - Value of that attribute.
Typical Usage:
ff.link(:id, 'user_name') # access the link element with an ID of user_name
ff.link(:name, 'address') # access the link element with a name of address
Output:
Link object.
361 362 363 364 |
# File 'lib/firewatir/container.rb', line 361 def link(how, what=nil) locate if respond_to?(:locate) return Link.new(self, how, what) end |
#radio(how, what = nil, value = nil) ⇒ Object
Description:
Used to access radio button element. Usually an <input type = radio> HTML tag.
Input:
- how - Attribute used to identify the radio button element.
- what - Value of that attribute.
Typical Usage:
ff.radio(:id, 'user_name') # access the radio button element with an ID of user_name
ff.radio(:name, 'address') # access the radio button element with a name of address
In many instances, radio buttons on an html page have the same name, but are identified by different values. An example is shown next.
<input type = radio name = email_frequency value = 'daily' > Daily Email
<input type = radio name = email_frequency value = 'Weekly'> Weekly Email
<input type = radio name = email_frequency value = 'monthly'>Monthly Email
FireWatir can access these using the following:
ff.radio(:id, 'day_to_send' , 'monday' ) # access the radio button with an id of day_to_send and a value of monday
ff.radio(:name ,'email_frequency', 'weekly') # access the radio button with a name of email_frequency and a value of 'weekly'
Output:
Radio button object.
340 341 342 343 |
# File 'lib/firewatir/container.rb', line 340 def radio(how, what=nil, value = nil) locate if respond_to?(:locate) return Radio.new(self, how, what, value) end |
#row(how, what = nil) ⇒ Object
Description:
Used to access a table row. Usually an <tr> HTML tag.
Input:
- how - The attribute used to identify the row.
- what - The value of that attribute.
Typical Usage:
ff.row(:id, 'tb_row')
ff.row(:index, 1)
Output:
TableRow object
167 168 169 170 |
# File 'lib/firewatir/container.rb', line 167 def row(how, what=nil) locate if respond_to?(:locate) TableRow.new(self, how, what) end |
#select_list(how, what = nil) ⇒ Object
Description:
Used to access select list element. Usually an <select> HTML tag.
Input:
- how - Attribute used to identify the select element.
- what - Value of that attribute.
Typical Usage:
ff.select_list(:id, 'user_name') # access the select list with an ID of user_name
ff.select_list(:name, 'address') # access the select list with a name of address
Output:
Select List object.
278 279 280 281 |
# File 'lib/firewatir/container.rb', line 278 def select_list(how, what=nil) locate if respond_to?(:locate) return SelectList.new(self, how, what) end |
#show_all_objects ⇒ Object
Description:
This method shows the available objects on the current page.
This is usually only used for debugging or writing new test scripts.
This is a nice feature to help find out what HTML objects are on a page
when developing a test case using FireWatir.
Typical Usage:
ff.show_all_objects
Output:
Prints all the available elements on the page.
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
# File 'lib/firewatir/container.rb', line 473 def show_all_objects puts "-----------Objects in the current context-------------" locate if respond_to?(:locate) elements = Document.new(self).all puts elements.length elements.each do |n| puts n.tagName puts n.to_s puts "------------------------------------------" end puts "Total number of objects in the current context : #{elements.length}" return elements # Test the index access. # puts doc[35].to_s end |
#table(how, what = nil) ⇒ Object
Description:
Used to access a table. Usually an <table> HTML tag.
Input:
- how - The attribute used to identify the table.
- what - The value of that attribute.
Typical usage:
ff.table(:index, 1) #index starts from 1.
ff.table(:id, 'main_table')
Output:
Table object.
127 128 129 130 |
# File 'lib/firewatir/container.rb', line 127 def table(how, what=nil) locate if respond_to?(:locate) Table.new(self, how, what) end |
#text_field(how, what = nil) ⇒ Object
Description:
Used for accessing a text field. Usually an <input type = text> HTML tag. or a text area - a <textarea> tag
Input:
- how - Attribute used to identify the text field element.
- what - Value of that attribute.
Typical Usage:
ff.text_field(:id, 'user_name') # access the text field with an ID of user_name
ff.text_field(:name, 'address') # access the text field with a name of address
Output:
TextField object.
236 237 238 239 |
# File 'lib/firewatir/container.rb', line 236 def text_field(how, what = nil) locate if respond_to?(:locate) TextField.new(self, how, what) end |