code written :
output: SKIP is not coming on the spreedsheet
Pass is not writen
Run mode yes for both Login test and checkitems
Can you tell me where is the error? I can't seem to find any error on the code and eclipse debugging not helping. Thank you
Hello Ashish Sir - could you please help me with this question? I'm stuck on this question for too long and I've reached out to your team but no one responded. Thank you
Hello Sir - can I get some help on this error? I'm unable to locate the issue in my code.
Instructor
Ashish Thakur Replied on 12/07/2022
You can debug this
Print the size of resultset and different variables.
Sorry for the late reply
No probelm sir. thank you for your response.
I've printed out the resultSet in two ways, please see the result. It's showing blank. Also, code is included below.
package com.qtpselenium.test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import com.qtpselenium.xls.read.Xls_Reader;
public class DriverScript {
public static Logger APP_LOGS;
// suite.xlsx
public Xls_Reader suiteXLS;
public int CurrentSuiteID;
public String currentTestSuite;
// current test suite
public Xls_Reader currentTestSuiteXLS;
public int currentTestCaseID;
public String currentTestCaseName;
public int currentTestStepID;// this will represent the test step sheet
public String currentKeyword;
public int currentTestDataSetID;
public Keywords keywords;
public Method method[] ;
public String keyword_execution_result;
public ArrayList<String> resultSet; // this array list will hold the result of executing one set of keywords for one particular test (pass/fail for each keyword)
public DriverScript() { //this CONSTRUCTOR is created with a variable keywords
keywords = new Keywords();
method = keywords.getClass().getMethods();
}
public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
DriverScript test = new DriverScript();
test.start();
}
public void start() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Initialize the application logs
APP_LOGS = Logger.getLogger("devpinoyLogger");
//APP_LOGS.debug("Hello");
// 1)check the RUNMODE of the test suite
// 2)check the RUNMODE of the test cases
// 3)execute the keywords of the test case serially
// 4)execute Keywords as many times as number of data tests which are set to
// YES(y)
//APP_LOGS.debug("Intialize Suite xls");
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++) {
// System.out.println(suiteXLS.getCellData(Constants.TEST_SUITE_SHEET,Constants.Test_Suite_ID,
// CurrentSuiteID)+"---" + suiteXLS.getCellData(Constants.TEST_SUITE_SHEET,
// "Runmode", 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 XLS FILE HAVING TEST CASES
// String runmode = suiteXLS.getCellData("Test Suite", "Runmode",
// CurrentSuiteID);
currentTestSuite = suiteXLS.getCellData(Constants.TEST_SUITE_SHEET, Constants.Test_Suite_ID,CurrentSuiteID);//this will give us the row number in TSID
System.out.println("***************************Current Test Suite :" + currentTestSuite);
if(suiteXLS.getCellData(Constants.TEST_SUITE_SHEET, Constants.RUNMODE, CurrentSuiteID).equals(Constants.RUNMODE_YES)) {
System.out.println("***************************Current Suite ID :" + CurrentSuiteID);
// execute the test cases in the suite
APP_LOGS.debug("Executing the suite****" + suiteXLS.getCellData(Constants.TEST_SUITE_SHEET, Constants.Test_Suite_ID, CurrentSuiteID));
currentTestSuiteXLS = new Xls_Reader(System.getProperty("user.dir") + "//src//com//qtpselenium//xls//" + currentTestSuite + ".xlsx");
System.out.println("***************************Current Test Suite XLS :" + currentTestSuiteXLS);
// iterate through all the test cases in the suite
for(currentTestCaseID =2; currentTestCaseID <= currentTestSuiteXLS.getRowCount("Test Cases"); currentTestCaseID++) {
APP_LOGS.debug(currentTestSuiteXLS.getCellData(Constants.TEST_CASES_SHEET, Constants.TCID,currentTestCaseID) + "--"+ currentTestSuiteXLS.getCellData(Constants.TEST_CASES_SHEET, Constants.RUNMODE,currentTestCaseID));
currentTestCaseName = currentTestSuiteXLS.getCellData(Constants.TEST_CASES_SHEET, Constants.TCID,currentTestCaseID);
resultSet = new ArrayList<String>();//each time new test case start, all the results are hold here until new test case start(all results for keywords in each test case)
System.out.println("here is the resultSet :" + resultSet);
String result ="";
for(String resSet:resultSet){
result+= resSet+",";
}
System.out.println("here is the resultSet : "+result);
if (currentTestSuiteXLS.getCellData(Constants.TEST_CASES_SHEET, Constants.RUNMODE, currentTestCaseID).equals(Constants.RUNMODE_YES)) {
APP_LOGS.debug("Executing the test case --->" + currentTestCaseName);
if (currentTestSuiteXLS.isSheetExist(currentTestCaseName)) {
// this for loop will help us RUN as many times as number of test data sets with
// Runmode yes"Y".
for (currentTestDataSetID = 2; currentTestDataSetID <= currentTestSuiteXLS.getRowCount(currentTestCaseName); currentTestDataSetID++)
{
APP_LOGS.debug("Iteration number ->" + (currentTestDataSetID - 1));
// this if statement is checking for the Runmode current data set to "Y", then
// it will execute the below statements
if (currentTestSuiteXLS.getCellData(currentTestCaseName, Constants.RUNMODE, currentTestDataSetID).equals(Constants.RUNMODE_YES)) {
// Executing the Keywords/this for loop iterating through all the KEYWOR
//executeKeywords(); // this is for multiple sets of data
createXLSReport();// this will be run after all the keywords for a particular test case has been implemented
}
}
} else { // if there is no sheet exist
// iterating through all keywords
//executeKeywords();// this is for no data in test, calling the function from below.
createXLSReport();
}
}
}
}
}
}
public void executeKeywords() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
for (currentTestStepID = 2; currentTestStepID <= currentTestSuiteXLS.getRowCount(Constants.TEST_STEPS_SHEET); currentTestStepID++) {
// checking TCID
if(currentTestCaseName.equals(currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.TCID, currentTestStepID))){// this line will compare and print only current Test keywords not every keywords
currentKeyword = currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.KEYWORD,currentTestStepID);
APP_LOGS.debug(currentKeyword);
//now here we write the code to execute the keywords as well
/* this will not work because we need to write too many if else statements to execute the keywords, so we have another workaround by creating a global constructor for driver script function
if(currentKeyword.equals("openBrowser")) {
//do something, this will not work because
}
*/
//we need to use reflection API to call the keywords
//Method method[] = keywords.getClass().getMethods(); // there is in build method in java call 'Method', which will allow us to access all the methods within this class to access their data
/*
for(int i=0; i<method.length; i++) {
System.out.println(method[i].getName());
//if we need call or print the specific methods we will do as below
if(method[i].getName().equals(currentKeyword)) {
//keyword_execution_result =(String) method[i].invoke(keywords);
APP_LOGS.debug(keyword_execution_result);
// resultSet.add(keyword_execution_result);//at the end, after all the keywords has have been executed for a particular test case, result will be added here
//NOW HOW DO WE REPORT THE RESULT WHICH IS COMING? WE NEED TO WRITE THIS TO OUR EXCEL FILE UNDER RESULT
}
}
*/
}
}
}
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(currentTestCaseName.equals(currentTestSuiteXLS.getCellData(Constants.TEST_STEPS_SHEET, Constants.RESULT, 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, Constants.KEYWORD_PASS);
index++;
}
}
if(resultSet.size()==0) { //if the result is zero, means no test case has been executed
//then we will mark it as skip on the excel spreadsheet under Result
currentTestSuiteXLS.setCellData(currentTestCaseName, Constants.RESULT, currentTestDataSetID, Constants.KEYWORD_SKIP);
System.out.println("It's skiping now test case because no keywords not found");
//return;
}else {
for(int i=0;i<resultSet.size();i++) {
if(!resultSet.get(i).equals(Constants.KEYWORD_PASS)) {//if any of the current result not equal pass, it will report as fail on the spreadsheet
currentTestSuiteXLS.setCellData(currentTestCaseName, Constants.RESULT, currentTestDataSetID, Constants.KEYWORD_FAIL);
return;
}
}
}
currentTestSuiteXLS.setCellData(currentTestCaseName, Constants.RESULT, currentTestDataSetID, Constants.KEYWORD_PASS);
//if(!currentTestSuiteXLS.getCellData(currentTestCaseName,"Runmode", currentTestDataSetID).equals("Y")){}
}
}
***********************************************************************************************************************************************
***************************Current Test Suite :Check Items
***************************Current Suite ID :2
***************************Current Test Suite XLS :com.qtpselenium.xls.read.Xls_Reader@3eb25e1a
here is the resultSet :[]
here is the resultSet :
here is the resultSet :[]
here is the resultSet :
LoginTest
TS01
Open browser
openBrowser
It's skiping now test case because no keywords not found
LoginTest
TS01
Open browser
openBrowser
It's skiping now test case because no keywords not found
here is the resultSet :[]
here is the resultSet :
***************************Current Test Suite :Search Suite
***************************Current Test Suite :C Suite