Example usage for org.apache.poi.hssf.usermodel HSSFSheet getLastRowNum

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getLastRowNum

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFSheet getLastRowNum.

Prototype

@Override
public int getLastRowNum() 

Source Link

Document

Gets the number last row on the sheet.

Usage

From source file:swift.selenium.Automation.java

License:Open Source License

/** Loads the Config sheet into HashMap **/
public static void LoadConfigData(String configFile) throws IOException {

    try {//  w w  w .  ja  v a2s .  c om

        Date initialDate = new Date();
        String strInitialDate = dtFormat.format(initialDate);
        TransactionMapping.report.setFromDate(strInitialDate);

        DataFormatter format = new DataFormatter();
        //String projectPath = System.getProperty("user.dir");
        //String configPath = projectPath + "\\CommonResources\\Config.xls";
        HSSFSheet configSheet = ExcelUtility.GetSheet(configFile, "Config");
        for (int rowIndex = 1; rowIndex <= configSheet.getLastRowNum(); rowIndex++) {
            HSSFRow rowActual = configSheet.getRow(rowIndex);
            String parameterName = format.formatCellValue(rowActual.getCell(0));
            String value = format.formatCellValue(rowActual.getCell(1));
            // Following 'if' is replacement of above, checks if parameterName and value are neither null nor Blank
            if (StringUtils.isNotBlank(parameterName) || StringUtils.isNotBlank(value)) {
                configHashMap.put(parameterName, value);
            }

        }

        if (configHashMap.containsKey("MOBILETEST")) {
            if (configHashMap.get("MOBILETEST").toString().equalsIgnoreCase("true")) {
                String appiumconfigPath = configHashMap.get("APPIUM_CONFIG_PATH").toString();
                HSSFSheet appiumconfigSheet = ExcelUtility.GetSheet(appiumconfigPath, "Config");
                int arowCount = appiumconfigSheet.getLastRowNum() + 1;

                for (int rowIndex = 1; rowIndex < arowCount; rowIndex++) {
                    HSSFRow rowActual = appiumconfigSheet.getRow(rowIndex);
                    String parameterName = format.formatCellValue(rowActual.getCell(0));
                    String value = format.formatCellValue(rowActual.getCell(1));

                    if (StringUtils.isNotBlank(parameterName) || StringUtils.isNotBlank(value)) {
                        appiumConfigMap.put(parameterName, value);
                    }
                }

            }
        }
    } catch (NullPointerException npe) {
        TransactionMapping.pauseFun("Null Values Found in Config Sheet");
        npe.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
        TransactionMapping.pauseFun(e.getMessage() + " From LoadConfig Function");
    }
}

From source file:swift.selenium.ExcelUtility.java

License:Open Source License

public static HSSFRow GetDataFromValues(String FilePath, String TestCaseID, String TransactionTypeFetched)
        throws IOException, InterruptedException, Exception {
    HSSFRow expectedRow = null;/*www. j  a v a 2s  . c  o  m*/
    HSSFSheet valuesSheet = GetSheet(FilePath, "Values");

    int rowCount = valuesSheet.getLastRowNum() + 1;
    int endRow = getRowCount(valuesSheet);
    if (endRow == 0) {
        TransactionMapping.pauseExecution = true;
    }

    for (int rowIndex = firstRow; rowIndex < firstRow + endRow; rowIndex++) {
        expectedRow = valuesSheet.getRow(rowIndex);
        WebHelper.GetCellInfo(FilePath, expectedRow, rowIndex, rowCount);
    }
    return expectedRow;
}

From source file:swift.selenium.ExcelUtility.java

License:Open Source License

