Forum Discussion

royd's avatar
royd
Regular Contributor
8 years ago
Solved

Need help with creating script extension.

Note: unfortunately this board does not allow to credit more than one person for the solution. I would like to recognize both Robert and Shankar for finding the solution for me. Kudos to you both, I really appreciate it.

 

I have attached the script file and the description.XML for reference. I’m trying to create an extension for all menu items across the application.  After changing the .zip extension .tcx I have placed the extension in C:\Program Files (x86)\SmartBear\TestComplete 12\Bin\Extensions\ScriptExtensions. Launched TestComplete, under File menu>Install Script Extension, made sure that SWCE Menu has the check mark.

 

When I try to call one of those menu items with following code, I get an error “object doesn’t support this property are method”.

 

menuSWCE.Menu.menuGroups();

While typing ‘menuSWCE’ and ‘Menu’, autocomplete pops up but not for ‘menuGroups’.

I’ve been through all the documentation, but I’m sure I’m missing something.  I’m making some silly mistake that I cannot figure out. I would really appreciate any help.

Thanks.

 

Dave

 

P.S.: I will be in meetings good portion of the day. Replying to my problem might be delayed, thanks for understanding.

  • Your regular expression in the above example is different from your regular expression in your original code.  Please make sure that Navigation.js is using the same regular expression that works in your normal project.

24 Replies

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Aliases, NameMapping, and Sys objects are supported in Script Extensions so FindChild, being a method off one of those objects, is supported.

       

       

      What I'm thinking is the problem is that you are using native TestComplete methods and objects within those intial variable declarations.  At those points, the script extension engine is not utilizing TestComplete but initializing the variables within the native JScript environment.  Sys.Browser, etc., are not recognized there.  I've run into various problems with this myself.

       

      Another problem is that you added the "NameSpace" to your runtime object.  That means the object is referenced as 

       

       

      Navigation.Menu.menuGroups()

       

       

      I'm not entirely sure why your call worked as it did with autocomplete with that NameSpace in place.

       

      You need to wrap your intialization in some other functions to be able to allow the testcomplete engines to initialize.

       

       

       

       

      var page;
      var mainMenu;
      
      function getpage() {
          page = Sys.Browser("iexplore").Page("https://*.imedconsent.com/*");
          return page; 
      }
      
      function getmainMenu() {
          mainMenu = getpage().FindChild("idStr", "regexp: (mainMenuInner)|(navMenuInner)", 10);
          return mainMenu;     
      }
      
      function swceProcPatient(){
          let menuProcPatient = getmainMenu().FindChild("contentText", "Process Patients", 20);
          menuProcPatient.Click();
        }
      
      
      function swceReports(){
        let menuReoports = getmainMenu().FindChild("contentText", "Reports", 20);
        menuReoports.Click();
        }
      
      
      function swceGroups(){
        let menuGroups = getmainMenu().FindChild("contentText", "Groups", 20);
        menuGroups.Click();
        }
      
      
      function fodSelectPatients(){
          let menuSelectPatients = getmainMenu().FindChild("contentText", "Select Patients", 20);
          menuSelectPatients.Click();
        }
      
      
      function swceHome(){
          let menuHome = getmainMenu().FindChild("contentText", "Home", 20);
          menuHome.Click();
        }
      
        
      
      function swceLogOut(){
          let menuLogout = getmainMenu().FindChild("contentText", "Logout", 5);
          menuLogout.Click();
        }
        

       

       

      • royd's avatar
        royd
        Regular Contributor

        Hi Robert

         

        Thanks for your help. I will try tonight and get back to you.

         

        Dave

  • royd's avatar
    royd
    Regular Contributor

    Hi Robert!

     

    I see that you are sitting in the background and enjoying the whole exchange! :) You know I am a rookie, this I guess part of growing pain! I am glad you are having fun watching this!! :D