Forum Discussion

AJ1000's avatar
AJ1000
Occasional Contributor
14 years ago

Setting variables in COM called from javascript not working

This following peice of javascript works with testcomeplete/testexecute:





var te = new ActiveXObject ("TestComplete.TestCompleteApplication.8");

var tei = te.Integration;

te.Manager.Runmode = 1;

tei.OpenProjectSuite("C:\\Tests\\AJProjectSuite\\AJProjectSuite.pjs");

tei.RunProjectTestItem ("AJ", "Tests_v_1_5");

while (tei.IsRunning())

{

 WScript.Sleep(100);

}

te.Quit();





However, when I try to add variables, it does not work -> I get an 'object required' error for line 5 (the documentation states the 'script should be running', but I am unsure what this means, as I want to alter the variables in the project suite before I run the tests which use the variables as part of the login process of my test web site):





var te = new ActiveXObject ("TestComplete.TestCompleteApplication.8");

var tei = te.Integration;

te.Manager.Runmode = 1;

var teproj = tei.GetObjectByName("Project");

var AJtst = teproj.Variables;

AJtst.VariableByName ("GlobalUserName") = "AjUser";

AJtst.VariableByName ("GlobalPassword") = "AjPassword";

tei.OpenProjectSuite("C:\\Tests\\AJProjectSuite\\AJProjectSuite.pjs");

tei.RunProjectTestItem ("AJ", "Tests_v_1_5");

while (tei.IsRunning())

{

 WScript.Sleep(100);

}

te.Quit();







How do I get this to work? Note: The javascript is being called from the following Bat file:





@echo off


echo calling js file


ajay.js


pause






How do I get variables to be altered before running the project test item? Please help.



Thanks.

4 Replies


  • Hi Ajay,





    Use the modified code:

    var te = new ActiveXObject ("TestComplete.TestCompleteApplication.8");

    var tei = te.Integration;

    te.Manager.Runmode = 1;

    tei.OpenProjectSuite("C:\\Tests\\AJProjectSuite\\AJProjectSuite.pjs");

    tei.RunProjectTestItem ("AJ", "Tests_v_1_5");

    var teproj = tei.GetObjectByName("Project");

    var AJtst = teproj.Variables;

    AJtst.VariableByName("GlobalUserName") = "AjUser";

    AJtst.VariableByName("GlobalPassword") = "AjPassword";

    while (tei.IsRunning())

    {

     WScript.Sleep(100);

    }

    te.Quit();







    The variables' values will be set before "Tests_v_1_5" is executed.
  • AJ1000's avatar
    AJ1000
    Occasional Contributor
    Thanks, it worked, even though it is not particularly intuitive.


  • AJ1000's avatar
    AJ1000
    Occasional Contributor
    I can confirm it works, but it does not produce an mht file, even though calling testexecute directly from the bat file does.



    Is there a COM setting that I have missed that generates the log file?



    Thanks.

  • Hi Ajay,





    This is due to specifics of using TE via COM, and there's no option that is responsible for this if running TE via COM. As for your question, there's no documented way to do this. We have an appropriate suggestion in our DB to implement such an ability, and your post has increased its rating. Thanks.





    You can find more information in the message sent to you via e-mail.