Select a link in a search results table based on a formatted value in the row.

Speedy993Speedy993 Posts: 16

I have a web app that will display a list of records after a search. I need the test to look at the first column of each row in the returned results. The rows of data are coming from two places and so the first column of each row will have slightly different formats based on the source of the data. If the cell in a row does not contain a dash (-), I want to select the link that the cell contains to go to a detail data page. The first row that meets my criteria should be selected.
Can this be done in SOATest itself or do I need javascript to do this? Not being very proficient in java or javascript and not having used SOATest in this fashion before, I am not sure how to proceed. Would I want to use a HTTP Traffic Extension Tool?

Can someone offer this noob some help?

Thanks!

Comments

  • jakubiakjakubiak Posts: 645 admin
    edited April 3

    Record your scenario as normal. Then modify the test that performs the click on the link by opening the test, and chaning the Element Locator option to "Use Script". Then you define a script that returns the element that you want to click on. I have created a sample script against the demo site http://parabank.parasoft.com that clicks on the link in the first cell whose text contains the value "12345". You can modify this script to find the table in your application and search for the text you want to find. I have attached a SOAtest .tst file as an example. For reference, here is the script that I am using:

    import com.parasoft.api.*;
    import org.w3c.dom.*;
    import webking.api.*;
    import webking.api.browser2.*;
    
    public Node clickTableLink(BrowserTestContext context) {
      // Get document
      Document doc = context.getDocument();
      // Get table element
      Element table = doc.getElementById("accountTable");
      if (table != null) {
        // Define index of column
        int colIndex = 0;
        // Count number of rows
        String[] columnCells = WebBrowserTableUtil.getCellValuesForColumn(colIndex, table);
        int numRows = columnCells.length;
        //Application.showMessage("numRows: " + numRows);
        for (int i = 0; i < numRows; ++i) {
          //Application.showMessage(i + ": " + columnCells[i])
          // Check for value in cell that triggers a click
          if (columnCells[i].contains("12345")) {
            // Table headers are considered a row but are not included in columnCells
            Element row = WebBrowserTableUtil.getRow(i + 1, table);
            if (row != null) {
              //Application.showMessage("row: " + row);
              // Return the link
              Element link = WebBrowserTableUtil.getLinkFromCell(colIndex, row);
              //Application.showMessage("link: " + link);
              if (link != null) {
                return link;
              }
            }
          }
        }
      }
      return null;
    }
    
  • Speedy993Speedy993 Posts: 16

    Thanks so much jakubiak. I will give it a shot. I appreciate your assistance.

  • Speedy993Speedy993 Posts: 16

    Sorry I have not replied back until now. With some very minor tweaking, this worked great for me. Thanks!

Sign In or Register to comment.