public static int getRowCount(HSSFSheet valSheet) throws IOException {
    int loopRowCount = 0;
    firstRow = 1;//  w ww .ja v  a  2s  . c o m
    Boolean isFirstFound = false;

    int rowCount = valSheet.getLastRowNum() + 1;
    for (int rowIndex = 1; rowIndex < rowCount; rowIndex++) {
        HSSFRow row = valSheet.getRow(rowIndex);
        testCaseID = row.getCell(0);
        String testCase = null;
        if (testCaseID == null) {
            testCase = "";
        } else {
            testCase = testCaseID.toString();
        }
        transactionType = row.getCell(1);
        if (testCaseID == null && transactionType == null) {
            break;
        } else if (testCase.equalsIgnoreCase(TransactionMapping.testCaseID.toString())
                && transactionType.toString().equals(TransactionMapping.transactionType.toString())) {
            if (firstRow == 1 && !isFirstFound) {
                firstRow = rowIndex;
                isFirstFound = true;
            }
            loopRowCount++;
        } else if ((!testCase.equalsIgnoreCase(TransactionMapping.testCaseID.toString())
                || !transactionType.toString().equals(TransactionMapping.transactionType.toString()))
                && !isFirstFound && rowIndex == rowCount - 1) {
            TransactionMapping.pauseFun("TestCaseID Or Transaction Didn't Match "
                    + TransactionMapping.testCaseID.toString() + " " + TransactionMapping.transactionType);
            ExcelUtility.writeReport(TransactionMapping.report);
            break;
        }
    }
    return loopRowCount;
}

From source file:swift.selenium.MainController.java

License:Open Source License

/**Finds the Start Pointer in the MainController Sheet and executes the Transaction**/
public static Reporter ControllerData(String FilePath) throws Exception {

    Reporter report = new Reporter();
    HSSFSheet reqSheet = ExcelUtility.GetSheet(Automation.configHashMap.get("CONTROLLER_FILEPATH").toString(),
            "MainControlSheet");
    sheetValues = WebHelper.getValueFromHashMap(reqSheet);
    int execFlag = Integer.parseInt(sheetValues.get("ExecuteFlag").toString());
    int rowCount = reqSheet.getLastRowNum() + 1;
    int colCount = 0;
    boolean isStartFound = false;

    for (int rowindex = 0; rowindex < rowCount && !isStartFound; rowindex++) {
        controllerRow = reqSheet.getRow(rowindex);
        //TM: commented the following to avoid continue
        /*if(controllerRow.getCell(execFlag).toString().equals(null))
        {//  ww  w.j av a2  s.c om
           continue;
        }*/
        //TM: following 'if' is replacement of the above
        if (controllerRow.getCell(execFlag) != null) {
            if (controllerRow.getCell(execFlag).toString().equals("Y")) {
                colCount = controllerRow.getLastCellNum() + 1;
                for (int colIndex = execFlag + 1; colIndex < colCount; colIndex++) {
                    HSSFCell cellVal = controllerRow.getCell(colIndex);

                    //TM: commented the following code to avoid continue
                    /*if(cellVal == null)
                    {
                       System.out.println("START not Found");
                       continue;
                            
                    }
                    else */
                    //TM: following new if added to check for null and else part for the same.
                    if (cellVal != null) {
                        if (cellVal.toString().equalsIgnoreCase("START")) {
                            startCol = colIndex;
                            startRow = rowindex;
                            isStartFound = true;
                            break;

                        }
                    } else {
                        System.out.println("START not Found");
                    }

                }
            } else {
                System.out.println("Execute Flag is N");
            }
        }

    }

    for (int rowIndex = startRow; rowIndex < rowCount; rowIndex++) {
        pauseExecution = false;
        controllerRow = reqSheet.getRow(rowIndex);
        colCount = controllerRow.getLastCellNum() + 1;
        testDesciption = WebHelper.getCellData("Test_Description", reqSheet, rowIndex, sheetValues);
        HSSFCell executeFlag = controllerRow.getCell(execFlag);
        controllerTestCaseID = controllerRow
                .getCell(Integer.parseInt(sheetValues.get("TestCaseID").toString()));
        controllerGroupName = controllerRow.getCell(Integer.parseInt(sheetValues.get("GroupName").toString()));

        if (controllerTestCaseID.getStringCellValue().equalsIgnoreCase("")
                || controllerTestCaseID.equals(null)) {
            System.out.println("No KeyWord Found");
            continue;
        }

        //TM: Commented the code to avoid continue
        /*if(executeFlag == null)
        {
           System.out.println("Execute Flag is not Set");
           continue;
        }*/

        if (executeFlag != null) {
            if (executeFlag.toString().equalsIgnoreCase("Y")) {
                for (int columnIndex = startCol + 1; columnIndex < colCount && !pauseExecution; columnIndex++) {
                    controllerTransactionType = controllerRow.getCell(columnIndex);
                    //TM: commented the following code to avoid continue
                    /*if(controllerTransactionType == null || controllerTransactionType.getStringCellValue().equals(""))
                    {
                       System.out.println("No Transaction Found in the Maincontroller at Cell : "+columnIndex);
                       continue;
                    }*/

                    //TM: Updated following sysout to give an understanding of what is getting printed on the console
                    System.out.println("Value of controllerTransactionType: " + controllerTransactionType);

                    //TM: wrapped the PAUSE if into another if as replacement of above commented if
                    if (controllerTransactionType != null
                            && StringUtils.isNotBlank(controllerTransactionType.getStringCellValue())) {
                        if (controllerTransactionType.toString().equalsIgnoreCase("PAUSE")) {
                            TransactionMapping.pauseFun("Do You Wish To Continue");
                        } else {
                            report = TransactionMapping.TransactionInputData(
                                    controllerTransactionType.getStringCellValue(),
                                    controllerTestCaseID.getStringCellValue(), testDesciption,
                                    controllerGroupName.getStringCellValue());
                        }
                    } else {
                        System.out
                                .println("No Transaction Found in the Maincontroller at Cell : " + columnIndex);
                    }

                }
            }
        } else {
            System.out.println("Execute Flag is not Set");
        }

    }
    startCol = execFlag + 1;

    return report;
}

