Forum Discussion

Sperk's avatar
Sperk
Occasional Contributor
7 years ago
Solved

Error writing to a file using Groovy

I'm trying to write Json assert results to an external file, I can create and write to the file, however when I try to append values to the file it throws an error.

 

In this code block when it just contain the log.info stmt it executes ok. If I add the append line if fails

 

resultsFile = testRunner.testCase.getPropertyValue("externalResultsFile")

testRunner.testCase.testSteps.each{ name,props ->
    if(props.metaClass.respondsTo(props, "getAssertionList")){
        // get assertionList
        props.getAssertionList().each{
          log.info "$it.label - $it.status"
          resultsFile.append("$it.label - $it.status")
        }
    }
}

The error returned by the debug button is:

groovy.lang.MissingMethodException: No signature of method: java.lang.String.append() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [Match content of [ProductFamily] - VALID] Possible solutions: expand(), expand(int), find(), any(), grep(), any(groovy.lang.Closure) error at line: 23

Any help would be welcome, I've googled here and Stackoverflow but no joy.

 

Mark Smith.

  • The first thing I see is that you appear to be getting a file name stored as a property, but you aren't treating it as a file.

     

    Try this line below? If that doesn't help I can try to dig in more later.

     

    resultsFile = new File (testRunner.testCase.getPropertyValue("externalResultsFile"))

1 Reply

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    The first thing I see is that you appear to be getting a file name stored as a property, but you aren't treating it as a file.

     

    Try this line below? If that doesn't help I can try to dig in more later.

     

    resultsFile = new File (testRunner.testCase.getPropertyValue("externalResultsFile"))