Forum Discussion

william_roe's avatar
william_roe
Super Contributor
11 years ago

Is there an IndexOf method in TestComplete 10.4?


The following code is 



function CheckEmployeeSiteAccess()


{


    //


    // Sets Whether Employee Should Have Site Access


    //


     


    // retrieves reference to browser


    var page = Sys.Browser().Page("*");


    


    if(Project.Variables.Employees.Value("SiteAccess") == null){return;}


    


    // retrieves value from 'SiteAccess' column in spreadsheet


    var SiteAccess  = Project.Variables.Employees.Value("SiteAccess").split(",");


    var AllSites = ['Site_2','Site_4','Site_6','Site_8','Site_10','Site_12','Site_14','Site_16','Site_18','Site_30'];


    


    // iterates through array of Site Access(s) and selects


    for (var i = 0; i < AllSites.length; i++) {


      //Delay(5000);


      //Sys.Refresh();


     


      //Log.Picture (obj.Picture(), "image");


      //ShowMessage(obj.FullName);


      


      // checks that site is not in list if user doesn't have access


      if(SiteAccess.indexOf(AllSites) == -1){


        aqObject.CheckProperty(Aliases.browser.CribMaster.headerPrimaryheader.sectionPrimaryinfo.section, "contentText", cmpNotContains, "tstsite_10", false);


      }


    }


}

3 Replies


  • Hi Colin,


     


    We have a corresponding suggestion in our DB - I've increased its rating. 


    Thanks.

  • Hi Keith,



    JScript arrays don't have the indexOf method, but you can use a function like this:



    ...

    if (indexOf(SiteAccess, AllSites) == -1)

    ...



    function indexOf(arr, item)

    {

      for (var i = 0; i < arr.length; i++)

      {

        if (arr === item) { return i; }

      }

      return -1;

    }

  • How about adding support for Python as a language?



    Then you get all the cool list/array comprehension that goes with it. Python is a very nice language for automated tests. It's very good with big lumps of data ....