在使用JXL编写excel时在第二次迭代中显示空指针异常?

在使用JXL编写excel时在第二次迭代中显示空指针异常?,excel,selenium,frameworks,jxl,Excel,Selenium,Frameworks,Jxl,我试图在键驱动框架中使用JXL设置或编写执行测试用例的结果。此外,我能够编写或设置结果,但只能在第一次迭代中进行。在第二次迭代时,它显示空指针异常。我试过了,但不明白到底是什么问题 主要方法: public class MainClass { private static final String BROWSER_PATH = "D:\\FF18\\firefox.exe"; private static final String TEST_SUITE_PATH = "D:\\c

我试图在键驱动框架中使用JXL设置或编写执行测试用例的结果。此外,我能够编写或设置结果,但只能在第一次迭代中进行。在第二次迭代时,它显示空指针异常。我试过了,但不明白到底是什么问题

主要方法:

public class MainClass {
    private static final String BROWSER_PATH = "D:\\FF18\\firefox.exe";
    private static final String TEST_SUITE_PATH = "D:\\configuration\\GmailTestSuite.xls";
    private static final String OBJECT_REPOSITORY_PATH = "D:\\configuration\\objectrepository.xls";
    private static final String ADDRESS_TO_TEST = "https://www.gmail.com";

    // other constants

    private WebDriver driver;
    private Properties properties;

    /* private WebElement we; */

    public MainClass() {
        File file = new File(BROWSER_PATH);
        FirefoxBinary fb = new FirefoxBinary(file);
        driver = new FirefoxDriver(fb, new FirefoxProfile());
        driver.get(ADDRESS_TO_TEST);
    }

    public static void main(String[] args) throws Exception {
        MainClass main = new MainClass();

        main.handleTestSuite();
    }

    private void handleTestSuite() throws Exception {
        ReadPropertyFile readConfigFile = new ReadPropertyFile();
        properties = readConfigFile.loadPropertiess();

        ExcelHandler testSuite = new ExcelHandler(TEST_SUITE_PATH, "Suite");
        testSuite.columnData();

        int rowCount = testSuite.rowCount();
        System.out.println("Total Rows=" + rowCount);

        for (int i = 1; i < rowCount; i++) {
            String executable = testSuite.readCell(
                    testSuite.getCell("Executable"), i);
            System.out.println("Executable=" + executable);

            if (executable.equalsIgnoreCase("y")) {
                // exe. the process
                String scenarioName = testSuite.readCell(
                        testSuite.getCell("TestScenario"), i);
                System.out.println("Scenario Name=" + scenarioName);
                handleScenario(scenarioName);
            }
        }
        WritableData writableData= new WritableData(TEST_SUITE_PATH,"Login");
        writableData.shSheet("Login", 5, 1, "Pass");
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        writableData.shSheet("Login", 5, 2, "Fail");
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        writableData.shSheet("Login", 5, 3, "N/A");
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    }

    private void handleScenario(String scenarioName) throws Exception {
        ExcelHandler testScenarios = new ExcelHandler(TEST_SUITE_PATH);
        testScenarios.setSheetName("Login");
        testScenarios.columnData();
        int rowWorkBook1 = testScenarios.rowCount();
        for (int j = 1; j < rowWorkBook1; j++) {
            String framWork = testScenarios.readCell(
                    testScenarios.getCell("FrameworkName"), j);
            String operation = testScenarios.readCell(
                    testScenarios.getCell("Operation"), j); // SendKey
            String value = testScenarios.readCell(
                    testScenarios.getCell("Value"), j);
            System.out.println("FRMNameKK=" + framWork + ",Operation="
                    + operation + ",Value=" + value);

            handleObjects(operation, value, framWork);
        }
    }

    private void handleObjects(String operation, String value, String framWork)
            throws Exception {
        System.out.println("HandleObject--> " + framWork);
        ExcelHandler objectRepository = new ExcelHandler(
                OBJECT_REPOSITORY_PATH, "OR");
        objectRepository.columnData();
        int rowCount = objectRepository.rowCount();
        System.out.println("Total Rows in hadleObject=" + rowCount);

        for (int k = 1; k < rowCount; k++) {
            String frameWorkName = objectRepository.readCell(
                    objectRepository.getCell("FrameworkName"), k);
            String ObjectName = objectRepository.readCell(
                    objectRepository.getCell("ObjectName"), k);
            String Locator = objectRepository.readCell(
                    objectRepository.getCell("Locator"), k); // SendKey

            System.out.println("FrameWorkNameV=" + frameWorkName
                    + ",ObjectName=" + ObjectName + ",Locator=" + Locator);

            if (framWork.equalsIgnoreCase(frameWorkName)) {
                operateWebDriver(operation, Locator, value, ObjectName);

            }
        }
    }

    private void operateWebDriver(String operation, String Locator,
            String value, String objectName) throws Exception {
        System.out.println("Operation execution in progress");
        WebElement temp = getElement(Locator, objectName);
        if (operation.equalsIgnoreCase("SendKey")) {
            temp.sendKeys(value);
        }

        Thread.sleep(1000);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        if (operation.equalsIgnoreCase("Click")) {
            temp.click();
        }

        if (operation.equalsIgnoreCase("Verify")) {
            System.out.println("Verify--->" +temp);
            temp.isDisplayed();

        }

    }

    public WebElement getElement(String locator, String objectName)
            throws Exception {
        WebElement temp = null;
        System.out.println("Locator-->" + locator);
        if (locator.equalsIgnoreCase("id")) {
            temp = driver.findElement(By.id(objectName));

        } else if (locator.equalsIgnoreCase("xpath")) {
            temp = driver.findElement(By.xpath(objectName));
            System.out.println("xpath temp ----->" + temp);
        } else if (locator.equalsIgnoreCase("name")) {
            temp = driver.findElement(By.name(objectName));
        }
        return temp;

    }
}
writable sheetC-->jxl.write.biff.WritableSheetImpl@ee1ede
strDataCC---->>Pass
strSheetName<<>><<>><<>>Login
writableSheet---->jxl.write.biff.WritableSheetImpl@ee1ede
strDataCC---->>Fail
strSheetName<<>><<>><<>>Login
writableSheet---->jxl.write.biff.WritableSheetImpl@ee1ede
Exception in thread "main" java.lang.NullPointerException
    at jxl.write.biff.File.write(File.java:149)
    at jxl.write.biff.WritableWorkbookImpl.write(WritableWorkbookImpl.java:706)
    at com.chayan.af.WritableData.shSheet(WritableData.java:86)
    at com.chayan.af.MainClass.handleTestSuite(MainClass.java:77)
    at com.chayan.af.MainClass.main(MainClass.java:48)
public类MainClass{
私有静态最终字符串浏览器\u PATH=“D:\\FF18\\firefox.exe”;
私有静态最终字符串测试\u套件\u PATH=“D:\\configuration\\GmailTestSuite.xls”;
私有静态最终字符串OBJECT\u REPOSITORY\u PATH=“D:\\configuration\\objectrepository.xls”;
私有静态最终字符串地址\u到\u测试=”https://www.gmail.com";
//其他常数
私有网络驱动程序;
私人物业;;
/*私人网站元素我们*/
公共类(){
文件=新文件(浏览器路径);
FirefoxBinary fb=新的FirefoxBinary(文件);
驱动程序=新的FirefoxDriver(fb,新的FirefoxProfile());
获取(地址到测试);
}
公共静态void main(字符串[]args)引发异常{
MainClass main=新的MainClass();
main.handleTestSuite();
}
私有void handleTestSuite()引发异常{
ReadPropertyFile readConfigFile=新的ReadPropertyFile();
properties=readConfigFile.LoadProperties();
ExcelHandler testSuite=新的ExcelHandler(测试套件路径,“套件”);
testSuite.columnData();
int rowCount=testSuite.rowCount();
System.out.println(“总行数=”+rowCount);
对于(int i=1;i”+框架);
ExcelHandler objectRepository=新的ExcelHandler(
对象存储库路径,“或”);
objectRepository.columnData();
int rowCount=objectRepository.rowCount();
System.out.println(“hadleObject中的总行数=“+rowCount”);
for(int k=1;k”+温度);
显示温度();
}
}
公共WebElement getElement(字符串定位器、字符串对象名)
抛出异常{
WebElement temp=null;
System.out.println(“定位器-->”+定位器);
if(定位器等信号情况(“id”)){
temp=driver.findElement(By.id(objectName));
}else if(locator.equalsIgnoreCase(“xpath”)){
temp=driver.findElement(By.xpath(objectName));
System.out.println(“xpath温度------->”+temp);
}else if(locator.equalsIgnoreCase(“名称”)){
temp=driver.findElement(By.name(objectName));
writable sheetC-->jxl.write.biff.WritableSheetImpl@ee1ede
strDataCC---->>Pass
strSheetName<<>><<>><<>>Login
writableSheet---->jxl.write.biff.WritableSheetImpl@ee1ede
strDataCC---->>Fail
strSheetName<<>><<>><<>>Login
writableSheet---->jxl.write.biff.WritableSheetImpl@ee1ede
Exception in thread "main" java.lang.NullPointerException
    at jxl.write.biff.File.write(File.java:149)
    at jxl.write.biff.WritableWorkbookImpl.write(WritableWorkbookImpl.java:706)
    at com.chayan.af.WritableData.shSheet(WritableData.java:86)
    at com.chayan.af.MainClass.handleTestSuite(MainClass.java:77)
    at com.chayan.af.MainClass.main(MainClass.java:48)