Forum Discussion

sshah1's avatar
9 years ago

Calling .cgi file from script and read dynamically generated values


I am doing desktop testing where I need to call .cgi script that will dynamically generate caserun IDS for testcases. I am able to call .cgi script as below.


var WScriptObj = Sys.OleObject("WScript.Shell");


for example:  path = "http://ip address/tr_new_run_testcomplete.cgi?&environment=Lab&cases=4,5,6,7"




CaseRun ID created as below.

{success: true, run_id: 35}
Test Case 25: CaseRun ID: 113

I need to get that value of CaseRunID. Need to figure out, 

1) How can I save that page?

2) Can I open it with notepad and read content as string.

After that I need to call other .cgi file to update status of each test case based on CaseRun ID.



  • OK so if you want to go with the "paste URL into browser" approach, you need to launch the browser and get the web page contents as follows.


    If you have the Web testing module:


    // Open the page in a browser (replace btIExplorer with your default browser)
    Browsers.Items(btIExplorer).Run(CreateCaseRunID_Path); var page = Sys.Browser().Page(CreateCaseRunID_Path);
    // Get the page's source code var str = page.contentDocument.documentElement.outerHTML; // TODO: extract values from str


    If you don't have the Web testing module, and assuming your default browser is IE:


    // Open the page in IE
    var ie = Sys.OleObject("InternetExplorer.Application");
    ie.Visible = true; ie.Navigate(CreateCaseRunID_Path); while (ie.ReadyState != 4) Delay(100);
    // Get the page's source code var str = ie.Document.documentElement.outerHTML; // TODO: extract values from str


    Let us know if this works for you.



    if I copy paste url string it loads the page fine without asking login info.


    It could be that you're already logged into this system in your browser - that's why it doesn't prompt for login. For example, you logged in a few weeks ago, or it uses your Windows account, or something like that. I initially suggested the approach with programmatic login so that the script is portable and doesn't depend on your current computer state (such as the browser you use). But of course you are free to use whatever method suits you best and works best for you. :)

9 Replies

  • HKosova's avatar
    SmartBear Alumni (Retired)

    I would suggest a different approach - access that URL via an HTTP request and read the response. Here's how you can do this:


    function Test()
      var strURL = "http://ip address/tr_new_run_testcomplete.cgi?&environment=Lab&cases=4,5,6,7";
      var oHTTP = Sys.OleObject("MSXML2.XMLHTTP");"GET", strURL, false);
      while((oHTTP.readyState != 4) && (oHTTP.readyState != "complete")) { 
      if (oHTTP.status == 200) {
        var str = oHTTP.responseText;
        // TODO: parse the str
        // ...
      } else {
        Log.Error("Could not access the URL. HTTP status " + oHTTP.status);

    How to parse the response depends on the response type. For example, if it's JSON like this

    {success: true, run_id: 35}

    you can use:

    // TC 11
    var obj = JSON.parse(oHTTP.responseText);
    // TC <= 10
    // var obj = eval("(" + oHTTP.responseText + ")");
    var run_id = obj.run_id;

    Hope this helps!

    • sshah1's avatar

      Thanks for your reply. I have further question:

      I am getting response from the ipaddress.index page and not from the page for which path is "CreateCaseRunID_Path" as below.


      CreateCaseRunID_Path = "http://ip addres/tr_new_run_testcomplete.cgi?run_summary=" + RunSummary + "&plan_id=" + PlanID + "&product_ver=" + ProdVer + "&build=" + Build + "&environment=" + Envn + "&cases=" + TestCaseNum;


      var oHTTP = Sys.OleObject("MSXML2.XMLHTTP");"GET", CreateCaseRunID_Path, false);


      how can I convert it to the text, so I can parse the string to obtain desired values.

      I am using TC11.

      Thanks for your time.

      • HKosova's avatar
        SmartBear Alumni (Retired)

        oHTTP.responseText will give you the response as text.