Luxoft / Twister

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

Missing PROPERTIES variable injection for Perl testcases #160

Closed mmajdoubi closed 9 years ago

mmajdoubi commented 9 years ago

The injection of PROPERTIES dictionary variable is missing in RunnerClasses.py for Perl scripts. See below for a snapshot of the code, only $EP $SUT $USER $SUITE_NAME $FILE_NAME variables are injected and are available for Perl. is there any other way how to make PROPERTIES dictionary available for Perl testcase?

client/executionprocess/RunnerClasses.py

Line 294

$STATUS_PASS = 0; $STATUS_FAIL = 3; $STATUS_SKIPPED = 4; $STATUS_ABORTED = 5; $STATUS_NOT_EXEC = 6; $STATUS_TIMEOUT = 7; $STATUS_INVALID = 8;

$EP = TWISTER_EP(); $SUT = TWISTER_SUT(); $USER = TWISTER_USER(); $SUITE_NAME = TWISTER_SUITE_NAME(); $FILE_NAME = TWISTER_FILE_NAME();

"""

Thanks in advance

croqaz commented 9 years ago

Hello, This will be fixed with the next batch of updates. Thank you.

mmajdoubi commented 9 years ago

is there any quick code-fix or workaround that I use in the mean time?

Thanks in advance

croqaz commented 9 years ago

Hello @mmajdoubi

Sure, add this is the code in RunnerClasses.py, in class TCRunPerl, in function _eval. Replace the definition of text_head variable with this:

        perl_config = '( ' + json.dumps(globs['CONFIG'])[1:-1] + ' )'
        perl_props = '( ' + json.dumps(globs['PROPERTIES'])[1:-1].replace('": ', '" => ') + ' )'

        text_head = r"""#!/usr/bin/perl

$STATUS_PASS     = 0;
$STATUS_FAIL     = 3;
$STATUS_SKIPPED  = 4;
$STATUS_ABORTED  = 5;
$STATUS_NOT_EXEC = 6;
$STATUS_TIMEOUT  = 7;
$STATUS_INVALID  = 8;

$EP  = TWISTER_EP();
$SUT = TWISTER_SUT();
$USER = TWISTER_USER();
$SUITE_NAME = TWISTER_SUITE_NAME();
$FILE_NAME  = TWISTER_FILE_NAME();
@CONFIG = %s;
%%PROPERTIES = %s;

""" % (perl_config, perl_props)

Don't forget to import json at the beggining of the file.

The CONFIG is an array and PROPERTIES is a hash, I think. I don't know Perl that much.

Use this in your perl test:

print "Config arr: @CONFIG \n";

@pkeys = keys %PROPERTIES;
@pvals = values %PROPERTIES;
print "Properties keys: @pkeys \n";
print "Properties vals: @pvals \n";