cancel
Showing results for 
Search instead for 
Did you mean: 

DDT using Excel sheet

Highlighted
Occasional Contributor

DDT using Excel sheet

As i m a new user for test complete. I didnt get it how to do this..................

I m working with Jscript...........

Consider i m testing for registration form. First i fill only First name of mine clicks on Register button.Then i vl Fill First name n last name n click register button..........I vl do this untill my last field is entered after last entry i want to click on cancel button. What to do for that?

All the entries are passed by excel sheel. All test is running except that cancel button



Here is my code........................

function Main()

{

  try

  {

    // Enter your code here.

  }

  catch(exception)

  {

    Log.Error("Exception", exception.description);

  }

}





 // User Registration form DDT for Registration button

 // Creates the driver (main routine)

 

function User_Registration_Form_TestDriver()

{

  var Driver;

  var  iexplore;  

 

  // Creates the driver

  // If you connect to an Excel 2007 sheet, use the following method call:

  Driver = DDT.ExcelDriver("C:\\MyFile.xlsx", "Sheet2", true);

  TestedApps.IEXPLORE.Run();  

  iexplore = Aliases.IEXPLORE;      

  Aliases.iexplore.pageMedizzleUserRegistration1.panelBgdiv.panelMaindiv.table.cell.table.cellMainstageMinHt.panelFormcontentdiv.table.cell.linkRegister.Click();

  // Iterates through records

  RecNo = 0;

  while (! Driver.EOF() )

  {

    User_Registration_Form_ProcessData();// Processes data

    Driver.Next(); // Goes to the next record

  }

 

  // Closing the driver

  DDT.CloseDriver(Driver.Name);

  iexplore.IEFrame.Close();

}







//Data Driven testing for Register button for user registration form

var RecNo;

// Posts data to the log (helper routine)

function User_Registration_Form_ProcessData()

{

 

 

  var  iexplore;

  var  page;

  var  panel;

  var  table;

  var  passwordBox;

  var  checkbox;

  var i;

 

   for(i=0 ;i<DDT.CurrentDriver.ColumnCount; i++)

   

  iexplore = Aliases.IEXPLORE;

  Aliases.iexplore.IEFrame.Maximize();

 

 

  page = iexplore.pageMedizzleUserRegistration;

  page.Wait();

  panel = page.panelBgdiv.panelMaindiv.table.cell.table.cellMainstageMinHt.formRegisterForm.panelContentdiv;

  table = panel.panelUserselectiondiv.table;

  table = panel.panelFormcontentdiv.table.cellFormfieldpadding.panelFormfielddiv.table;



  //Enter First Name

  table.cell.textboxTxtfirstname.Text = DDT.CurrentDriver.Value("First Name");



   //Enter Last Name

  table.cell10.textboxtxtlastname.Text = DDT.CurrentDriver.Value("Last Name");



    //Enter Email Address

  table.cell7.textboxTxtemailid.Text = DDT.CurrentDriver.Value("Email address");



  //Enter User Name

  table.cell1.textboxTxtusername.Text = DDT.CurrentDriver.Value("User Name");



    //Enter password

  passwordBox = table.cell2.passwordboxTxtpasswd.Text=DDT.CurrentDriver.Value("Password");



  //Enter password again

  passwordBox = table.cell8.passwordboxTxtconfirmpasswd.Text=DDT.CurrentDriver.Value("Confirm Password");



   //Select Gender

  if(DDT.CurrentDriver.Value("Gender")=="Male")

  {

 

  table.cell3.table.cell.radiobuttonRadiogroup20.Click();

 

  }

  else

  {

  table.cell3.table.cell1.radiobuttonRadiogroup21.Click();

 

  }

 

  //Select Register as

  if(DDT.CurrentDriver.Value("Register as")=="Patient")

  {  

  table.cell9.table.cell1.radiobuttonRadiogroup10.Click();

      

  }

  else

  {  

  table.cell9.table.cell.radiobuttonRadiogroup11.Click();

 

  }

 

   //Enter Capcha Code

  table.cell4.textboxTxtcaptcha.Text=DDT.CurrentDriver.Value("Capcha Code");

 

  //Select Stay Connected

  if(DDT.CurrentDriver.Value("Stay Connected")=="Yes")

  {

  checkbox = table.cell5.table.cell.checkboxChknewletters.Click();

  }

  else

  {

  }

 

    //Select Privacy Policy

  if(DDT.CurrentDriver.Value("Privacy Policy")=="Yes")

  {

  table.cell6.table.cell.checkboxChkprivacy.Click();

  }

  else

  {

    Log.Message("Select the Privacy Policy");

  }

    if(i<=DDT.CurrentDriver.ColumnCount)

    {

    table.cellRegistrationfieldtxt.table.cell1.panelButtonBlueDisplay.submitbuttonSubmit.Click();

    }

    

    else

    {

    table.cellRegistrationfieldtxt.table.cell.panel.resetbuttonInput.Click();

    }

  //iexplore.IEFrame.Close();

  //aqUtils.Delay(2000);

    

}

Thanks.
Regards,
Payal
13 REPLIES 13
Highlighted
Contributor

RE: DDT using Excel sheet

Payal,



First thing is I am not able to see any line of code for Cancel button - are you talking about Reset button?




Next is want to suggest you to take care of  few things from your next post,

1) Do not duplicate your post in different sections - there is no use of this.