From source file:swift.selenium.TransactionMapping.java

License:Open Source License

public static Reporter TransactionInputData(String transaction, String testId, String description, String group)
        throws Exception {

    HashMap<String, Object> inputHashTable = new HashMap<String, Object>();
    HSSFSheet workSheet = ExcelUtility.GetSheet(
            Automation.configHashMap.get("TRANSACTION_INPUT_FILEPATH").toString(),
            "Web_Transaction_Input_Files");
    int rowCount = workSheet.getLastRowNum() + 1;
    transactionType = transaction;/*w w w .  j  ava  2s . c  om*/
    testCaseID = testId;
    for (int rowIndex = 1; rowIndex < rowCount; rowIndex++) {
        String transactionCode = getCellData("TransactionCode", workSheet, rowIndex, inputHashTable);
        String transactionType = getCellData("TransactionType", workSheet, rowIndex, inputHashTable);
        String directoryPath = getCellData("DirPath", workSheet, rowIndex, inputHashTable).toString();
        String inputExcel = getCellData("InputSheet", workSheet, rowIndex, inputHashTable).toString();

        String TestFilePath = Automation.configHashMap.get("INPUT_DATA_FILEPATH").toString()
                + directoryPath.toString() + File.separator + inputExcel.toString();

        if (transactionType.toString().equalsIgnoreCase(transaction.toString())) {
            if (transactionCode != null && directoryPath == null
                    && transaction.toString().equalsIgnoreCase(transactionType.toString())) {
                report.strInputPath = "";
                report.strOperationType = "";
                report.strTransactioncode = transactionCode;
                report.strTestDescription = description;
                DataInput("", testCaseID.toString(), transactionType, transactionCode, "");
                break;
            }

            if (!transactionType.toString().startsWith("Verify")) {
                operationType = "Input";
            }

            if (transactionType.toString().startsWith("Verify") && (!directoryPath.toString().isEmpty())
                    && (!inputExcel.toString().isEmpty())) {
                operationType = "InputandVerfiy";

            } else if (transactionType.toString().startsWith("Verify") && (directoryPath.toString().isEmpty())
                    && (inputExcel.toString().isEmpty())) {
                operationType = "Verify";
            }
            if (transaction.toString().equalsIgnoreCase(transactionType.toString())) {
                if ((directoryPath == null || inputExcel == null) && operationType != "Verify") {
                    pauseFun("Please Enter the directory or excelsheet name");
                } else {
                    String inputFilePath = null;
                    if (operationType != "Verify") {
                        inputFilePath = Automation.configHashMap.get("INPUT_DATA_FILEPATH").toString()
                                + directoryPath.toString() + File.separator + inputExcel.toString();
                    }
                    System.out.println(inputFilePath);
                    report.strInputPath = inputFilePath;
                    report.strOperationType = operationType;
                    report.strTestDescription = description;
                    report.strTransactioncode = transactionCode;
                    report.strGroupName = group;
                    DataInput(inputFilePath, testCaseID.toString(), transactionType, transactionCode,
                            operationType);
                    break;
                }
            }
        } else if (!transactionType.toString().equalsIgnoreCase(transaction.toString())
                && rowIndex == rowCount - 1) {
            pauseFun("Transaction " + transaction.toString() + " Not Found");
            ExcelUtility.writeReport(report);
        }
    }

    return null;

}

