DDT.CurrentDriver.Next(); not working!
I am following the instruction here https://support.smartbear.com/testcomplete/docs/reference/program-objects/ddt/exceldriver.html
When running the script, it gets stuck at -
while (!DDT.CurrentDriver.EOF()) { if (DDT.CurrentDriver.Value("Name") == "Tom Morgan") { newPatient.createPatients();
DDT.CurrentDriver.Next(); } }
Interestingly, while writing the script, by mistakenly put "DDT.CurrentDriver.Next();" outside the if statement. The script ran once! That is when I realized that it is in the wrong place. Correcting that caused it to stop working!
while (!DDT.CurrentDriver.EOF()) { if (DDT.CurrentDriver.Value("Name") == "Tom Morgan") { newPatient.createPatients(); } DDT.CurrentDriver.Next(); }
I can not figure out what I am doing wrong!
OK, I took a few minutes and spent time getting this to work. THIS should work now...
try { var xlDriver = DDT.ExcelDriver("C:\\femalePatients.xlsx", "patients", true); var startingRow = 2; //Let's say Lizzie is the second patient var rowsToProcess = 6; var currentRow = 0; while (!xlDriver.EOF()) { currentRow++ //Increment this counter to mark what row you're on if((currentRow >= startingRow) && (rowsToProcess > 0)){ newPatient.createPatients(); rowsToProcess-- //decrement this counter to indicate you've processed the current row } if (rowsToProcess === 0){ break; } xlDriver.Next(); //Go to the next row } } catch(exception)//exception { Log.Error(exception.message); } DDT.CloseDriver(xlDriver.Name); }
I'm building my own counters so the first row to attempt to process is row 1, not row 0. My code above should skip the first row of actual data in your excel file then, starting with the second row of date, will create new patients for that row and the next 5 and then it should exit the loop. This worked for me in my test environment so it should work for you.
EDIT: Note that the "rows" that I'm using have nothing directly to do with the driver itself... these are constructs that I created for tracking our way through the while loop and determining when to process and when to exit.
I see the problem... in newPatients.createPatient, you need to remove line nine where you define a new driver and then change all the xlDriver variables to DDT.CurrentDriver. This is a legitimate way to use CurrentDriver. You're calling "createPatient" within a data loop that's using a driver and you want to operate on the contents in the driver. So... leave pDDT.js as it is... it's fine... and make the following changes to newPatient.js
function createPatients(){ var page = Sys.Browser("*").Page("*"); var dept, admitDate, pName, gender, dob, ssn, email1, email2, lang, createPt; aqUtils.Delay(1000); dept = page.FindChild("ObjectIdentifier", "PAT_LOC", 10); admitDate = page.FindChild("ObjectIdentifier", "ADMITDATE", 10); pName = page.FindChild("ObjectIdentifier", "PATNAME", 10); gender = page.FindChild("ObjectIdentifier", "PATSEX", 10); dob = page.FindChild("ObjectIdentifier", "PATDOB", 10); ssn = page.FindChild("ObjectIdentifier", "PATSSN", 10); email1 = page.FindChild("ObjectIdentifier", "PRIMARYADDRESS", 10); email2 = page.FindChild("ObjectIdentifier", "SECONDARYADDRESS", 10); lang = page.FindChild("ObjectIdentifier", "LANGUAGEPREF", 10); Log.AppendFolder(DDT.CurrentDriver.Value("Name")); dept.ClickItem(DDT.CurrentDriver.Value("Department")); admitDate.SetText(DDT.CurrentDriver.Value("Admission Date")); pName.SetText(DDT.CurrentDriver.Value("Name")); gender.ClickItem(DDT.CurrentDriver.Value("Sex")); dob.SetText(DDT.CurrentDriver.Value("DOB")); ssn.SetText(DDT.CurrentDriver.Value("SSN")); email1.SetText(DDT.CurrentDriver.Value("email1")); email2.SetText(DDT.CurrentDriver.Value("email2")); lang.ClickItem(DDT.CurrentDriver.Value("Lang")); createPt = page.FindChild("ObjectIdentifier", "submitBtn", 10); createPt.ClickButton(); aqUtils.Delay(6000); page.Keys("[F5]"); Log.PopLogFolder(); } module.exports.createPatients = createPatients;