Error trying to verify array value from another script unit [//USEUNIT] in current script unit.
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
Checkpoints
-
IE
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi NisHera. Thanks for prompt response.
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi NisHera
I think you are onto something here! As I mentioned earlier, I am pretty new at this! When you say "globally", what exactly do you mean, can you clarify (with an example) please?
Thanks.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
https://support.smartbear.com/viewarticle/85041/
^^^ Explained in there under "Important notes".
Just how Jscript scopes it's variables.
More here: https://msdn.microsoft.com/en-us/library/e1s0ezse(v=vs.100).aspx
(Assume the MSDN ref applies to how Jscript in TC behaves. I don't use Jscript personally, but I use C# script which uses the same engine as far as I'm aware.)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Colin
Based on your suggested reading, found out I need to declare the variable outside of the function. So this is what I have-
Unit "Search Patient by Department"
//USEUNIT Patient_Info // [Name, ptSource, acNum, MRN, DOB, aDate, Dept, Group] - in a array "pStat[]"" //search the patient by department function searchDept() { //gather patient info (unit "Patient_Info") Patient_Info.getPatientStat(); //back to Unit Search Patient by Department // log pStat - Log.message("Name: " + pStat[0]); Log.message("Patient Source: " + pStat[1]); Log.message("Account Number: " + pStat[2]); Log.message("MRN: " + pStat[3]); Log.message("DOB: " + pStat[4]); Log.message("Admission Date: " + pStat[5]); Log.message("Department: " + pStat[6]); Log.message("Group: " + pStat[7]); //home Aliases.browser.swce.aspnetForm.menuHome.Click(); //select search by department and patient name Aliases.browser.pifHome.aspnetForm.selectSearchBy.ClickItem(1); //select department dropdown - "Emergency Department" Aliases.browser.pifHome.aspnetForm.selectDepartment.ClickItem(3); //set patient name Aliases.browser.pifHome.aspnetForm.inputPatientName.SetText("Lena") //search Aliases.browser.pifHome.aspnetForm.btnSearch.ClickButton(); //select patient Aliases.browser.pifHome.aspnetForm.firstPatient.Click(); //view information Aliases.browser.swce.aspnetForm.menuViewInfo.Click(); // MRN =
Log.Message(pStat[3]); //check patient MRN aqObject.CheckProperty(Aliases.browser.swce.aspnetForm.panelPatientInfo.MRN, "contentText", cmpEqual, pStat[3]); . . .
Unit "Patient_Info"
//patient info var pStat = []; function getPatientStat() { . . . //point IE to SWCE3 Browsers.Item("iexplore", "", Browsers.pX86).Run("https://swce3.imedconsent.com/SRC"); //input username ...; //input password ... //slelect domain 'none' Aliases.browser.pifLogin.aspnetForm.setDomain.ClickItem(0); //click login Aliases.browser.pifLogin.aspnetForm.btnLogin.ClickButton(); //search patient name Aliases.browser.pifHome.aspnetForm.inputPatientName.SetText("lena"); //click search Aliases.browser.pifHome.aspnetForm.btnSearch.ClickButton(); //view information Aliases.browser.swce.aspnetForm.menuViewInfo.Click(); 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]; }
I am running "Search Patient by Department" routine, it immediately runs the Patient_Info routine and returns back to continue.
For some reason, array values are not ported over to Search Patient by Department. Log reports "undefined". Not sure what I did wrong.
Thanks for your help.
Dave
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like to thank both Colin and NisHera for pointing to right direction and my mistake! Thank you!