From source file:swift.selenium.WebHelper.java

License:Open Source License

public static void GetCellInfo(String FilePath, HSSFRow rowValues, int valuesRowIndex, int valuesRowCount)
        throws IOException // newly Added two Variables for Action Loop
{
    try {/*from ww  w . j a va 2  s.  com*/
        frmDate = new Date();
        isDynamicNumFound = true;
        List<WebElement> controlList = null;
        //String testCase = null;
        String ctrlValue = null;
        //HSSFRow structureRow=null;
        InputStream myXls = new FileInputStream(FilePath);
        HSSFWorkbook workBook = new HSSFWorkbook(myXls);
        format = workBook.createDataFormat();
        HSSFSheet sheetStructure = workBook.getSheet("Structure");
        //HSSFCell controlValue=null;
        int rowCount = sheetStructure.getLastRowNum() + 1;
        HSSFSheet headerValues = ExcelUtility.GetSheet(FilePath, "Values");
        //HSSFRow headerRow = headerValues.getRow(0);
        System.out.println(Automation.dtFormat.format(frmDate));
        String fromDate = Automation.dtFormat.format(frmDate);
        TransactionMapping.report.setFromDate(fromDate);
        structureHeader = getValueFromHashMap(sheetStructure);
        columnName = null;
        int dynamicIndexNumber;//Added for Action Loop
        String imageType, indexVal, controlName, executeFlag, action, logicalName, controltype, controlID,
                dynamicIndex, newDynamicIndex, rowNo, colNo;//newly Added for Action Loop

        //Setting of default reporting values before executing a transaction
        TransactionMapping.report.setStrMessage("");
        TransactionMapping.report.setStrStatus("PASS");

        for (int rowIndex = 1; rowIndex < rowCount; rowIndex++) {
            //structureRow = sheetStructure.getRow(rowIndex);
            controlName = getCellData("ControlName", sheetStructure, rowIndex, structureHeader);//structureRow.getCell(3);
            executeFlag = getCellData("ExecuteFlag", sheetStructure, rowIndex, structureHeader);//structureRow.getCell(0);

            if (executeFlag.toString().equals("Y")) {
                WebElement webElement = null;
                imageType = getCellData("ImageType", sheetStructure, rowIndex, structureHeader);
                action = getCellData("Action", sheetStructure, rowIndex, structureHeader);//structureRow.getCell(1);
                logicalName = getCellData("LogicalName", sheetStructure, rowIndex, structureHeader);//structureRow.getCell(2);
                controltype = getCellData("ControlType", sheetStructure, rowIndex, structureHeader);//structureRow.getCell(4);
                controlID = getCellData("ControlID", sheetStructure, rowIndex, structureHeader);//structureRow.getCell(6);
                indexVal = getCellData("Index", sheetStructure, rowIndex, structureHeader);//structureRow.getCell(7);
                columnName = getCellData("ColumnName", sheetStructure, rowIndex, structureHeader);
                rowNo = getCellData("RowNo", sheetStructure, rowIndex, structureHeader);
                colNo = getCellData("ColumnNo", sheetStructure, rowIndex, structureHeader);
                dynamicIndex = getCellData("DynamicIndex", sheetStructure, rowIndex, structureHeader);//Added code for Loop

                if (action.equalsIgnoreCase("LOOP")) {
                    loopRow = rowIndex + 1;
                }

                // if rownum != 1 , then do below steps 
                if ((valuesRowIndex != ExcelUtility.firstRow) && (dynamicIndex.length() > 0)) //valuesRowIndex
                {

                    dynamicIndexNumber = Integer
                            .parseInt(dynamicIndex.substring(dynamicIndex.length() - 1, dynamicIndex.length()));

                    if (ExcelUtility.dynamicNum == 0) {
                        ExcelUtility.dynamicNum = dynamicIndexNumber + 1;
                        isDynamicNumFound = false;

                    } else if (ExcelUtility.dynamicNum != 0 && isDynamicNumFound) {
                        ExcelUtility.dynamicNum = ExcelUtility.dynamicNum + 1;
                        isDynamicNumFound = false;
                    }

                    newDynamicIndex = dynamicIndex.replace(String.valueOf(dynamicIndexNumber),
                            String.valueOf(ExcelUtility.dynamicNum));
                    controlName = controlName.replace(dynamicIndex, newDynamicIndex);
                }

                /**Stop the execution of the current test case unexpected alert**/
                control = controltype.toString();

                if (!action.equalsIgnoreCase("LOOP") && !action.equalsIgnoreCase("END_LOOP")) {
                    //boolean isControlValueFound =false;
                    if (valuesHeader.isEmpty() == true) {
                        valuesHeader = getValueFromHashMap(headerValues);
                    }
                    Object actualValue = null;
                    if (logicalName != null) {
                        actualValue = valuesHeader.get(logicalName.toString());
                    } //headerRow.getCell(colIndex);
                    if (actualValue == null) {
                        System.out.println("Null");
                    } else {
                        //int colIndex = Integer.parseInt(actualValue.toString());
                        //controlValue = rowValues.getCell(colIndex);
                        ctrlValue = getCellData(logicalName, headerValues, valuesRowIndex, valuesHeader);

                        testcaseID = rowValues
                                .getCell(Integer.parseInt(valuesHeader.get("TestCaseID").toString()));

                        if (testcaseID == null) {
                            testCase = "";
                        } else {
                            testCase = testcaseID.toString();
                        }
                        transactionType = rowValues
                                .getCell(Integer.parseInt(valuesHeader.get("TransactionType").toString()));
                    }

                    if ((action.equals("I") && !ctrlValue.isEmpty())
                            || (action.equals("V") && !ctrlValue.isEmpty()) || !action.equals("I")) {
                        if (!controltype.startsWith("Sikuli")) {
                            if (!action.equalsIgnoreCase("LOOP") && !controltype.equalsIgnoreCase("Wait")
                                    && !action.equalsIgnoreCase("END_LOOP")
                                    && !controltype.equalsIgnoreCase("Browser")
                                    && !controltype.equalsIgnoreCase("Window")
                                    && !controltype.equalsIgnoreCase("Alert")
                                    && !controltype.equalsIgnoreCase("URL")
                                    && !controltype.equalsIgnoreCase("WaitForJS")
                                    && !controltype.contains("Robot")
                                    && !controltype.equalsIgnoreCase("BrowserType")
                                    && !controltype.equalsIgnoreCase("BrowserAuth")
                                    && !controltype.equalsIgnoreCase("Calendar")
                                    && !controltype.equalsIgnoreCase("CalendarNew")
                                    && !controltype.equalsIgnoreCase("CalendarIPF")
                                    && !controltype.equalsIgnoreCase("CalendarEBP")
                                    && (!action.equalsIgnoreCase("Read")
                                            || ((action.equalsIgnoreCase("Read") && !controlName.isEmpty())))
                                    && !controltype.equalsIgnoreCase("JSScript")
                                    && !controltype.equalsIgnoreCase("DB") && !controlID.equalsIgnoreCase("XML")
                                    && !controltype.startsWith("Process") && !controltype.startsWith("Destroy")
                                    && !controltype.startsWith("ReadSikuli")
                                    && !controltype.equalsIgnoreCase("WebService")
                                    && !controltype.equalsIgnoreCase("WebService_REST")
                                    && !controltype.equalsIgnoreCase("JSONResp")
                                    && !action.equalsIgnoreCase("VA") && !action.equalsIgnoreCase("VA")
                                    && !controltype.equalsIgnoreCase("CaptureScreen")
                                    && !controltype.equalsIgnoreCase("CloseWindow")
                                    && !controlID.equalsIgnoreCase("DonutChart")
                                    && !controlID.equalsIgnoreCase("BarChart") && !action.equalsIgnoreCase("GB")
                                    && !controltype.equalsIgnoreCase("SwitchContext")
                                    && !controltype.equalsIgnoreCase("SwipeDown")) {
                                if ((indexVal.equalsIgnoreCase("") || indexVal.equalsIgnoreCase("0"))
                                        && !controlID.equalsIgnoreCase("TagValue")
                                        && !controlID.equalsIgnoreCase("TagText")) {
                                    webElement = getElementByType(controlID, controlName, control, imageType,
                                            ctrlValue);

                                } else {
                                    controlList = getElementsByType(controlID, controlName, control, imageType,
                                            ctrlValue);

                                    if (controlList != null && controlList.size() > 1) {
                                        webElement = GetControlByIndex(indexVal, controlList, controlID,
                                                controlName, control, ctrlValue); //, ISelenium selenium)
                                    } else {
                                        break;
                                    }
                                }
                            }
                        } else {
                            sikuliScreen = new Screen();
                        }
                    }

                    /***   Perform action on the identified control   ***/
                    doAction(imageType, controltype, controlID, controlName, ctrlValue, logicalName, action,
                            webElement, true, sheetStructure, headerValues, rowIndex, rowCount, rowNo, colNo);
                }

                if (action == "END_LOOP" && (valuesRowCount != valuesRowIndex)) {
                    loopRow = 1;
                    break;
                }

            } else {
                System.out.println("ExecuteFlag is N");
            }
        }

        //Setting of reporting values after execution in case of no exception
        Date toDate = new Date();
        TransactionMapping.report.setFromDate(Automation.dtFormat.format(frmDate));
        TransactionMapping.report.setStrIteration(Automation.configHashMap.get("CYCLENUMBER").toString());
        TransactionMapping.report.setStrTestcaseId(TransactionMapping.testCaseID.toString());
        //TransactionMapping.report.setStrGroupName(MainController.controllerGroupName.toString());
        TransactionMapping.report.setStrTrasactionType(TransactionMapping.transactionType.toString());
        //TransactionMapping.report.setStrTestDescription(MainController.testDesciption);
        TransactionMapping.report.setToDate(Automation.dtFormat.format(toDate));

        //Setting status for field verification failures
        if (fieldVerFailCount > 0) {
            TransactionMapping.report.setStrMessage("Check Detailed Results");
            TransactionMapping.report.setStrStatus("FAIL");
        }
    } catch (Exception e) {
        TransactionMapping.pauseFun(e.getMessage());
    } finally {
        structureHeader.clear();
        valuesHeader.clear();
        ExcelUtility.writeReport(TransactionMapping.report);
        fieldVerFailCount = 0;
    }
}

