Forum Discussion

royd's avatar
royd
Regular Contributor
9 years ago

Error trying to verify array value from another script unit [//USEUNIT] in current script unit.

I am using TestComplete v11,31,242 and Jscript. I have been using TC and Jscript about three months now. So my understanding is limited. I am creating modular script units for functions that are going to be called repeatedly. Currently scripting search (regression) for patient search (our product is EMR for Hospitals/Clinics).

 

To perform various searches based on patient name, source, account #, MRN, DOB, admission date, department, group etc. So I am collecting all the patient information by searching for the patient, selecting the patient and going to "View Detail Information". Collecting the above information and placing them in an array "pStat".

 

The array function unit is called from the "Search" script unit. Then proceeding to perform searches. Once the patient is found, some of the information collected earlier is used to verify accuracy (property checkpoint). At the checkpoint I am getting an error. If I copy/paste the entire array script into the search script, it runs without any error! Can not figure out how to fix this. Please help.

 

The "array" script:

function getPatientStat()
{

. . .

//select patient Aliases.browser.pifHome.aspnetForm.firstPatient.Click(); //view information Aliases.browser.swce.aspnetForm.menuViewInfo.Click(); //get patient info var pStat = []; var pStat = [Aliases.browser.swce.aspnetForm.panelPatientInfo.Name.contentText, Aliases.browser.swce.aspnetForm.panelPatientInfo.ptSource.contentText, Aliases.browser.swce.aspnetForm.panelPatientInfo.acNum.contentText, Aliases.browser.swce.aspnetForm.panelPatientInfo.MRN.contentText, Aliases.browser.swce.aspnetForm.panelPatientInfo.DOB.contentText, Aliases.browser.swce.aspnetForm.panelPatientInfo.aDate.contentText, Aliases.browser.swce.aspnetForm.panelPatientInfo.Dept.contentText, Aliases.browser.swce.aspnetForm.panelPatientInfo.Group.contentText];

 

The script collecting all the intended information. But failing in property checkpoint in "search" Unit. 

 

 

 

 Property checkpoint:

//USEUNIT Patient_Info

//gather patient info
Patient_Info.getPatientStat();


//select patient Aliases.browser.pifHome.aspnetForm.firstPatient.Click(); //view information Aliases.browser.swce.aspnetForm.menuViewInfo.Click(); //check MRN
aqObject.CheckProperty(Aliases.browser.swce.aspnetForm.panelPatientInfo.MRN, "contentText", cmpEqual, pStat[3]);

 

 

If the array function is included in search script, it runs with no problem.

 

 

 

Thanks in advance!

 

Dave

 

 

 

  • you have declared var pStat [] globally (out side function)  which is OK

    but you are again declaring var pStat [] inside function so the program got confused...

     

    inside of function you do not need Var keyword 

    just do like 

    pStat = 
        [Aliases.browser.swce.aspnetForm.panelPatientInfo.Name.contentText, 
        Aliases.browser.swce.aspnetForm.panelPatientInfo.ptSource.contentText, 
        Aliases.browser.swce.aspnetForm.panelPatientInfo.acNum.contentText,  
        Aliases.browser.swce.aspnetForm.panelPatientInfo.MRN.contentText,
        Aliases.browser.swce.aspnetForm.panelPatientInfo.DOB.contentText,  
        Aliases.browser.swce.aspnetForm.panelPatientInfo.aDate.contentText,  
        Aliases.browser.swce.aspnetForm.panelPatientInfo.Dept.contentText,  
        Aliases.browser.swce.aspnetForm.panelPatientInfo.Group.contentText];  

    or better

    pStat[0] = Aliases.browser.....Name.contentText
    pStat[1] =Aliases....pt.Source.contentText
    
    
    

    pl type full-name instead of dots above

     

    Also a good place to grasp programming concepts is http://www.w3schools.com remember this is not jScrip TC have but most concepts are similer

  • NisHera's avatar
    NisHera
    Valued Contributor

     

    By any chance did you defined "pStat" in side of a function?

    do you get "pStat"in autocomplete (ctrl+space)

     

    what is if you just log the value like

    Log.Message(pStat[3]);  

    ......... Just before check point.

    • royd's avatar
      royd
      Regular Contributor

      Hi 

       

      Yes, pStat is inside of a function. It has been delared, if you look at the first block of code, it goes like (within function) -

       

      function getPatientStat()
      {

      . . .

      var pStat = []; var pStat = [Aliases.browser.swce.aspnetForm.panelPatientInfo.Name.contentText, . . .

      Autocomplete works only when the "array" is inside of the main unit. Once removed, it does not!

       

      Log.Message(pStat[3]); 

      Therefore, does not work when the "array" is missing from the main unit. This tells me that it is loosing track of array values one the"array" unit is completed and returns to main unit!

       

      Any thoughts?

       

      There has to be a way to retain the array values, so I can continue with the rest of the test.

       

       

       

      Dave

       

      • NisHera's avatar
        NisHera
        Valued Contributor

        If you declare an array or variable inside a function, it is not available outside of the function. Unless it's a return parameter of the function.

        Previously I was assuming your array was globally declared.

         

        Or am I totally misunderstood your question?