preload

Web Table operations (WinRunner, TSL)

Posted by Albert Gareev on Oct 19, 2007 | Categories: Source codeWeb

Service Functions – Windows Web GUI / WinRunner

Get cell text

# Attention! This is the low-level function which is supposed to be called in the loop
# Has no obj_exists verification inside - take care about it outside
public function wb_ht_get_cell_text(in table, in row, in col, out value) {
 auto rc,actual_text_length,count;
 auto col_count, row_count;
 
 value = "";

# Check if the col is out of range
 rc = tbl_get_cols_count(table, col_count);
 if (rc != E_OK) return(E_GENERAL_ERROR);
 if (col > col_count) {
  value = "";
  return(E_OK); 
  } 

# Check if the row is out of range
 rc = tbl_get_rows_count(table, row_count);
 if (rc != E_OK) return(E_GENERAL_ERROR);
 if (row > row_count) {
  value = "";
  return(E_OK); 
  } 

# Note: this block is the workaround for non-rectangular tables 
 rc = web_obj_get_text(table, "#" & row, "#" & col, value);
 if (rc != E_OK) {
  value = "";
  return(E_OK); 
  } 
  
# Get text if cell exists  
 rc = web_tbl_get_cell_data(table, "#" & row, "#" & col, 0, value, actual_text_length);  
 if (rc != E_OK) rc = E_GENERAL_ERROR;
  
 return(rc); 
}

Get cell object

# Attention! This is the low-level function which is supposed to be called in the loop
# Has no obj_exists verification inside - take care about it outside
public function wb_ht_get_cell_obj(in table, in row, in col, in obj_class, in obj_loc, out obj_desc) {
 auto rc;
 auto col_count, row_count;
 
 obj_desc = "";

# Check if the col is out of range
 rc = tbl_get_cols_count(table, col_count);
 if (rc != E_OK) return(E_GENERAL_ERROR);
 if (col > col_count) {
  obj_desc = "";
  return(E_NOT_FOUND); 
  } 

# Check if the row is out of range
 rc = tbl_get_rows_count(table, row_count);
 if (rc != E_OK) return(E_GENERAL_ERROR);
 if (row > row_count) {
  obj_desc = "";
  return(E_NOT_FOUND); 
  } 

 if (obj_loc == "") obj_loc = 0;  
  
# Get obj if cell exists  
 rc = web_obj_get_child_item(table, row, col, obj_class, obj_loc, obj_desc);  
  
 return(rc); 
}

Find column by RegEx

# Attention! This is the low-level function which is supposed to be called in the loop
# Has no obj_exists verification inside - take care about it outside
public function wb_ht_get_cell_col(in table, in header_row, in col_key_regex, out col) {
 auto rc, i, col_count;
 auto cell_text;
 
 rc = tbl_get_cols_count(table, col_count);
 if (rc != E_OK) return(E_GENERAL_ERROR);

 for (i=1;i<=col_count;i++) {
  rc = wb_ht_get_cell_text(table, header_row, i, cell_text);
  if (rc != E_OK) return(E_GENERAL_ERROR);
  rc = match(cell_text, col_key_regex);
  if (rc>0) {
   col = i;
   return(E_OK);
   }
  }
  
 return(E_NOT_FOUND); 
}

Find row by RegEx

# Attention! This is the low-level function which is supposed to be called in the loop
# Has no obj_exists verification inside - take care about it outside
public function wb_ht_get_cell_row(in table, in header_col, in row_key_regex, out row) {
 auto rc, i, row_count;
 auto cell_text;
 
 rc = tbl_get_rows_count(table, row_count);
 if (rc != E_OK) return(E_GENERAL_ERROR);

 for (i=1;i<=row_count;i++) {
  rc = wb_ht_get_cell_text(table, i, header_col, cell_text);
  if (rc != E_OK) return(E_GENERAL_ERROR);
  rc = match(cell_text, row_key_regex);
  if (rc>0) {
   row = i;
   return(E_OK);
   }
  }
  
 return(E_NOT_FOUND); 
}

Check table exists with defined text in expected cell

public function wb_ht_tbl_cell_exists(in location, in key_cell, in key_row, in key_column, out table_desc, in regex_flag) {
 auto rc;
 auto t_desc, cell_text;
 
 t_desc = "{class: object,MSW_class: html_table}";
 GUI_desc_set_attr(t_desc, "location", location);
 
 rc = obj_exists(t_desc);
 if (rc != E_OK) return(E_NOT_FOUND);

 rc = wb_ht_get_cell_text(t_desc, key_row, key_column, cell_text);
 if (rc != E_OK) return(E_GENERAL_ERROR);
 if (cell_text == "") return(E_ITEM_NOT_FOUND);
 
 rc = str_text_test(str_trim_web(cell_text), key_cell, regex_flag);
 if (!rc) return(E_ITEM_NOT_FOUND);

 table_desc = t_desc;
 return(E_OK); 
}


Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.