cancel
Showing results for 
Search instead for 
Did you mean: 

Error writing to a file using Groovy

SOLVED
Sperk
Occasional Contributor

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.

1 ACCEPTED SOLUTION

Accepted Solutions
msiadak
Community Hero

Re: Error writing to a file using Groovy

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"))



---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!

View solution in original post

1 REPLY 1
msiadak
Community Hero

Re: Error writing to a file using Groovy

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"))



---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors