18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Problem with _get/_setGlobal and/or string comparison

halluecehnhalluecehn Members
edited November -1 in Sahi - Open Source
Hi,

I have some code like this:
_setGlobal("test_language", "de_DE");
var $language = _getGlobal("test_language");

if ($language == "de_DE") { ... } else {...}

and it executes the else case. Why? I would expect the string comparison to be true.

Best regards

Comments

  • PopeyePopeye Members
    Try

    _set($language, _getGlobal("test_language"));
    instead of
    var $language = _getGlobal("test_language");
  • narayannarayan Administrators
    halluecehn,

    Your code should have worked. We will verify it here.

    _setGlobal and _getGlobal are no longer required in most cases.

    Are you fetching the value "de_DE" from somewhere on the user interface?

    Regards,
    Narayan
  • halluecehnhalluecehn Members
    edited April 2010
    No, I intended to use it as a way to set the language of the user interface of our application that has to be tested. For example, buttons have different labels for differnt languages. So for every language I intend to define a .sah file with variables definitions -- same variable names, different values. Then for every language there is a suite with the same tests except for the first test file, that has only one line that sets the language via _setGlobal. Then in some .sah file that has to be included in every test _getGlobal is called and depending on the value of that global variable, the appropriate language dependant .sah file with variables definitions is included.

    so e.g testsuite_de.suite:
    de_DE_defs.sah / # meaningless start url
    test1.sah url1 
    test2.sah url2
    ...
    

    testsuite_en_us.suite:
    en_US_defs.sah /
    test1.sah url1
    test2.sah url2
    ...
    

    de_DE_defs.sah:
    var $var1 = "german button";
    var $var2 = "german label";
    ...
    

    en_US_defs.sah:
    var $var1 = "us button";
    var $var2 = "us label";
    ...
    

    include_for_all_tests.sah
    var $test_language = getGlobal("test_language");
    if ($test_language == "de_DE")  {
       _include("de_DE_defs.sah");
    else {
       _include("en_US"_defs.sah");
    }
    

    test1.sah
    _include("include_for_all_tests.sah");
    // do something with $var1 and $var2
    

    testsuite_de.sah
    setGlobal("test_language", "de_DE");
    

    testsuite_en_us.sah
    setGlobal("test_language", "en_US")'
    

    Is there another way to do this? Is it possible to give parameters to the test files in the suite file? Or to read some external variables, e.g. environment variables?

    Best regards,
  • narayannarayan Administrators
    Hi halluecehn,

    We will look at how to solve this problem better. Meanwhile use Popeye's suggestion to get global. It works.

    Regards,
    Narayan
  • Hi narayan,

    Thank you very much for the quick answer! I assume you meen using java.util.Properties as described in topic id 1225.

    However, this does not quite solve my problem, as I want to run the same suite in different languages without modifiyng any of the test scripts ever.

    But I've came to another solution, the first test is now instead of setting a global variable just copying the language dependant file to a default filename and the subsequential tests are only knowing about this default and including it.

    Best regards,
Sign In or Register to comment.