Forum Discussion

AYedidya's avatar
AYedidya
New Contributor
11 years ago

[Res] Casting context.expand #result

I have script #1 (= MetaData) were I populate hash table with data and I would like to use this hash table in script #2 (= ResultData).

This hash table is the result of script #1 so I am using context.expand in script #2 (ResultData) as follows:
def metaDataHashtable = new Hashtable()
metaDataHashtable = context.expand('${MetaData#result}')

When I print the metaDataHashtable I get it correctly with all the data but I cannot access the values inside it as the context.expand returns it as a string and not as hashtable.

I also tried to pass the hashtable to a test case/project property but it also returns it as a string.
How can I pass parameters from one test step to another test step were the data type is different than String (i.e. integer, hashtable, etc.)?

4 Replies

  • AYedidya's avatar
    AYedidya
    New Contributor
    Hi,
    Using context.setProperty & context.getProperty , I am able to get the hashtable from script#1 and use it on script#2 but in order to do that, I have to run script #1 from script#2 and only then, I can access the hashtable.
    I do not want to run the entire script #1 from script#2 (script #1 already ran before I execute script#2 so it will run twice if I run It also from script#2)

    How can I only get the hashtable from script #1 and use it on script #2 without running script #1 from script #2?

    Script #1 – (MetaData):
    context.setProperty( "metadata", new MetaData( log, context, testRunner) )
    def metaDataHashtable = new Hashtable()
    metaDataHashtable.put("key_1","value_1")
    metaDataHashtable.put("key_2","value_2")
    metaDataHashtable.put ……………..
    context.setProperty("metaDataHashtable",metaDataHashtable )

    Script #2:
    module_1 = testSuite.testCases["TestCase_Name"].testSteps["MetaData"]
    module_1.run(testRunner,context) – this line runs script#1
    def metadata = context.metadata
    log.info metadata.context.getProperty("metaDataHashtable")

    Thank you!
  • AYedidya's avatar
    AYedidya
    New Contributor
    I found out I can directly share the context between teststeps .

    Script#1:
    context.setProperty("metaDataHashtable",metaDataHashtable )

    and then access it from scrip#2:
    def metaDataHashtable = context.getProperty("metaDataHashtable")

    All I had to do is run the entire testcase (first script#1 and then script#2)
    I didn't know it was so simple…
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    I'm glad it worked out. In the normal flow of running your TestCase, you will get the expected results.

    Regards,

    Giscard
    SmartBear Support