Set TestSuiteProperty via Event
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Set TestSuiteProperty via Event
Hello Community,
We just have a simple question regarding the changing of TestSuite properties with an event. We want to Change the property before every Teststep automattically.
We tried the following lines:
testRunner.testCase.testSuite.setProperty("Time", "Test123");
AND we also tried
testRunner.testCase.testSuite["Time"].value = "Test123";
but none of them seem to work. We tried different events but we get no feedback. We do not know if our events even get executed, because we get no feedback. We also have no console to which we can make an output to, so we can see if our code gets executed. Could you please assisst?
Thank you in advance.
Daniel
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @derbestebaer,
If you are adding event at TestSuite Leve then write:
testRunner.testSuite.setPropertyValue("Time", "test")
Hope this will work for you.
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
Thanks and Regards,
Himanshu Tayal
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @HimanshuTayal
You said "If you are adding event at TestSuite Leve then write."
As far as I know the Events (menu at the upper right) are global and i can not specify, that i want to add an event for the TestSuite Level.
We tried to add your line there with different triggers, but nothing happens. So my question still remains, how to i set this Variable though the Events :
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@derbestebaer, I've been able to set a test suite property from the TestRunListener.beforeStep event handler. As a stand-alone example, I did the following:
1) Created a new test suite
2) Added a test suite custom property called "tsProp"
3) Added a TestRunListener.beforeStep event handler with the following script (lots of log statements to aid debugging):
def stepName = testStep.getName() log.info('TestRunListener.beforeStep: About to run test step ' + stepName) def existingValue = testStep.getTestCase().getTestSuite().getPropertyValue('tsProp') log.info('TestRunListener.beforeStep: Existing value of tsProp = ' + existingValue) // Set the test suite property testStep.getTestCase().getTestSuite().setPropertyValue('tsProp', stepName) log.info('TestRunListener.beforeStep: set tsProp = ' + stepName)
4) Added a new test case.
5) Added 5 Groovy Test Steps to the test case all with the identical script just to display the current value of the test suite property:
def tsProp = context.expand( '${#TestSuite#tsProp}' ) log.info('Groovy Script Test Step: tsProp = ' + tsProp)
On running the test case I got the following log output (the test suite property was blank when I ran the test case):
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: About to run test step Groovy Script 1
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: Existing value of tsProp =
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: set tsProp = Groovy Script 1
Wed Oct 31 17:14:46 GMT 2018:INFO:Groovy Script Test Step: tsProp = Groovy Script 1
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: About to run test step Groovy Script 2
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: Existing value of tsProp = Groovy Script 1
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: set tsProp = Groovy Script 2
Wed Oct 31 17:14:46 GMT 2018:INFO:Groovy Script Test Step: tsProp = Groovy Script 2
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: About to run test step Groovy Script 3
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: Existing value of tsProp = Groovy Script 2
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: set tsProp = Groovy Script 3
Wed Oct 31 17:14:46 GMT 2018:INFO:Groovy Script Test Step: tsProp = Groovy Script 3
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: About to run test step Groovy Script 4
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: Existing value of tsProp = Groovy Script 3
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: set tsProp = Groovy Script 4
Wed Oct 31 17:14:46 GMT 2018:INFO:Groovy Script Test Step: tsProp = Groovy Script 4
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: About to run test step Groovy Script 5
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: Existing value of tsProp = Groovy Script 4
Wed Oct 31 17:14:46 GMT 2018:INFO:TestRunListener.beforeStep: set tsProp = Groovy Script 5
Wed Oct 31 17:14:46 GMT 2018:INFO:Groovy Script Test Step: tsProp = Groovy Script 5
Compare my scripts to yours and see how you get on.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @Radford,
Thank you very much. That helped me a lot. I managed to set the Testsuit variable via an event Script.
Two points are still missing for me:
1. For our testing, we use soap ui in a way, in which we run every Teststep manually. Since you already used the event "TestRunListener.beforeStep " i expected that the event would also be triggered, if i run a teststep (SendSyncData) manually, but it seems, that the Testsuitvariable tsProp gets only written, when i run the whole Testsuite. I tried different events i.e. LoadTestRunListen.beforeTestStep but i dont get the event triggered by running the TestStep only.
2. Where can i find the outputconsole from ´your logfile bellow? If i add a groovy script i can see a console but this console is only for the current teststep. If i rightclick on the Testsuit and select "Groovy Console" i dont get any output there.
Thank you very much in advance.
Daniel
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mmmmmmh....
is there really no one who could help us?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1) I am not 100% sure of this but the way I understand it is, the "TestRunListener.beforeStep" event only triggers when you actually run a test case, like wise the "TestSuiteRunListener.beforeRun" only runs when you run a test suite. Thus it makes sense to me that they don't trigger when you run just a test step manually. Sorry if this does not really help, I've always written my tests so the "Test Case" is the independent unit I run, I've never created tests where I have to manually run test steps.
2) The log outputs I refered to are the main application logs, see the following documentaion link for full details:
https://support.smartbear.com/readyapi/docs/configure/logs.html
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
Great set of instructions, @Radford! And thank you for getting back to this topic!
@derbestebaer, if your question was answered, could you please click the Accept as Solution button below the reply that provides the solution? This will help other users find the answer faster in the future.
Thank you in advance!
Olga Terentieva
SmartBear Assistant Community Manager