From source file:SwiftSeleniumWeb.Automation.java

License:Open Source License

/**Loads the Config sheet into HashMap**/
public static void LoadConfigData()
        throws IOException, SQLException, ClassNotFoundException, URISyntaxException {

    try {/*from   ww w . java 2  s . c o m*/

        Date initialDate = new Date();
        String strInitialDate = dtFormat.format(initialDate);
        SwiftSeleniumWeb.WebDriver.report.setFromDate(strInitialDate);

        DataFormatter format = new DataFormatter();
        String projectPath = System.getProperty("user.dir");
        String configPath = projectPath + "\\CommonResources\\Config.xls";
        HSSFSheet configSheet = ExcelUtility.GetSheet(configPath, "Config");
        int rowCount = configSheet.getLastRowNum() + 1;

        for (int rowIndex = 1; rowIndex < rowCount; rowIndex++) {
            HSSFRow rowActual = configSheet.getRow(rowIndex);
            String parameterName = format.formatCellValue(rowActual.getCell(0));
            String value = format.formatCellValue(rowActual.getCell(1));

            if (StringUtils.isNotBlank(parameterName) || StringUtils.isNotBlank(value)) {
                configHashMap.put(parameterName, value);
            }

        }
    } catch (NullPointerException npe) {
        MainController.pauseFun("Null Values Found in Config Sheet");
    } catch (Exception e) {
        MainController.pauseFun(e.getMessage() + " From LoadConfig Function");
    }
}

