Forum Discussion

Sheetal's avatar
Sheetal
Occasional Contributor
8 years ago

How to make generalized script for all web links

I have to test the Portal application for which I wrote the script as

var BrowserItems, i;
var url = "http://192.168.1.224/VPortal";
var form, form1;

BrowserItems = new Array(1);
BrowserItems[0] = Browsers.Item("iexplore");
// BrowserItems[0] = Browsers.Item("chrome");
// BrowserItems[2] = Browsers.Item("firefox");
for(i = 0; i < BrowserItems.length; i++)
{
BrowserItems[i].Run(url);
//Clicks at point (1270, 32) of the 'MSTaskListWClass' object.


// Browsers.Item(btChrome).Run(url);
page = Aliases.browser.page1921681224SsoLoginIvssoservi;
form = page.formLoginform;

 

But if the same application is installed on another machine based on that "IP" address of the URL will get changed say "192.168.1.239" and I try to simply change 224 to 239 in all links but it is not working.

I want the generic code so that I can run script for portal running on any machine

 

Help will be appreciated.

5 Replies

  • Updating the URL should work fine.

     

    If the IP is changing, it is the remote machine the site is installed to correct? As if it was the local machine, it would always be localhost/127.0.0.1?

     

    So a simple URL update to the new remote host should be fine.

     

    Which means there is something wrong with either your mappings or your code.

     

    I'm not a jScript guy. But your code looks odd to me ...

     

    1. Where is the end of your loop? I see a start (open) brace, but not and end (close) one?

    2. What is "form1"? You declare it outside the loop but it is never used in your code snippet?

    3. You have a comment about clicking something (using co-ordinates = BAD!) but no code to do it?

    4. Why are you assigning two variables ("page" - which is not declared - and "form") to the same constant values every time it loops? Assuming this code is within a loop. It's hard to say as you don't show your loop end.

    5. One of those variables is being assigned to the same page every time? If that is the problem then it's because you have the page mapped to a hard coded URL (containing the wrong IP address I'd guess).

     

    You need to sort some of the above points if you want a reliable answer? What you're trying to do (use a variable top level part of the URL) is common and simple. I do it all the time.

    • Sheetal's avatar
      Sheetal
      Occasional Contributor

      This was initial code which I shared here. It's long way to go.

       

      Yes, I was to access the remote machine URL. But as I have created script only for Local page access. I want to run number of portals installed on remote machine using the same script.

       

      I am new to TestComplete just a beginner 

      Actual code is

      //USEUNIT Login_form1
      //USEUNIT Management_Form

      function Login()
      {

      //Iterates through the specified browsers.
      var BrowserItems, i;
      var url = "http://192.168.1.224/VPortal";
      var form, form1;

      BrowserItems = new Array(1);
      BrowserItems[0] = Browsers.Item("iexplore");
      // BrowserItems[0] = Browsers.Item("chrome");
      // BrowserItems[2] = Browsers.Item("firefox");
      for(i = 0; i < BrowserItems.length; i++)
      {
      BrowserItems[i].Run(url);
      //Clicks at point (1270, 32) of the 'MSTaskListWClass' object.


      // Browsers.Item(btChrome).Run(url);
      page = Aliases.browser.page1921681224SsoLoginIvssoservi;
      form = page.formLoginform;

      LoginObject(form);
      //Check_Message = Aliases.browser.page1921681224SsoLoginIvssoservi.Table(2).Cell(0, 0).Table("errorBox").Cell(0, 1).TextNode("message").Name

      Log.Message("Logged in the Application successfully");

      form1 = Aliases.browser.page1921681224VportalMgtconsoleA.frameTopframe.link;
      //page.Wait();

      MgtTree(form1);
      form1.Click();
      }
      }

       

      Where I am calling number of functions. page is always reference to same URL IP as stored in script. How can I simplify the script so that I can access all URL IPs.

       

      • Colin_McCrae's avatar
        Colin_McCrae
        Community Hero

        You are taking actions on stored objects. (The Aliases you are assigning.)

         

        I suspect you Alias/Object mappings are your problem. What properties have you used to map them? If you used the URL (containing the IP) then that's likely your (initial) problem.

         

        If the URL (IP) is an identification property of your stored pages, then you need to use a wildcard (*) in place of the part of the IP that changes.

         

        You might also want to have a read on how to use Objects & Aliases a little better. An Alias should not simply be a copy of the object, complete with big horrible long name. Ideally you should rename them. (It will make your code a LOT more readable) and strip out the parts (containers & frames usually) that are not really all that meaningful in terms of addressing the object.

         

        The Alias should be a condensed, more readable, version of the full object reference.