I have no idea if this will help you, i wrote it awhile ago and it still works
for me. I ripped out as much app specific junk as i could :)
look at 'multi_find' and work your way down. Its not exactly what you want but
might give you ideas. "find_value" would be values in rows, "find_type" would
be values in the header.
Also of note, this is note pretty, and has all sorts of hacky bits in it ;)
# beware of dog
class Support_Grid_Search
def initialize()#stuff removed
@base_table = ''#this would be specific to your app
# Error value 'constant'
@error = -1
end
def find( find_value, find_type )
if grid_find(find_value, find_type) == @error
return( generic_find( find_value, find_type, 'find' ) )
else
return( true )
end
end
# Multi find DOES NOT SUPPORT GENERIC FIND - deal with it
def multi_find( find_value_a, find_type_a, find_value_b, find_type_b )
if multi_grid_find( find_value_a, find_type_a, find_value_b,
find_type_b ) == @error
return( false )
else
return( true )
end
end
def multi_grid_find( find_value_a, find_type_a, find_value_b,
find_type_b )
# Locate both of the header columns
cell_a = find_in_row(1,1,find_type_a)
cell_b = find_in_row(1,1,find_type_b)
if cell_a == @error or cell_b == @error
# 'generic' search
return( @error )
end
# BOTH values have to match in a row, this is annoying O_o
row_count = @base_table.row_count()
for row in (2..row_count)
found_row = find_in_column(cell_a,row,find_value_a)
if found_row == @error
return( @error )
else
result_cell =
find_in_row(found_row,1,find_value_b)
if result_cell != @error
return( found_row )
end
end
end
end
# multi means multiple values in the row, not rows to check
def multi_click( find_value_a, find_type_a, find_value_b, find_type_b )
row = multi_grid_find( find_value_a, find_type_a, find_value_b,
find_type_b )
if row == @error
@logger.log('unable to find row to check')
else
@base_table[row].click
end
end
def check( find_value, find_type )
if grid_check(find_value, find_type) == @error
return( generic_find( find_value, find_type, 'check' ) )
else
return( true )
end
end
def grid_check(find_value, find_type)
row = grid_find(find_value, find_type)
if row == @error
return( row )
else
@base_table[row][1].span(:index,1).checkbox(:index,1).set()
return( row )
end
end
def grid_find(find_value, find_type)
# Figure out how many rows there are in the table
row_count = @base_table.row_count()
# If theres only one the grid is empty
if row_count == 1
@logger.log('nothing to search')
return( @error )
end
# Search the 'header' row, figure out what cell (column)
contains the data we want
cell = find_in_row(1,1,find_type)
# Skip it if you can't find it
if cell == @error
@logger.log('no column of type: ' + find_type)
return( @error )
end
# Now search down the column and return the results
return( find_in_column(cell,2,find_value) )
end
def find_in_row(row,start_cell,find_value)
cell_count = @base_table.column_count(row)
for cell in start_cell..cell_count
@base_table[row][cell].flash(1)
if @base_table[row][cell].text.gsub(/\r\n/, "
").include? find_value
return cell
end
end
return @error
end
def find_in_column(cell,start_row,find_value)
row_count = @base_table.row_count()
for row in start_row..row_count
begin
@base_table[row][cell].flash(1)
if @base_table[row][cell].text.include?
find_value
return row
end
rescue
# it seems the row_count is wrong, so just skip
the bad rows
end
end
return @error
end
def generic_find( find_value, find_type, find_or_check )
# REMOVED, too specific
end
end
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=6897&messageID=19889#19889
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general