From source file:SwiftSeleniumWeb.ExcelUtility.java

License:Open Source License

/**
 * Reads the Values sheet from Input Excel and returns the row 
 *  //from   w  w w.ja  va 2  s .c o  m
 * @param FilePath
 * @param TestCaseID
 * @param TransactionType
 * @return
 * @throws IOException
 * @throws InterruptedException
 * @throws Exception
 */
public static HSSFRow GetDataFromValues(String FilePath, String TestCaseID, String TransactionType)
        throws IOException, InterruptedException, Exception {
    HSSFRow expectedRow = null;
    HSSFSheet valuesSheet = GetSheet(FilePath, "Values");

    int rowCount = valuesSheet.getLastRowNum() + 1;
    int endRow = getRowCount(valuesSheet);
    if (endRow == 0) {
        MainController.pauseExecution = true;
    }

    for (int rowIndex = firstRow; rowIndex < firstRow + endRow && !MainController.pauseExecution; rowIndex++) {
        expectedRow = valuesSheet.getRow(rowIndex);
        WebHelper.GetCellInfo(FilePath, expectedRow, rowIndex, rowCount);
    }
    return expectedRow;
}

From source file:SwiftSeleniumWeb.ExcelUtility.java

License:Open Source License

/**
 * Get row count of a sheet //from  w ww  .ja  v  a  2  s.co m
 * @param valSheet
 * @return
 * @throws IOException
 */