2) Refrain from using the phone-text language as this might confuse people who are not used to it plus I don't think you ll really save a lot of time writing "vl" instead of "will"!

3) Do not dump the whole long code - Be specific in your question and area of problem.




Thankyou





Syed Ahmed Safvan

Highlighted
Occasional Contributor

RE: DDT using Excel sheet

Ahmed,

Yes you are right. I am again telling you my query.

1] Consider i am testing any form using Jscript

2] It fills first field and clicks on submit button and checking for errors which are displayed and so on.

3] At the end it fills all the fields and then clicks on cancel button(In my case it is Reset button)

4] So how to select the last row of the excel sheet so that at that point it clicks on cancel button.
Thanks.
Regards,
Payal
Highlighted
Contributor

RE: DDT using Excel sheet

Payal,



This is a simple case of control flow.




You have the below IF condition running in the loop "for(i=0 ;i<DDT.CurrentDriver.ColumnCount; i++)" - (looks like you have forgot to write the braces )





    if(i<=DDT.CurrentDriver.ColumnCount)

     table.cellRegistrationfieldtxt.table.cell1.panelButtonBlueDisplay.submitbuttonSubmit.Click();

    else

     table.cellRegistrationfieldtxt.table.cell.panel.resetbuttonInput.Click();




Obviously  DDT.CurrentDriver.ColumnCount will never be greater than i. So the else condition will never execute.




If you have not forgot the braces and thats how the code is in that case you would have your  i as the max column count all the time in the function User_Registration_Form_ProcessData()




And I have no clue why you want to run that loop at all to accomplish what you want!




Thankyou








Syed Ahmed Safvan

Highlighted

RE: DDT using Excel sheet

Hi Payal,


If you need to find out whether DDTDriver has reached the end of the input file, you need to use the DDTDriver.EOF method. Please see the "DDTDriver.EOF" help topic for more information.



Best regards,
Alexey

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Occasional Contributor

RE: DDT using Excel sheet

Hello Ahmed,



I got that i forgot to give Braces for for loop.After giving braces also my code is not working for reset button.I also changed the conditions in the if  loop still its not working please guide



Thank you
Thanks.
Regards,
Payal
Highlighted

RE: DDT using Excel sheet

Hi Payal,


To help us investigate the problem, please provide us with a detailed description of the difference between the expected behavior and the actual behavior of TestComplete.



Best regards,
Alexey

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Contributor

RE: DDT using Excel sheet

Payal,



Try the code structure given below. This is a case of control flow (knowledge of programming and debugging related issue) and not related to TC tool.





function User_Registration_Form_TestDriver()

{

  //....

  //...

  //...

  while (! Driver.EOF() ) 

  {

    User_Registration_Form_ProcessData();// Processes data

    //Click your Reset Button here

    ResetButton.Click();

    Driver.Next(); // Goes to the next record

  }  

  // Closing the driver

  DDT.CloseDriver(Driver.Name);

  iexplore.IEFrame.Close();

}







function User_Registration_Form_ProcessData()

{

 //....

 //...

 //....  

 for(i=0 ;i<DDT.CurrentDriver.ColumnCount; i++)

  {

    //....

    //...

    //....

    if(i<=DDT.CurrentDriver.ColumnCount)

    {

      table.cellRegistrationfieldtxt.table.cell1.panelButtonBlueDisplay.submitbuttonSubmit.Click();

    }   

   //Delete the Else Part from here it wont be invoked in any case 

  }

{


Syed Ahmed Safvan

Highlighted
Occasional Contributor

RE: DDT using Excel sheet

Hello Ahmed,



We are trying to automate error handling test case. Here is the scenario -

1. Excel sheet has 10 rows containing data.

2. From the first 9 rows, the data should be filled onto the form and 'Submit' button is to be clicked.

3. From the 10th row data, the data should be filled onto the form and 'Cancel' button is to be clicked.



Using Column count check, we were not getting the desired result.



We need to use the row count for this.



This is what we did.



function test_driver()

{



var....



// This will give the used row count

var excel = Sys.OleObject("Excel.Application");

var book = excel.Workbooks.Open("C:\\Excel.xls");

var rowCount = book.Sheets(1).UsedRange.Rows.Count;

Log.Message(rowCount);

excel.Quit();



Driver = DDT.ExcelDriver("C:\\Excel.xls", "Sheet1", true);

 

// Iterates through records

RecNo = 0;

i = 1;

 

while (! Driver.EOF() )

{

    

 User_Registration(); // Run User Registration function

      

   if (i<rowCount-1)

    {

        Submit_Button();

    }

   else

    {

        Cancel_Button();

    }

    

i=i+1;

Driver.Next() // Goes to the next record

 

}

   

Aliases.iexplore1.IEFrame.Close();

// Closing the driver

DDT.CloseDriver(Driver.Name);

}



function User_Registration()

{

.

.

.

function to fill in data from excel sheet

.

.

}





There is nothing wrong in Test Complete tool, but we highly recommend that Test Complete should introduce inbuilt excel row count method.



If there is any better way to do this please let me know



Thank you.

Payal
Thanks.
Regards,
Payal
Highlighted
Contributor

RE: DDT using Excel sheet

If i were you, I would not use DDT for the spread sheet. I would use COM instead. It ll take a little time for you to get used to and redo your scripts but once you are there you cant resist using it.



Thankyou




Syed Ahmed Safvan

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors