Search code examples
sqlrft

IBM Rational Functional Tester - Hitting the Database


Im a new to this tool IBM RFT. How can I fetch data(in table form) from a Microsoft sql database dynamically for each time the script is running? And this data should be checked with the data(as a table) displayed on a webapp for verification. Is this possible in any way?


Solution

  • First of all: disable Simplified Scripting, or else it will screw up all your work sooner or later (usually very soon).
    StackOverflow is full of guides on how to fetch data from MS SQL, like
    How do I connect to a SQL Server 2008 database using JDBC?
    JDBC: Simple MSSql connection example not working

    And so the internet: http://www.javaworkspace.com/connectdatabase/connectSqlserver.do

    Now, to get the data from the table: https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000013976627
    https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000013731472
    https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000013836617

    A short code example:

    ITestDataTable t=(ITestDataTable)table_htmlTable_name().getTestData("contents");
    
    for(int i=0; i<t.getRowCount(); i++) {
        for(int j=0; j<t.getColumnCount(); j++) {
            logInfo("Row:" + i + " - Column: " + j +
                " - Value: " + t.getCell(i,j).toString());
        } 
    }
    

    I didn't try the code but should work ok. Change table_htmlTable_name with the corresponding object in your code. When you've learned how to read data from the table and the database, you can test them using a custom Verification Point.

    String expectedValue = getValueFromDb();
    String tableValue = getValueFromTable();
    vpManual( "VpName Here", expectedValue, tableValue).performTest;
    

    The vpManual() can check only simple values (double, String, int, bool)