public static int getRowCount(HSSFSheet valSheet) throws IOException {
    int loopRowCount = 0;
    firstRow = 1;
    Boolean isFirstFound = false;

    int rowCount = valSheet.getLastRowNum() + 1;
    for (int rowIndex = 1; rowIndex < rowCount; rowIndex++) {
        HSSFRow row = valSheet.getRow(rowIndex);
        testCaseID = row.getCell(0);
        String testCase = null;
        if (testCaseID == null) {
            testCase = "";
        } else {
            testCase = testCaseID.toString();
        }
        transactionType = row.getCell(1);
        if (testCaseID == null && transactionType == null) {
            break;
        } else if (testCase.equalsIgnoreCase(MainController.controllerTestCaseID.toString())
                && transactionType.toString().equals(MainController.controllerTransactionType.toString())) {
            if (firstRow == 1 && !isFirstFound) {
                firstRow = rowIndex;
                isFirstFound = true;
            }
            loopRowCount++;
        } else if ((!testCase.equalsIgnoreCase(MainController.controllerTestCaseID.toString())
                || !transactionType.toString().equals(MainController.controllerTransactionType.toString()))
                && !isFirstFound && rowIndex == rowCount - 1) {
            MainController.pauseFun("TestCaseID Or Transaction Didn't Match "
                    + MainController.controllerTestCaseID + " " + MainController.controllerTransactionType);
            ExcelUtility.writeReport(SwiftSeleniumWeb.WebDriver.report);
            break;
        }
    }
    return loopRowCount;
}

