public void createXLSReport() { String colName = Constants.RESULT + (CurrentTestDataSetID - 1); boolean isColExist = false; for (int c = 0; c < CurrentTestSuiteXls.getColumnCount(Constants.TEST_STEPS_SHEET); c++) { System.out.println(CurrentTestSuiteXls.getCellData(Constants.TEST_STEPS_SHEET, c, 2)); if (CurrentTestSuiteXls.getCellData(Constants.TEST_STEPS_SHEET, c, 1).equals(colName)) { isColExist = true; break; } } if (!isColExist) CurrentTestSuiteXls.addColumn(Constants.TEST_STEPS_SHEET, colName); int index = 0; for (int i = 2; i <= CurrentTestSuiteXls.getRowCount(Constants.TEST_STEPS_SHEET); i++) { if (CurrnetTestCaseName.equals( CurrentTestSuiteXls.getCellData(Constants.TEST_STEPS_SHEET, Constants.TEST_CASE_ID, i))) { if (ResultSet.size() == 0) CurrentTestSuiteXls.setCellData( Constants.TEST_STEPS_SHEET, colName, i, Constants.KEYWORD_SKIP); else CurrentTestSuiteXls.setCellData( Constants.TEST_STEPS_SHEET, colName, i, ResultSet.get(index)); index++; } } if (ResultSet.size() == 0) { // skip CurrentTestSuiteXls.setCellData( CurrnetTestCaseName, Constants.RESULT, CurrentTestDataSetID, Constants.KEYWORD_SKIP); return; } else { for (int i = 0; i < ResultSet.size(); i++) { if (!ResultSet.get(i).equals(Constants.KEYWORD_PASS)) { CurrentTestSuiteXls.setCellData( CurrnetTestCaseName, Constants.RESULT, CurrentTestDataSetID, ResultSet.get(i)); return; } } } CurrentTestSuiteXls.setCellData( CurrnetTestCaseName, Constants.RESULT, CurrentTestDataSetID, Constants.KEYWORD_PASS); // if(!currentTestSuiteXLS.getCellData(currentTestCaseName, // "Runmode",currentTestDataSetID).equals("Y")){} }
public void start() throws ReflectiveOperationException, IllegalArgumentException, Exception { // Initilize app logs APP_LOGS = Logger.getLogger("devpinoyLogger"); APP_LOGS.debug("Hello"); APP_LOGS.debug("Config loaded, stating test"); // Check the RunMode of TestSuite // Check RunMode of TestCase in TestSuite // If Yes, Execute keywords of TestCase serially. // Iterate Keywords as many times as number of datasets (rows), which are set to yes. SuiteXLS = new Xls_Reader(System.getProperty("user.dir") + "//src/com//qtpselenium//xls//Suite.xlsx"); for (CurrentSuiteID = 2; CurrentSuiteID <= SuiteXLS.getRowCount(Constants.TEST_SUIT_SHEET); CurrentSuiteID++) { System.out.println( SuiteXLS.getCellData(Constants.TEST_SUIT_SHEET, Constants.TEST_SUIT_ID, CurrentSuiteID) + "------" + SuiteXLS.getCellData( Constants.TEST_SUIT_SHEET, Constants.TEST_SUIT_RUNMODE, CurrentSuiteID)); APP_LOGS.debug( SuiteXLS.getCellData(Constants.TEST_SUIT_SHEET, Constants.TEST_SUIT_ID, CurrentSuiteID) + "------" + SuiteXLS.getCellData( Constants.TEST_SUIT_SHEET, Constants.TEST_SUIT_RUNMODE, CurrentSuiteID)); // Test suite name == test suite xls file having test cases CurrentTestSuite = SuiteXLS.getCellData(Constants.TEST_SUIT_SHEET, Constants.TEST_SUIT_ID, CurrentSuiteID); if (SuiteXLS.getCellData( Constants.TEST_SUIT_SHEET, Constants.TEST_SUIT_RUNMODE, CurrentSuiteID) .equalsIgnoreCase("Y")) { // Execute the Test Case from suite APP_LOGS.debug( "*****Excuting Suite ***" + "-----------" + SuiteXLS.getCellData( Constants.TEST_SUIT_SHEET, Constants.TEST_SUIT_ID, CurrentSuiteID)); CurrentTestSuiteXls = new Xls_Reader( System.getProperty("user.dir") + "//src/com//qtpselenium//xls//" + CurrentTestSuite + ".xlsx"); //// Iterate through all the test cases in the sheet for (CurrentTestCaseID = 2; CurrentTestCaseID <= CurrentTestSuiteXls.getRowCount("Test Cases"); CurrentTestCaseID++) { APP_LOGS.debug( CurrentTestSuiteXls.getCellData( Constants.TEST_CASE_SHEET, Constants.TEST_CASE_ID, CurrentTestCaseID) + "--------" + CurrentTestSuiteXls.getCellData( Constants.TEST_CASE_SHEET, Constants.TEST_CASE_RUNMODE, CurrentTestCaseID)); CurrnetTestCaseName = CurrentTestSuiteXls.getCellData( Constants.TEST_CASE_SHEET, Constants.TEST_CASE_ID, CurrentTestCaseID); ResultSet = new ArrayList<String>(); // Check if Runmode for Test Case is Yes if (CurrentTestSuiteXls.getCellData( Constants.TEST_CASE_SHEET, Constants.TEST_CASE_RUNMODE, CurrentTestCaseID) .equalsIgnoreCase("Y")) { APP_LOGS.debug( "Excuting The Test Case " + CurrentTestSuiteXls.getCellData( Constants.TEST_CASE_SHEET, Constants.TEST_CASE_ID, CurrentTestCaseID)); // check if Test Case has any Test Data set if (CurrentTestSuiteXls.isSheetExist(CurrnetTestCaseName)) { // Run this as many times as number of test Datasets for (CurrentTestDataSetID = 2; CurrentTestDataSetID <= CurrentTestSuiteXls.getRowCount(CurrnetTestCaseName); CurrentTestDataSetID++) { APP_LOGS.debug("Iteration number" + "----" + (CurrentTestDataSetID - 1)); // Checking the Runmode for Current Data Set. if (CurrentTestSuiteXls.getCellData( CurrnetTestCaseName, Constants.TEST_CASE_RUNMODE, CurrentTestDataSetID) .equalsIgnoreCase("Y")) { // Iterating through all keywords (steps) ExecuteKeyWords(); createXLSReport(); } } } else { // simply run keywords for the test case with not data sets. ExecuteKeyWords(); createXLSReport(); } } } } } }
public void ExecuteKeyWords() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { for (CurrentTestStepID = 2; CurrentTestStepID <= CurrentTestSuiteXls.getRowCount(Constants.TEST_STEPS_SHEET); CurrentTestStepID++) { data = CurrentTestSuiteXls.getCellData( Constants.TEST_STEPS_SHEET, Constants.Data, CurrentTestStepID); String dataCol = CurrentTestSuiteXls.getCellData( Constants.TEST_STEPS_SHEET, Constants.Data, CurrentTestStepID); // config, OR, XLS /*object means the object on site on which we are going to perform the task or action. * This may be it is as link, a button, a input box, radio button, etc. * We need to get properties of that object and we save it to identify the object first * and then we can perform some actions on that object.we save properties of object in OR.properties. * We assing the key to the properties of object. * We use the key(object name)from OR.properties and specify that key in testcase xl sheet's 'object' col. * Object col values can only be read from OR.prop.*/ /*Data means, it can be retrive from either config, of xls sheet test col (in case of datasheet), * or OR.properties.so the idea is , data can be read from config, OR or xl sheet. *but object always comes from config.So, data is something we provide to the action for and object on the web page. *e.g.Data is used so that, we you can compare the values if you need to. *also it helps to keep values of constants. It is specified in XL sheet in 'Data' col. *we use the switch in the sheet to specify the source of data. *e.g col=Username, which mean take the key of data from Testcase XL sheet col named Username. *e.g.config=browserType, where browser type is key and its value is in config.properties. *if there is no switch, key value is in OR.properties.*/ // System.out.print(data + "before loop"); if (dataCol.startsWith(Constants.CONFIG)) { // data has to be read from config.prop String temp[] = dataCol.split(Constants.dataSeparator); String key = temp[1]; // System.out.print(key + "key is "); // data=CONFIG.getProperty(key); data = key; // System.out.print(data + "after loop"); } else if (dataCol.startsWith(Constants.COL)) { // data has to be read from data col in test sheet String temp[] = dataCol.split(Constants.dataSeparator); String colName = temp[1]; data = CurrentTestSuiteXls.getCellData(CurrnetTestCaseName, colName, CurrentTestDataSetID); // data = colName; } else { // data has to be read from OR.prop // data=OR.getProperty(dataCol); // System.out.print(data); String data_string = dataCol; data = data_string; /*System.out.print(data + " data after loop from OR prop \n"); System.out.print("----- Excuting keyword ----" + CurrentKeyword +"\n"); String Expected=DriverScript.OR.getProperty(data); System.out.print(Expected + " this is OR.getProperty(data) value \n"); */ } object = CurrentTestSuiteXls.getCellData( Constants.TEST_STEPS_SHEET, Constants.OBJECT, CurrentTestStepID); /*System.out.print("----- Excuting keyword ----" + CurrentKeyword +"\n"); System.out.print(object +"--- object after col loop from OR prop \n"); System.out.print(data +"--- data after col loop from OR prop \n");*/ // Checking TCID if it has Runmode "Yes"; if (CurrnetTestCaseName.equals( CurrentTestSuiteXls.getCellData( Constants.TEST_STEPS_SHEET, Constants.TEST_CASE_ID, CurrentTestStepID))) { CurrentKeyword = CurrentTestSuiteXls.getCellData( Constants.TEST_STEPS_SHEET, Constants.TEST_STEPS_KEYWORD, CurrentTestStepID); APP_LOGS.debug(CurrentKeyword + "----- Excuting keyword " + CurrentKeyword); // System.out.print(CurrentKeyword); // Code to Execute the KEyword steps // System.out.println(method); // Reflection API // object=CurrentTestSuiteXls.getCellData(CurrnetTestCaseName, Constants.OBJECT, // CurrentTestStepID); for (int i = 0; i < method.length; i++) { if (method[i].getName().equalsIgnoreCase(CurrentKeyword)) { // APP_LOGS.debug("Method is " + method[i]); APP_LOGS.debug("Current Keyword is " + CurrentKeyword); // OBJECT Keyword_Execution_Result = (String) method[i].invoke( Keywords, object, data); // pass on the object and data to all functions in Keywords.java APP_LOGS.debug(Keyword_Execution_Result); ResultSet.add(Keyword_Execution_Result); // report the result // capture screenshot capturescreenShot_method.invoke( Keywords, CurrentTestSuite + "_" + CurrnetTestCaseName + "_TS" + CurrentTestStepID + "_" + (CurrentTestDataSetID - 1), Keyword_Execution_Result); } } } } }