Kishore Jagadeesan
Kishore Jagadeesan

Reputation: 23

Testng to print result pass/ fail

Here, I am trying to print the results of testcases... But whatever I do the test reult prints only as 16... I want it to print as success or pass/ fail It would be a great help if you could post a example.

public class EdiitAttendancePunchesByDepartment {

    public EdiitAttendancePunchesByDepartment() {
    }

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @BeforeMethod
    public void setUp() {
    }

    @AfterMethod
    public void tearDown() {
    }
    Boolean t = true;

    @Test(priority = 0,dataProvider = "globalcfg")
    public void global(String propid, String propvalue) throws IOException {
        ConfigurationBean cfgbean = new ConfigurationBean();

        for (ConfigurationModel cc : cfgbean.getConfigurationList()) {
            if (cc.getPropertyId().equals(propid)) {
                cc.setPropertyId(propid);
                cc.setPropertyValue(propvalue);
                System.out.println("Propid : " + cc.getPropertyId() + " value : " + cc.getPropertyValue());
            }
        }

        File output = new File("D:/data/kishore/Edit_punches_output.xls");
        FileWriter writes = new FileWriter(output.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(writes);
        bw.write("EmpID-Date-Punch_Times-PayDay-Total_IN_Hours-OT-TEST_ID-Leave_Type");
        bw.close();

        cfgbean.setCreateButtonFlag(Boolean.FALSE);
        cfgbean.setUpdateButtonFlag(Boolean.TRUE);
        cfgbean.updateConfiguration();
        cfgbean.retrieveConfiguration();
        for (ConfigurationModel cc : cfgbean.getConfigurationList()) {
            if (cc.getPropertyId().equals(propid)) {
                System.out.println("Propid Out Put : " + cc.getPropertyId() + " value Out Put: " + cc.getPropertyValue());
            }
        }
        System.out.println("Global Config running>>>>>>>>>>>>>>>");
         boolean tr=Reporter.getCurrentTestResult().isSuccess();
         System.out.println("Check<><><><><><><><><><><><><><><><><><><><>"+tr);
         if(tr==true){
             System.out.println("Result /////////////////////////////////////"+tr);
         }
        System.out.println("Test result>>>>>>>>>>>>>> "+Reporter.getCurrentTestResult().getStatus());
    }

    @Test(priority = 1,dataProvider = "viewpunches")
    public void testviewpunches(String cmpcode, String orgcode, String Empid, String Empname, String deptname, Integer compgrpid,
            String date, String Time1, String Time2, String type, String typeid) {

        EditEmpTimeSheetBean bean = new EditEmpTimeSheetBean();
        bean.setCmpCode(cmpcode);
        bean.setOrgCode(orgcode);
        try {
            SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
            SimpleDateFormat format1 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            Date date1 = format.parse(date);
            Date time1 = format1.parse(Time1);
            Date time3 = format1.parse(Time2);
            SimpleDateFormat op = new SimpleDateFormat("dd/MM/yyyy");

            bean.setTimeSheetDate(date1);
            bean.setEmpCompGroupId(compgrpid);
            bean.setDepartmentName(deptname);

            bean.setEmployeeCode(Empid);
            bean.setEmployeeName(Empname);
            bean.setDialogFlag(Boolean.TRUE);
            bean.viewTimeSheetDetailByDepartment();

            EmployeeDTO dto = new EmployeeDTO();
            EmployeeService service = new EmployeeServiceImpl();
            dto = service.retrieveEmployee(bean.getCmpCode(), bean.getOrgCode(), bean.getEmployeeCode());
            if (dto == null) {
                File output = new File("D:/data/kishore/Edit_punches_output.xls");
                FileWriter write_new = new FileWriter(output, true);
                BufferedWriter bw_new = new BufferedWriter(write_new);
                bw_new.write("\n" + bean.getEmployeeCode() + "- NO record found - - - - -" + typeid);
                bw_new.close();
                System.out.println("Invalid Employee Code");
            } else {
                System.out.println("Valid code");
            }


            for (EmpWorkLogModel cc : bean.getEmpWorkLogArray()) {
                if (cc.getEmployeeCode().equals(Empid)) {
                    cc.onChange();
                    List<LogTimeModel> kl = new ArrayList<LogTimeModel>();
                    LogTimeModel m = new LogTimeModel();
                    LogTimeModel mn = new LogTimeModel();

                    m.setPunchTimes(time1);
                    if (type.equalsIgnoreCase("insert")) {
                        m.setOpFlag(Constant.OP_FLAG_INSERT);
                    }
                    if (type.equalsIgnoreCase("update")) {
                        m.setOpFlag(Constant.OP_FLAG_UPDATE);
                    }
                    if (type.equalsIgnoreCase("delete")) {
                        m.setOpFlag(Constant.OP_FLAG_DELETE);
                    }
                    mn.setPunchTimes(time3);
                    if (type.equalsIgnoreCase("insert")) {
                        mn.setOpFlag(Constant.OP_FLAG_INSERT);
                    }
                    if (type.equalsIgnoreCase("update")) {
                        mn.setOpFlag(Constant.OP_FLAG_UPDATE);
                    }
                    if (type.equalsIgnoreCase("delete")) {
                        mn.setOpFlag(Constant.OP_FLAG_DELETE);
                    }
                    if (type.equalsIgnoreCase("CHANGE")) {
                    }
                    kl.add(m);
                    kl.add(mn);
                    cc.setPunchList(kl);
                    System.out.println("punch time>>>>>>>>>>>>>>>>>XXXXXXXXX>>>>>>>>>>>>XXXXXXXXXX   " + mn.getPunchTimes() + "       " + cc.getPunchTime() + "   " + cc.getFromDate());

                    System.out.println("Emp ID : " + cc.getEmployeeCode() + " \nPunch time : " + cc.getPunchTimes() + " \nPay Day : " + cc.getPayDay() + " \nIN hours: " + cc.getWorkedTime());

                } else {

                    System.out.println("\n\nNo Records found for : " + cc.getEmployeeCode());
                }
            }System.out.println("Test result>>>>>>>>>>>>>> "+Reporter.getCurrentTestResult().getStatus());
            bean.updateLogTime();
            testview(bean.getEmployeeCode(), bean.getEmployeeName(), bean.getShiftId(), date, typeid);



        } catch (Exception e) {
            System.out.println(" Error :" + e);
            e.printStackTrace();
        }

    }

This is the output i receive

sessionFactory1 org.hibernate.internal.SessionFactoryImpl@196a6ac sessionFactory1 SessionStatistics[entity count=0collection count=0] Propid : com.rgs.payroll.enableDynamicWeekOff value : N Propid Out Put : com.rgs.payroll.enableDynamicWeekOff value Out Put: N Global Config running> Check<><><><><><><><><><>false Test result>>>>>>>>>>>>>> 16

Upvotes: 1

Views: 633

Answers (2)

noor
noor

Reputation: 3004

Remove pass fail decision making code from ur test case and use the below code:

@AfterMethod
public void tearDown(ITestResult result) {

   if (result.getStatus() == ITestResult.FAILURE) {
   System.out.println(result.getMethod().getMethodName()+ " is failed");
   //do something here.
   }        
}

Upvotes: 1

juherr
juherr

Reputation: 5740

16 means "STARTED".

It's the only value you can expect into the test itself. TestNG will only determine the value after the end of the method.

You can try to print the result from the @AfterMethod method.

Upvotes: 0

Related Questions