Forum Discussion

derbestebaer's avatar
derbestebaer
New Contributor
6 years ago

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

 

 

 

 

7 Replies

  • Hi derbestebaer,

     

    If you are adding event at TestSuite Leve then write:

     

    testRunner.testSuite.setPropertyValue("Time", "test")

    Hope this will work for you.

     

    • derbestebaer's avatar
      derbestebaer
      New Contributor

      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 :

       

       

       

       

       

      • Radford's avatar
        Radford
        Super Contributor

        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.