Skip to content

General Actions

initDBConnection

Description: This function will initialize the database connection

ObjectName Action Input Condition Reference
Database 🟢 initDBConnection

Performs connection of Database

@Action(object = ObjectType.DATABASE, desc = "Initiate the DB transaction")
    public void initDBConnection() {
        try {
            if (verifyDbConnection()) {
                DatabaseMetaData metaData = dbconnection.getMetaData();
                Report.updateTestLog(Action, " Connected with " + metaData.getDriverName() + "\n"
                    + "Driver version " + metaData.getDriverVersion() + " \n"
                    + "Database product name " + metaData.getDatabaseProductName() + "\n"
                    + "Database product version " + metaData.getDatabaseProductVersion(),
                    Status.PASSNS);
            } else {
                Report.updateTestLog(Action, "Could not able to make DB connection ", Status.FAILNS);
            }
            } catch (ClassNotFoundException | SQLException ex) {
                Report.updateTestLog(Action, "Error connecting Database: " + ex.getMessage(),
                Status.FAILNS);
        }
    }

Internally uses the following Java logic :

    Class.forName(dbDriver);
    if (dbConnectionString != null && dbUser != null && dbPass != null) {
        dbconnection = DriverManager.getConnection(dbConnectionString, dbUser,dbPass);
    } else if (dbConnectionString != null) {
        dbconnection = DriverManager.getConnection(dbConnectionString);
    }

closeDBConnection

Description: This function will close the database connection

ObjectName Action Input Condition Reference
Database 🟢 closeDBConnection
@Action(object = ObjectType.DATABASE, desc = "Close the DB Connection")
    public void closeDBConnection() {
        try {
            if (closeConnection()) {
                Report.updateTestLog(Action, "DB Connection is closed", Status.PASSNS);
            } else {
                Report.updateTestLog(Action, "Error in closing the DB Connection ", Status.FAILNS);
            }
        } catch (SQLException ex) {
            Report.updateTestLog(Action, "Error: " + ex.getMessage(),
                Status.FAILNS);
        }
    }

Internally uses the following Java logic :

    dbconnection.close();
    statement.close();
    result.close();

assertDBResult

Description: This function will assert if the SQL result contains a particular data in a specific column after the execution of a SQL select statement.

Input Format : @ExpectedValue

Condition : Name of the column in which result is expected

ObjectName Action Input Condition Reference
Database 🟢 assertDBResult @Data nameOfDBColumn << Hardcoded Input
Database 🟢 assertDBResult DatasheetName:ColumnName nameOfDBColumn << Input from Datasheet
Database 🟢 assertDBResult %variableName% nameOfDBColumn <<Input from variable
@Action(object = ObjectType.DATABASE, desc = "Assert the value [<Input>] exist in the column [<Condition>] ", input = InputType.YES, condition = InputType.YES)
    public void assertDBResult() {
        if (assertDB(Condition, Data)) {
            Report.updateTestLog(Action, "Value " + Data + " exist in the Database", Status.PASSNS);
        } else {
            Report.updateTestLog(Action, "Value " + Data + " doesn't exist in the Database", Status.FAILNS);
        }
    }

public boolean assertDB(String columnName, String condition) {
    boolean isExist = false;
    try {
        result.beforeFirst();
        if (getColumnIndex(columnName) != -1) {
            while (result.next()) {
                if (Objects.equal(result.getString(columnName), condition)) {
                    isExist = true;
                    break;
                }
            }
        } else {
            Report.updateTestLog(Action, "Column " + columnName + " doesn't exist", Status.FAIL);
        }
    } catch (SQLException ex) {
        Report.updateTestLog(Action, "Error asserting the value in DB " + ex.getMessage(), Status.FAIL);
        return false;
    }
    return isExist;
    }

executeSelectQuery

Description: This function will execute the given select query on the database

Input Format : @SQL Query

ObjectName Action Input Condition
Database 🟢 executeSelectQuery @select designation from job where id=121;
@Action(object = ObjectType.DATABASE, desc = "Execute the Query in [<Input>]", input = InputType.YES)
    public void executeSelectQuery() {
        try {
            executeSelect();
            Report.updateTestLog(Action, "Executed Select Query", Status.DONE);
        } catch (SQLException ex) {
            Report.updateTestLog(Action, "Error executing the SQL Query: " + ex.getMessage(),
                Status.FAILNS);
        }   
    }

    public void executeSelect() throws SQLException {
        initialize();
        result = statement.executeQuery(Data);
        resultData = result.getMetaData();
        populateColumnNames();
    }    

executeDMLQuery

Description: This query will execute an SQL DML statement on the database and will commit the results back to the database

Input Format : @SQL Query

ObjectName Action Input Condition
Database 🟢 executeDMLQuery @UPDATE job SET "designation"=Tester WHERE id = 121;
Database 🟢 executeDMLQuery Sheet:Column
Database 🟢 executeDMLQuery %dynamicVar%
@Action(object = ObjectType.DATABASE, desc = "Execute the Query in [<Input>]", input = InputType.YES)
    public void executeDMLQuery() {
        try {
            if (executeDML()) {
                Report.updateTestLog(Action, " Table updated by using " + Data, Status.PASSNS);
            } else {
                Report.updateTestLog(Action, " Table not updated by using " + Data, Status.FAILNS);
            }
        } catch (SQLException ex) {
            Report.updateTestLog(Action, "Error executing the SQL Query: " + ex.getMessage(),
                Status.FAILNS);
        }
    }