Вы находитесь на странице: 1из 5

package com.qtpselenium.test; import import import import import import java.io.FileInputStream; java.io.IOException; java.lang.reflect.InvocationTargetException; java.lang.reflect.Method; java.util.ArrayList; java.util.

Properties;

import org.apache.log4j.Logger; import com.qtpselenium.xls.read.Xls_Reader; public class DriverScript { public static Logger APP_LOGS; // called into Keywords class // global variables for Suite public Xls_Reader suiteXLS; public int currentSuiteID; public String currentTestSuite; // global variables for single suite having testcases public Xls_Reader currentTestSuiteXLS; public int currentTestCaseID; public String currentTestCaseName; public int currentTestStepID; public int currentDataSetID; public String currentKeyword; public public public public public public public Keywords Keywords; // Reference of the class Keywords Method method[]; String Keyword_Execution_Result; // Holds the result of each keyword. ArrayList<String> resultSet; // Holds the results of keywords set for one tc. String data; //holds the data value of current keyword executed. String object; //holds Object column of the test Steps xls String ColName;

//Properties files initialisation public static Properties CONFIG; public static Properties OR;

// Constructor to run keywords public DriverScript() { Keywords = new Keywords(); method = Keywords.getClass().getMethods(); // Returns the array of all the methods in this class

} public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException { // System.out.println("java.class.path="+System.getProperty("java.class.path")); //Initialise Property file -Config FileInputStream fs=new FileInputStream(System.getProperty("user.dir")+ "//src//com//qtpselenium//config//Config.properties"); CONFIG=new Properties(); CONFIG.load(fs);

//Initialise Property file -OR fs=new FileInputStream(System.getProperty("user.dir")+ "//src//com//qtpselenium//config//OR.properties"); OR=new Properties(); OR.load(fs);

//System.out.println(CONFIG.getProperty("TestSiteURL")); //System.out.println(OR.getProperty("test")); DriverScript test = new DriverScript(); test.start(); }

public void start() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Initialise the app logs APP_LOGS = Logger.getLogger("devpinoyLogger"); APP_LOGS.debug("Helloo Rajesh"); APP_LOGS.debug("Properties initialised and started testing..."); // Check the runmode of the test suite (suite.xlsx) // check the runmode of the test case in the suite (testsuite.xlsx) // Execute the keywords of the test case serially // Execute keywords as many times as number of data-sets which are set to "Yes. APP_LOGS.debug("Initialising Test suite"); suiteXLS = new Xls_Reader(System.getProperty("user.dir")+ "//src//com//qtpselenium//xls/Suite.xlsx");

for (currentSuiteID = 2; currentSuiteID <= suiteXLS.getRowCount(Constants.TEST_SUITE_SHEET); currentSuiteID++) {

APP_LOGS.debug(suiteXLS.getCellData(Constants.TEST_SUITE_SHEET,Constants.TEST_SUITE_ID, currentSuiteID) + "---" + suiteXLS.getCellData(Constants.TEST_SUITE_SHEET,Constants.RUNMODE, currentSuiteID));

// Test Suite Name = test suite xlsx file which is having testcases. currentTestSuite = suiteXLS.getCellData(Constants.TEST_SUITE_SHEET, Constants.TEST_SUITE_ID, currentSuiteID); if (suiteXLS.getCellData(Constants.TEST_SUITE_SHEET, Constants.RUNMODE, currentSuiteID).equals(Constants.RUNMODE_YES)) { // Execute the test cases in the suite. APP_LOGS.debug("*********Executing the test cases in the Current Suite*********"); currentTestSuiteXLS = new Xls_Reader(System.getProperty("user.dir")+ "//src//com//qtpselenium//xls/"+ currentTestSuite + ".xlsx");

// Iterate through all the testcases for (currentTestCaseID = 2; currentTestCaseID <= currentTestSuiteXLS.getRowCount(Constants.TEST_CASES_SHEET); currentTestCaseID++) { currentTestCaseName = currentTestSuiteXLS.getCellData(Constants.TEST_CASES_SHEET, Constants.TCID,currentTestCaseID);

resultSet = new ArrayList<String>(); // Initialize if (currentTestSuiteXLS.getCellData(Constants.TEST_CASES_SHEET, Constants.RUNMODE,currentTestCaseID).equals(Constants.RUNMODE_YES)) { // Execute the test case in the suite. APP_LOGS.debug("Executing Testcase" + "---->"+ currentTestCaseName); // Check if the test data sheet exists if (currentTestSuiteXLS.isSheetExist(currentTestCaseName)) { APP_LOGS.debug(currentTestCaseName+ "-->Test data sheet exists");

// Run all keywords as many times as number of test data sets for (currentDataSetID = 2; currentDataSetID <= currentTestSuiteXLS.getRowCount(currentTestCaseName); currentDataSetID++) { APP_LOGS.debug("Iteration" + "---->"+ currentDataSetID);

if (currentTestSuiteXLS.getCellData(currentTestCaseName, Constants.RUNMODE,currentDataSetID).equals(Constants.RUNMODE_YES)) {

APP_LOGS.debug(currentTestSuiteXLS.getCellData(currentTestCaseName,Constants.RUNMODE,cu rrentDataSetID)); // Iterate through all keywords executeKeywords(); // When Test data set is present createXLSReport(); } } }

// If Test data sheet doesn't exist. else {

APP_LOGS.debug(currentTestCaseName+ "-->Test data sheet does not exists"); executeKeywords(); // When Test data set NOT present createXLSReport();

} } } } } }

public void executeKeywords() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { //hold the data of keyword data = currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.DATA, currentTestStepID); data = currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.OBJECT, currentTestStepID); // Iterate through all keywords for (currentTestStepID = 2; currentTestStepID <= currentTestSuiteXLS.getRowCount(Constants.TEST_STEPS_SHEET); currentTestStepID++) {

// Checking the runmode for current data set. if (currentTestCaseName.equals(currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.TCID,currentTestStepID))) { currentKeyword = currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.KEYWORD,currentTestStepID); APP_LOGS.debug(currentKeyword); // Write code to execute the Keywords from "Keywords' class. for (int i = 0; i < method.length; i++) { if (method[i].getName().equals(currentKeyword)) { String Keyword_Execution_Result = (String) method[i].invoke(Keywords, object, data); //Return each keyword object and data APP_LOGS.debug(Keyword_Execution_Result); resultSet.add(Keyword_Execution_Result); // All the results will be added one by one.

// Report the result } } } } }

public void createXLSReport() { ColName=Constants.RESULT+(currentDataSetID-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(currentTestCaseName.equals(currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.TCID, 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(currentTestCaseName,Constants.RESULT, currentDataSetID, Constants.KEYWORD_SKIP); return; } else { for (int i = 0; i < resultSet.size(); i++) { if (!resultSet.get(i).equals(Constants.KEYWORD_PASS)) { currentTestSuiteXLS.setCellData(currentTestCaseName,Constants.RESULT, currentDataSetID,resultSet.get(i)); return; } } } currentTestSuiteXLS.setCellData(currentTestCaseName, Constants.RESULT,currentDataSetID, Constants.KEYWORD_PASS); } }

Вам также может понравиться