allure-framework / allure-js-commons

Deprecated, use https://github.com/allure-framework/allure-js instead
Other
27 stars 40 forks source link

Added extra validation to undefined type #25

Closed wallysson-hotmart closed 7 years ago

wallysson-hotmart commented 7 years ago

At some cases, while generating xml reports the allure common can't get correctly the value from start and stop. In that cases they pass values as empty string making allure report generation to fail causing errors like:

Exception in thread "main" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Long.parseLong(Long.java:601)
    at java.lang.Long.valueOf(Long.java:803)
    at com.sun.xml.internal.bind.DatatypeConverterImpl._parseLong(DatatypeConverterImpl.java:118)
    at ru.yandex.qatools.allure.model.TestCaseResult_JaxbXducedAccessor_stop.parse(TransducedAccessor_field_Long.java:50)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:195)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:559)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:538)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:153)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:380)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2787)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:118)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:243)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:221)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:276)
    at javax.xml.bind.JAXB.unmarshal(JAXB.java:242)
    at ru.yandex.qatools.allure.commons.AllureFileUtils.unmarshal(AllureFileUtils.java:59)
    at ru.yandex.qatools.allure.commons.AllureFileUtils.unmarshal(AllureFileUtils.java:50)
    at ru.yandex.qatools.allure.commons.AllureFileUtils.unmarshal(AllureFileUtils.java:40)
    at ru.yandex.qatools.allure.data.io.TestSuiteReader$TestSuiteResultIterator.next(TestSuiteReader.java:48)
    at ru.yandex.qatools.allure.data.io.TestSuiteReader$TestSuiteResultIterator.next(TestSuiteReader.java:1)
    at ru.yandex.qatools.allure.data.io.TestCaseReader$TestCaseResultIterator.nextSuite(TestCaseReader.java:46)
    at ru.yandex.qatools.allure.data.io.TestCaseReader$TestCaseResultIterator.hasNext(TestCaseReader.java:56)
    at ru.yandex.qatools.allure.data.AllureReportGenerator.generate(AllureReportGenerator.java:61)
    at ru.yandex.qatools.allure.data.AllureReportGenerator.generate(AllureReportGenerator.java:53)
    at ru.yandex.qatools.allure.AllureMain.main(AllureMain.java:48)
Command aborted due to exception {}.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
    at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:153)
    at ru.yandex.qatools.allure.command.ReportGenerate.runUnsafe(ReportGenerate.java:48)
    at ru.yandex.qatools.allure.command.AbstractCommand.run(AbstractCommand.java:52)
    at ru.yandex.qatools.allure.CommandLine.main(CommandLine.java:46)

To fix that, i've created some variables to handle data before it generates the actual XML data. Some issues already related to this at other projects:

https://github.com/webdriverio/webdriverio/issues/1432 https://github.com/webdriverio/wdio-allure-reporter/issues/26

I'm not shure if the beans folder it's the best place to fix the actual problem, but at some cases where the event it's waiting for an execution to be finishe like "waitForExist" from webdriver causes to pass undefined data while generating de XML.

just-boris commented 7 years ago

This fix was already proposed in #23, but it will not work.

I tried to explain this here in the comment that the whole integration Cucumber -> Webdriver.io -> Allure is broken. Webdriver.io tries to mitigate the differences between testing frameworks, such as Mocha, Jasmine, and Cucumber, and sometimes abstractions there are leaking, that causes problems.

This repo also contains some common layer between testing frameworks and Allure reporting core. But the thing is that this core is quite stable and successfully used by some other tools:

They all are working fine without fix like this one. I am not sure that your changes will not be breaking there. This is why I'd rather recommend focusing any possible efforts directly to Webdriver.io ecosystem. Check out https://github.com/webdriverio/wdio-cucumber-framework/pull/34 as another possible solution for your issue.

wallysson-hotmart commented 7 years ago

I'm agree with you that some projects that are actually working could not run properly due to changes, even few ones like this PR. In my case, some calls at .toXML was getting undefined values which was preventing Allure generate correctly. I will try to find a way into wdio-allure-reporter.

The best clue untill now to fix this is this issue you related: webdriverio/wdio-cucumber-framework#34

Actually im my project it's fixed as i'm forked the repo, i will continue using it with my fixes but i will try to find a way to fix it by the wdio-allure-reporter. Thanks by the way

just-boris commented 7 years ago

Hello!

Finally, there is a solution for that problem. I have merged https://github.com/allure-framework/allure-js-commons/pull/26 that handles stop times differently. Now empty strings are just do not appear in the resulting XML.

It will be working only with Allure v2 (in v1 you still will be seeing some error), that you can try as a beta now npm install allure-commandline@beta. As a beta version, it doesn't not ship Jenkins plugin yet, only CLI at this moment.