Question

I have one class, that creates excel sheet.For that I added poi-3.2.jar to classpath. I am working with Eclipse3.7.
I have generated testcases by recording workbench actions using with WindowTester Pro. I edited generated testcase and tried to create excel sheet within that, to write test result.

If I use same API from normal java program (within that plugin itself), it can able to create excel file without errors. But, when I try to create from testcase, I am getting the following error:

java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook

I have added required jar file into lib folder and added to build-path. Why its working from normal java program, but not working from WindowTester generated testcase.

Here is my code:

import com.windowtester.runtime.IUIContext;
import com.windowtester.runtime.swt.UITestCaseSWT;
import com.windowtester.runtime.swt.locator.eclipse.WorkbenchLocator;

public class Configuration extends UITestCaseSWT {

/*
 * @see junit.framework.TestCase#setUp()
 */
protected void setUp() throws Exception {
    super.setUp();
    IUIContext ui = getUI();
    try {
        CreateExcelFile file = new CreateExcelFile();
        file.CreateExcel();
    } catch (Throwable e) {
        System.out.println("***** Exception catched.. *****");
        // fail("Configuration failed");
        e.printStackTrace();
    }
    ui.ensureThat(new WorkbenchLocator().hasFocus());
}

/**
 * Main test method.
 */
public void testConfiguration() throws Exception {

    //Test code
    }

@Override
protected void tearDown() throws Exception {
    super.tearDown();
    // ....
}

}


public class CreateExcelFile {
HSSFRow row;
HSSFRichTextString string;

public void CreateExcel() {
    try {
        String filename = "E:/hello.xls";
        HSSFWorkbook hwb = new HSSFWorkbook();
        HSSFSheet sheet = hwb.createSheet("new sheet");

        HSSFRow rowhead = sheet.createRow((short) 0);
        string = new HSSFRichTextString("TC_Name");
        rowhead.createCell((int) 0).setCellValue(string);
        string = new HSSFRichTextString("Result");
        rowhead.createCell((int) 1).setCellValue(string);

        for (int i = 0; i <= 10; i++) {
            row = sheet.createRow((short) i);
            string = new HSSFRichTextString("TC_Name" + i);
            row.createCell((int) 0).setCellValue(string);
            if (i % 2 == 0) {
                row.createCell((int) 1).setCellValue(true);
            } else {
                row.createCell((int) 1).setCellValue(false);
            }
        }
        FileOutputStream fileOut = new FileOutputStream(filename);
        hwb.write(fileOut);

        fileOut.close();
        System.out.println("Your excel file has been generated!");
    } catch (Exception ex) {
        System.out.println(ex);
    }
}

}

Could anyone help me.

Was it helpful?

Solution

I got the problem cause. Its because of run-time classpath.The solution, I found is opened MANIFEST.MF in the manifest editor.Then at the Run-time tab, Classpath section, added required JAR.
Now its working without Error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top