Forum Discussion

jsc's avatar
jsc
Regular Contributor
12 years ago

Assigning mapped objects to variables

Hi all,



I am generating a generic script and for better handling I want to assign the rather awkward namemappings to variables and work with them.

Unfortunately I failed completely and didn't find the proper site in http://support.smartbear.com/viewarticle/11508/.

So I got 2 questions on this.



My initial script is like this, I am using Jscript:



1)

function test()

{

  Aliases.Genesis.FContainerFormGenesis.TWCAxFrameSDK.ToolbarButtonNew.Click(52, 15, 0);

  Aliases.Genesis.FContainerFormGenesis.TWCAxFrameSDK.AdvDockPanelMain.ToolBarSpeedBar.PopupMenu.Click(5);

}





I tried to assign the mapped objects to variables and work with them, like:



2)

function test()

{

  var NewButton = Aliases.Genesis.FContainerFormGenesis.TWCAxFrameSDK.ToolbarButtonNew;

  var NewPopupMenu = Aliases.Genesis.FContainerFormGenesis.TWCAxFrameSDK.AdvDockPanelMain.ToolBarSpeedBar.PopupMenu;

  NewButton.Click(52, 15, 0);

  NewPopupMenu.Click(5);

}



My questions:



1. calling script 1) from keyword test is working. running this script directly from the scripts via "run current routine" doesn't work - why? (test finishes green without executing the actions (opening popup and clicking element 5).



2. calling script 2) from keyword tests makes testcomplete hang completely and has to be terminated via task manager. can't I assign the name mappings like this? How do I have to do it?



Thanks a lot in advance,



Joachim




5 Replies

  • jsc's avatar
    jsc
    Regular Contributor
    ok... the first question I can answer myself.

    There is no access to name mappings of the keyword tests, therefore the test cannot work.
  • jsc's avatar
    jsc
    Regular Contributor
    I also got the problem with the 2nd question:



    You can only assign name mapping objects to variables if the name mapping objects are visible on screen!

    So if I map the second object after I clicked on the first button, then it's no problem.



    Isn't there any way to map name mapping objects if they are not (yet) visible?



    Joachim
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Joachim,


    I'll start with your second question first :-), so --


    2)

    Look at your code snippet --


    var NewButton = Aliases.Genesis.FContainerFormGenesis.TWCAxFrameSDK.ToolbarButtonNew;

    var NewPopupMenu = Aliases.Genesis.FContainerFormGenesis.TWCAxFrameSDK.AdvDockPanelMain.ToolBarSpeedBar.PopupMenu;

    NewButton.Click(52, 15, 0);

    NewPopupMenu.Click(5);


    When you assign a name-mapping expression to a variable, you assign the object reference returned by this expression to the variable.

    The PopupMenu scripting objects are available only if the underlying menu is visible on the screen. When you assign a mapped pop-up menu to a variable, the menu does not exist, and you assign a reference to a non-existent object. This object does not have a Click method, so calling this method causes problems.


    However, the problem that I would expect to see is something like "Object Not Found", but you said that TestComplete hangs completely. Perhaps, TestComplete is waiting for the pop-up menu, and you have a long auto-wait timeout set in your project. Could you please check the Project Properties -> Playback -> "Auto-wait timeout" setting? Its default value is 10000 ms (10 seconds). If you have a larger value, this could make you think that TestComplete got hung...

    Also, please check the Playback -> "Stop on error" setting. If it is disabled, TestComplete does not stop the test when it fails to find the pop-up menu. It continues running further test commands, and, possibly, it waits for windows and controls needed by these commands, and this gives an impression that it hangs. Can you click the Stop button in the TestComplete indicator when TestComplete hangs? Can you click on menus and panels? If TestComplete does not hang, it should respond to your actions.


    1)

    As for your first code snippet, at the moment, it's difficult for me to say what goes wrong. The name mappings are shared throughout the project items, they are the same for keyword tests and scripts, there are no "keyword test name mappings" or "script name mappings". Perhaps, your keyword test performs some other actions before calling this script function, these actions are not performed when you call the function with the "Run Current Routine" command, and this causes problems. If I am wrong, I'd suggest that you send a test project demonstrating the problem and the project's logs to our Support Team:


    http://support.smartbear.com/message/?prod=TestComplete


    Please include the issue description and insert the link to this forum thread. Also, please specify the TestComplete version you are using.

  • jsc's avatar
    jsc
    Regular Contributor
    Hi Alex,



    thanks for your answer.



    1) as I now changed the order of assigning the objects, the problem no longer exists. But as far as I remember, TC completely hung.

    2) I called the routine when I opened the script-Extensions project in TestComplete and not the main project with the keyword tests.

    So in this project the namemapping of the keyword tests is not accessible.



    Kind regards,



    Joachim
  • jsc's avatar
    jsc
    Regular Contributor
    Hi Alex,



    thanks for your answer.



    1) as I now changed the order of assigning the objects, the problem no longer exists. But as far as I remember, TC completely hung.

    2) I called the routine when I opened the script-Extensions project in TestComplete and not the main project with the keyword tests.

    So in this project the namemapping of the keyword tests is not accessible.



    Kind regards,



    Joachim