File Written twice on executing the Groovy Script
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2012
07:45 AM
02-28-2012
07:45 AM
File Written twice on executing the Groovy Script
Hi
I am trying to create a Script Assertion which writes into a file
On running the test suite the file is written more than once. I'm not sure why it does this .
here is my script assertion
The same script executed inside a groovy script is writing the file only once. What is the difference in how the script is executed when within a groovy script and within a script assertion.
Thanks and regards
Smitha
I am trying to create a Script Assertion which writes into a file
On running the test suite the file is written more than once. I'm not sure why it does this .
here is my script assertion
def startDate = new Date().format("yyyy_MM_dd_HHmmssSSS")
def filename = "C:/Users/smipan/Desktop/SoapUIPRO/LiveEvents/EventId_"+startDate+"_LiveFeeds.csv"
dataStore = new File( filename )
for (i in 1..8)
{
def current = "Test Line" + i
log.info current
dataStore.append( current)
}
The same script executed inside a groovy script is writing the file only once. What is the difference in how the script is executed when within a groovy script and within a script assertion.
Thanks and regards
Smitha
7 REPLIES 7
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2012
02:52 PM
02-28-2012
02:52 PM
Hi Smitha,
this is a known issue - ie that a script assertion is being executed twice in some situations - for now you will need to guard against this yourself, for example store a flag in the context or make sure that you only create the file if it hasn't already been created.
Sorry for the inconvenience,
regards!
/Ole
SmartBear Software
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
this is a known issue - ie that a script assertion is being executed twice in some situations - for now you will need to guard against this yourself, for example store a flag in the context or make sure that you only create the file if it hasn't already been created.
Sorry for the inconvenience,
regards!
/Ole
SmartBear Software
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2012
02:23 AM
02-29-2012
02:23 AM
Hi
How do I store a flag in the context ?
I append the filename with a time stamp and it is Looping through multiple times for different values meant to create unique files for diffferent values (it might not be unique and that's what i'm trying to identify that there is no duplicate content generated by my application) . Therefore its not easy to identify whether the script was executed as a part of the loop or is this just as a result of "multiple execution". Is there a fix planned for this problem in a future release ? Do you have an estimate if and when it will be fixed ?
As I see it , the best option i would have is to use a datastore to loop through and use a groovy script to store the files rather than just through a script assertion . Is there another easier alternative ?
thanks and Regards
Smitha
How do I store a flag in the context ?
I append the filename with a time stamp and it is Looping through multiple times for different values meant to create unique files for diffferent values (it might not be unique and that's what i'm trying to identify that there is no duplicate content generated by my application) . Therefore its not easy to identify whether the script was executed as a part of the loop or is this just as a result of "multiple execution". Is there a fix planned for this problem in a future release ? Do you have an estimate if and when it will be fixed ?
As I see it , the best option i would have is to use a datastore to loop through and use a groovy script to store the files rather than just through a script assertion . Is there another easier alternative ?
thanks and Regards
Smitha
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2012
08:54 AM
02-29-2012
08:54 AM
Does this help?
Change the assertion to this:
Now add a Groovy script step after the request that resets the flag.
This is to allow the request to write the files if it is re-executed due to looping.
Change the assertion to this:
if (context.alreadyWritten == null || !context.alreadyWritten) {
def startDate = new Date().format("yyyy_MM_dd_HHmmssSSS")
def filename = "C:/Users/smipan/Desktop/SoapUIPRO/LiveEvents/EventId_"+startDate+"_LiveFeeds.csv"
dataStore = new File( filename )
for (i in 1..8)
{
def current = "Test Line" + i
log.info current
dataStore.append( current)
}
context.setProperty('alreadyWritten', true)
} else {
log.info ('Already written!')
}
Now add a Groovy script step after the request that resets the flag.
context.setProperty('alreadyWritten', false)
This is to allow the request to write the files if it is re-executed due to looping.
"Ignorance more frequently begets confidence than does knowledge"
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2014
04:50 PM
09-17-2014
04:50 PM
Is this problem still a known bug in SoapUI Pro 5.1.1?
I encountered the same problem today, and want to make sure it's not caused by something else.
I encountered the same problem today, and want to make sure it's not caused by something else.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2014
02:31 PM
09-19-2014
02:31 PM
Hi RhettS,
I confirm this is still currently a bug in 5.1.2 (SOAP-2783).
You can take a look at M McDonald's workaround script using a flag to prevent multiple executions of the script.
Regards,
Giscard
SmartBear Support
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
I confirm this is still currently a bug in 5.1.2 (SOAP-2783).
You can take a look at M McDonald's workaround script using a flag to prevent multiple executions of the script.
Regards,
Giscard
SmartBear Support
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2017
06:19 AM
03-07-2017
06:19 AM
Hi.
Is this still issue still present in 5.3.0 ? I am encountering this issue when assertion script is ran and I am appending to file.
I have applied the workaround but it still prints twice.
Cheers
FC
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2017
12:10 PM
10-12-2017
12:10 PM
The workaround worked for me (non-Pro v 5.3.0), but holy cow, this is still a bug after five and a half years?! That is a very long time for such a bug to persist!
