Question

im writing tests with selenium. i wrote a testrunner that write the results of the tests into a xlsx file. the problem is, that works only in eclipse! if i run 2 or more testclasses via 'gradle' only the first class executet the testprotocol correct that meens each class after the first one throws exception. the result is, that only the first test-class-results are written to the protocol.

de.h2o.testing.testprotocol.Screenshot STANDARD_ERROR
    Jan 14, 2014 9:49:21 AM de.h2o.testing.testprotocol.TestProtocol writeToFile
    Warnung: error occured while writing protocol file: org.apache.xmlbeans.impl.values.XmlValueDisconnectedException: null
org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
    at org.apache.xmlbeans.impl.values.XmlObjectBase.check_orphaned(XmlObjectBase.java:1247)
    at org.apache.xmlbeans.impl.values.XmlObjectBase.setterHelper(XmlObjectBase.java:1980)
    at org.apache.xmlbeans.impl.values.XmlObjectBase.set(XmlObjectBase.java:2062)
    at org.apache.poi.xssf.usermodel.XSSFRow.createCell(XSSFRow.java:170)
    at org.apache.poi.xssf.usermodel.XSSFRow.createCell(XSSFRow.java:147)
    at org.apache.poi.xssf.usermodel.XSSFRow.createCell(XSSFRow.java:39)
    at de.h2o.testing.testprotocol.TestProtocol.setCellValue(TestProtocol.java:376)
    at de.h2o.testing.testprotocol.TestProtocol.writeTableHead(TestProtocol.java:216)
    at de.h2o.testing.testprotocol.TestProtocol.writeToFile(TestProtocol.java:113)
    at de.h2o.testing.testprotocol.TestProtocol.afterClass(TestProtocol.java:102)
    at de.h2o.testing.testprotocol.H2oTestRunner$1.finishTestRun(H2oTestRunner.java:85)
    at de.h2o.testing.testprotocol.H2oTestRunner$1.countDownTestCounter(H2oTestRunner.java:119)
    at de.h2o.testing.testprotocol.H2oTestRunner$1.testIgnored(H2oTestRunner.java:113)
    at org.junit.runner.notification.RunNotifier$6.notifyListener(RunNotifier.java:175)
    at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:61)
    at org.junit.runner.notification.RunNotifier.fireTestIgnored(RunNotifier.java:172)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at de.h2o.testing.testBase.CompleteTestWatcher$1.evaluate(CompleteTestWatcher.java:16)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at de.h2o.testing.testprotocol.H2oTestRunner.run(H2oTestRunner.java:123)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

the problem is not in any testclass or in the testrunner or whatever, because everything works fine while using .csv files. now, after change to xlsx, i dosnt work with gradle.

hope someone could help...

here is the code. its called in every testclass. the writeHead, writeData -methods and so on are filling the sheet with data. the exception is thrown is the method: setCellValue.

private void writeTableHead(Sheet sheet) {

    setCellValue(7, 0, "*******************************");
    // print versionline

    setCellValue(8, 0, "Version");
    int cellCount = 4;
    for (TestRun runTriple : summary.getTestRuns()) {
        setCellValue(8, cellCount, runTriple.version);
        setStyle(8, cellCount, styles.get("borderThin"));
        sheet.setColumnWidth(cellCount, 2500);
        cellCount++;
    }
    setCellValue(9, 0, "Build");
    cellCount = 4;
    for (TestRun runTriple : summary.getTestRuns()) {
        setCellValue(9, cellCount, runTriple.build);
        setStyle(9, cellCount, styles.get("borderThin"));
        cellCount++;
    }
    setCellValue(10, 0, "Package");
    setCellValue(10, 1, "Class");
    setCellValue(10, 2, "Name");
    setCellValue(10, 3, "Type");
    cellCount = 4;
    for (TestRun runTriple : summary.getTestRuns()) {
        setCellValue(10, cellCount, new SimpleDateFormat("dd.MM.yyyy").format(runTriple.date));
        setStyle(10, cellCount, styles.get("date"));
        cellCount++;
    }

}

private void writeHead(Sheet sheet) {
    double totalFailed = summary.getNumberOfFailedTests();
    double totalSkipped = summary.getNumberOfSkippedTests();
    double totalSucceeded = summary.getNumberOfSucceededTests();
    double totalNumberOfTests = summary.getNumberOfTests();
    double succeededPercent = totalSucceeded / totalNumberOfTests;
    double failedPercent = totalFailed / totalNumberOfTests;
    double skippedPercent = totalSkipped / totalNumberOfTests;

    setCellValue(0, 0, "TESTPROTOKOL");

    setCellValue(1, 0, "Archiv");
    setCellValue(1, 1, "Git repository");

    setCellValue(2, 0, "Anzahl Tests");
    setCellValue(2, 1, totalNumberOfTests);

    setCellValue(3, 0, "Erfolgreiche Tests");
    setCellValue(3, 1, totalSucceeded);
    setCellValue(3, 2, succeededPercent);

    setCellValue(4, 0, "Fehlgeschlagene Tests");
    setCellValue(4, 1, totalFailed);
    setCellValue(4, 2, failedPercent);

    setCellValue(5, 0, "Geskippte Tests");
    setCellValue(5, 1, totalSkipped);
    setCellValue(5, 2, skippedPercent);

}

private void setCellValue(int row, int column, String value) {
    Row tmpRow;
    if (sheet.getRow(row) == null) {
        tmpRow = sheet.createRow(row);
    } else {
        tmpRow = sheet.getRow(row);
    }
    tmpRow.createCell(column).setCellValue(value);
}



private void writeToFile() {

    try {

        // Write protocolHEAD
        writeHead(sheet);

        // Write tableHEAD
        writeTableHead(sheet);

        // print data
        writeData(sheet);
        formatSheet(sheet);

        FileOutputStream stream = new FileOutputStream(file);
        wb.write(stream);
        stream.flush();
        stream.close();

        System.out.println("Protocol written to " + file.getAbsolutePath());
    } catch (Exception e) {
        log.warning("error occured while writing protocol file: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
        e.printStackTrace();
    }
}
Was it helpful?

Solution

The main problem was, that gradle tried to execute multiple tests in parallel. Because of that, the first test starts writing the file, so the other tests where blocked accessing the file. After running the tests sequentially, everything works fine

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