Luxoft / Twister

Twister Test Automation Framework
http://www.twistertesting.com/
Apache License 2.0
38 stars 21 forks source link

Workaround: PROPERTIES variable injection for TCL testcases #161

Closed mmajdoubi closed 9 years ago

mmajdoubi commented 9 years ago

I find a way how to make PROPERTIES dictionary accessible for TCL scripts, the PROTERTIES variable reference/injection is missing RunnerClasses.py for TCL scripts. Below you can find the change that I did perform to make it operational:

Client/executionprocess/RunnerClasses.py (add PROPERTIES reference)

Inject variables

    self.tcl.setvar('USER', globs['USER'])
    self.tcl.setvar('EP', globs['EP'])
    self.tcl.setvar('SUT', globs['SUT'])
    self.tcl.setvar('SUITE_ID', globs['SUITE_ID'])
    self.tcl.setvar('SUITE_NAME', globs['SUITE_NAME'])
    self.tcl.setvar('FILE_ID', globs['FILE_ID'])
    self.tcl.setvar('FILE_NAME', globs['FILE_NAME'])
    self.tcl.setvar('CONFIG', ';'.join(globs['CONFIG']))
    self.tcl.setvar('ITERATION', globs['ITERATION'])
    #Line 117: PROPERTIES dictionary added
    self.tcl.setvar('PROPERTIES', globs['PROPERTIES'])

How to make use of PROPERTIES dictionary in any TCL testcase

package require Tclx package require json #step1: Define PROPERTIES variable according to JSON format, replace single quotes with double ones set PROPERTIES_JSON [string map {\' \"} $PROPERTIES] #step2: Convert JSON to dictionary format set PROPERTIES_DICT [::json::json2dict $PROPERTIES_JSON] #step3: make use of all PROPERTIES by using dict get methode set MTU [dict get $PROPERTIES_DICT MTU]

Could you please review the change above, I classified it a workaround? I hope that you have another way how to make PROPERTIES accessible for TCL testcases/scripts

Thanks in advance

croqaz commented 9 years ago

Hello, you are right, the PROPERTIES variable is indeed not injected in TCL and PERL tests. I will find a method to fix it, your code seems a good place to start. Thank you !!

croqaz commented 9 years ago

Hello, This code should fix this quickly, in RunnerClasses.py, if you feel adventurous :) Put this instead of your code self.tcl.setvar('PROPERTIES', globs['PROPERTIES'])

# Set properties Associative Array
for k, v in globs['PROPERTIES'].iteritems():
    self.tcl.eval('set PROPERTIES({}) {}'.format(k, v))

Then, in the Tcl test, use like this:

puts "\nProperties::"
foreach i [array names PROPERTIES] {
    puts "PROPERTIES($i) = $PROPERTIES($i)"
}

I will submit this and it will be pushed on Github with the next batch of fixes. Thank you.

mmajdoubi commented 9 years ago

I changed RunnerClaases.py with the proposed TCL code change, it's working as expected. BTW The Perl Properties code change is also working, many thanks !