From source file:SwiftSeleniumWeb.MainController.java

License:Open Source License

/**
 * Finds the Start Pointer in the MainController Sheet and executes the Transaction
 * //  w w w. j  av  a2 s  .c  om
 * @param FilePath
 * @return
 * @throws Exception
 */
public static Reporter ControllerData(String FilePath) throws Exception {
    Reporter report = new Reporter();
    HSSFSheet reqSheet = ExcelUtility.GetSheet(Automation.configHashMap.get("CONTROLLER_FILEPATH").toString(),
            "MainControlSheet");
    sheetValues = WebHelper.getValueFromHashMap(reqSheet);
    int execFlag = Integer.parseInt(sheetValues.get("ExecuteFlag").toString());
    int rowCount = reqSheet.getLastRowNum() + 1;
    int colCount = 0;
    boolean isStartFound = false;
    for (int rowindex = 0; rowindex < rowCount && !isStartFound; rowindex++) {
        controllerRow = reqSheet.getRow(rowindex);

        if (controllerRow.getCell(execFlag) != null) {
            if (controllerRow.getCell(execFlag).toString().equals("Y")) {
                colCount = controllerRow.getLastCellNum() + 1;
                for (int colIndex = execFlag + 1; colIndex < colCount; colIndex++) {
                    HSSFCell cellVal = controllerRow.getCell(colIndex);

                    if (cellVal != null) {
                        if (cellVal.toString().equalsIgnoreCase("START")) {
                            startCol = colIndex;
                            startRow = rowindex;
                            isStartFound = true;
                            break;

                        }
                    } else {
                        System.out.println("START not Found");
                    }

                }
            } else {
                System.out.println("Execute Flag is N");
            }
        }

    }

    for (int rowIndex = startRow; rowIndex < rowCount; rowIndex++) {
        pauseExecution = false;
        controllerRow = reqSheet.getRow(rowIndex);
        colCount = controllerRow.getLastCellNum() + 1;
        testDesciption = WebHelper.getCellData("Test_Description", reqSheet, rowIndex, sheetValues);
        HSSFCell executeFlag = controllerRow.getCell(execFlag);
        controllerTestCaseID = controllerRow
                .getCell(Integer.parseInt(sheetValues.get("TestCaseID").toString()));
        controllerGroupName = controllerRow.getCell(Integer.parseInt(sheetValues.get("GroupName").toString()));

        if (controllerTestCaseID.getStringCellValue().equalsIgnoreCase("")
                || controllerTestCaseID.equals(null)) {
            System.out.println("No KeyWord Found");
            continue;
        }

        if (executeFlag != null) {
            if (executeFlag.toString().equalsIgnoreCase("Y")) {
                for (int columnIndex = startCol + 1; columnIndex < colCount && !pauseExecution; columnIndex++) {
                    controllerTransactionType = controllerRow.getCell(columnIndex);

                    System.out.println("Value of controllerTransactionType: " + controllerTransactionType);

                    if (controllerTransactionType != null
                            && StringUtils.isNotBlank(controllerTransactionType.getStringCellValue())) {
                        if (controllerTransactionType.toString().equalsIgnoreCase("PAUSE")) {
                            pauseFun("Do You Wish To Continue");
                        } else {
                            report = TransactionMapping.TransactionInputData(controllerTestCaseID,
                                    controllerTransactionType,
                                    Automation.configHashMap.get("TRANSACTION_INPUT_FILEPATH").toString());
                        }
                    } else {
                        System.out
                                .println("No Transaction Found in the Maincontroller at Cell : " + columnIndex);
                    }

                }
            }
        } else {
            System.out.println("Execute Flag is not Set");
        }

    }
    startCol = execFlag + 1;
    return report;
}