Forum Discussion

johnsski's avatar
johnsski
New Contributor
2 months ago
Solved

2 For loops to run through 2 arrays - how?!

Hi.

I'm trying to create a test that clicks on each tab (via an array of tab names) then runs a parameterised test using an array of tab mappings as below. It runs for the 1st tab then tries to run the parameterised test again, but it hasn't moved onto the next tab yet, so it fails.

Am I trying something impossible? 

Thanks.

function Verify_ContextMenuOptionsOnAllEyeLensSubtabsTEST()
{
  Log.AppendFolder("Verify the context menu options on all the Eye subtabs");
  
  //arrange
  let eyeTabs = ["Tear Film", "Cornea", "Nasolacrimal Duct", "Conjunctiva", "Aqueous Humor", "Retina", "Choroid", "Sclera", "Iris", "Vitreous Humor", "Lens"];
  let eyeTabMaps = [tearFilm, cornea, nasolacrimalDuct, conjunctiva, aqueousHumor, retina, choroid, sclera, iris, vitreousHumor, lens];
    
  for (let i = 0; i < eyeTabs.length; i++)
  {    
    for (let j = 0; j < eyeTabs[i].length; j++)
      {
        Verify_GenericEyeSubTabContextMenuOptions(eyeTabMaps[j]);        
      }
    Log.AppendFolder("Verify the context menu options on the :"  + eyeTabs[i] + " tab");       
    Actions.Select_TabByName(Aliases.simcyp.MainWindowInstance.RadTabControl, eyeTabs[i]);
    MenuToolBars.ClearAllSelections();
    Log.PopLogFolder();
  } 
  
  Log.PopLogFolder();
}

  • rraghvaniThanks for the clues(!) After some minutes I've done it!


    function Verify_ContextMenuOptionsOnAllEyeLensSubtabsTEST()
    {
      Log.AppendFolder("Verify the context menu options on all the Eye subtabs");
      
      //arrange
      let eyeTabs = [ ["Tear Film", tearFilm], ["Cornea", cornea], ["Nasolacrimal Duct", nasolacrimalDuct], ["Conjunctiva", conjunctiva], ["Aqueous Humor", aqueousHumor], ["Retina", retina], ["Choroid", choroid], ["Sclera", sclera], ["Iris", iris], ["Vitreous Humor", vitreousHumor], ["Lens", lens] ];  
          
      for (let i = 0; i < eyeTabs.length; i++)
      {    
        Log.AppendFolder("Verify the context menu options on the: "  + eyeTabs[i][0] + " tab");       
        Actions.Select_TabByName(Aliases.simcyp.MainWindowInstance.RadTabControl, eyeTabs[i][0]);
        MenuToolBars.ClearAllSelections();
        Verify_GenericEyeSubTabContextMenuOptions(eyeTabs[i][1]);        
        Log.PopLogFolder();
      } 
      
      Log.PopLogFolder();
    }

3 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Here's an example of using a two dimensional array,

    function test()
    {
        var items = [
            ["Tear Film", "tearFilm"],
            ["Cornea", "cornea"],
            ["Nasolacrimal Duct", "nasolacrimalDuct"]
        ]
    
        for (var i = 0; i < items.length; i++) {
            Log.Message("Tab '" + items[i][1] + "'");
        }
    }

     

  • johnsski's avatar
    johnsski
    New Contributor

    rraghvaniThanks for the clues(!) After some minutes I've done it!


    function Verify_ContextMenuOptionsOnAllEyeLensSubtabsTEST()
    {
      Log.AppendFolder("Verify the context menu options on all the Eye subtabs");
      
      //arrange
      let eyeTabs = [ ["Tear Film", tearFilm], ["Cornea", cornea], ["Nasolacrimal Duct", nasolacrimalDuct], ["Conjunctiva", conjunctiva], ["Aqueous Humor", aqueousHumor], ["Retina", retina], ["Choroid", choroid], ["Sclera", sclera], ["Iris", iris], ["Vitreous Humor", vitreousHumor], ["Lens", lens] ];  
          
      for (let i = 0; i < eyeTabs.length; i++)
      {    
        Log.AppendFolder("Verify the context menu options on the: "  + eyeTabs[i][0] + " tab");       
        Actions.Select_TabByName(Aliases.simcyp.MainWindowInstance.RadTabControl, eyeTabs[i][0]);
        MenuToolBars.ClearAllSelections();
        Verify_GenericEyeSubTabContextMenuOptions(eyeTabs[i][1]);        
        Log.PopLogFolder();
      } 
      
      Log.PopLogFolder();
    }