5. Executing Script and Checking Results

Applies to TestComplete 15.10, last modified on December 15, 2021

The test script of the Orders application consists of several routines. One test consists of such operations as Opening the Order form, Populating the form, verifying the output data and closing the form. The appropriate routines are responsible for these operations. The Main routine performs multiple iterations of one test operation using different input data. Below is the complete test script:

JavaScript, JScript

function OpenForm(mainForm)
{
  mainForm.MainMenu.Click("Orders|New order...");
}

function PopulateForm(groupBox, Driver)
{
  var numericUpDown, textBox;

  groupBox.ProductNames.ClickItem(Driver.Value(1));
  numericUpDown = groupBox.Quantity;
  numericUpDown.Click(8, 7);
  numericUpDown.wValue = Driver.Value(2);
  groupBox.Date.wDate = Driver.Value(3);
  textBox = groupBox.Customer;
  textBox.Click(69, 12);
  textBox.wText = Driver.Value(0);
  textBox = groupBox.Street;
  textBox.Click(4, 8);
  textBox.wText = Driver.Value(4);
  textBox = groupBox.City;
  textBox.Click(12, 14);
  textBox.wText = Driver.Value(5);
  textBox = groupBox.State;
  textBox.Click(21, 6);
  textBox.wText = Driver.Value(6);
  textBox = groupBox.Zip;
  textBox.Click(14, 14);
  textBox.wText = Driver.Value(7);
  groupBox.WinFormsObject(Driver.Value(8)).ClickButton();
  textBox = groupBox.CardNo;
  textBox.Click(35, 15);
  textBox.wText = Driver.Value(9);
  groupBox.ExpDate.wDate = Driver.Value(10);
}

function Checkpoint(Driver)
{
  aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.Price, "wText", cmpEqual, Driver.Value(11), false);
  aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.Discount, "wText", cmpEqual,Driver.Value(12), false);
  aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.groupBox1.Total, "wText", cmpEqual, Driver.Value(13), false);
}

function CloseForm(orderForm)
{
  orderForm.ButtonOK.ClickButton();
}

function CloseApplication(mainForm, orders)
{
  mainForm.Close();
  orders.dlgConfirmation.btnNo.ClickButton();
}

function Main()
{
  var orders, mainForm, orderForm, groupBox, Driver;

  Driver = DDT.ExcelDriver("../../TestBook.xlsx", "TestSheet", true);
  TestedApps.RunAll();
  orders = Aliases.Orders;
  mainForm = orders.MainForm;
  while(!Driver.EOF())
  {
    OpenForm(mainForm);
    orderForm = orders.OrderForm;
    groupBox = orderForm.Group;
    PopulateForm(groupBox, Driver);
    Checkpoint(Driver);
    CloseForm(orderForm);
    Driver.Next();
  }
  CloseApplication(mainForm, orders);
}

Python

def OpenForm(mainForm):
  mainForm.MainMenu.Click("Orders|New order...")

def PopulateForm():
  groupBox.ProductNames.ClickItem(Driver.Value[1])
  numericUpDown = groupBox.Quantity
  numericUpDown.Click(8, 7)
  numericUpDown.wValue = Driver.Value[2]
  groupBox.Date.wDate = Driver.Value[3]
  textBox = groupBox.Customer
  textBox.Click(69, 12)
  textBox.wText = Driver.Value[0]
  textBox = groupBox.Street
  textBox.Click(4, 8)
  textBox.wText = Driver.Value[4]
  textBox = groupBox.City
  textBox.Click(12, 14)
  textBox.wText = Driver.Value[5]
  textBox = groupBox.State
  textBox.Click(21, 6)
  textBox.wText = Driver.Value[6]
  textBox = groupBox.Zip
  textBox.Click(14, 14)
  textBox.wText = Driver.Value[7]
  groupBox.WinFormsObject(Driver.Value[8]).ClickButton()
  textBox = groupBox.CardNo
  textBox.Click(35, 15)
  textBox.wText = Driver.Value[9]
  groupBox.ExpDate.wDate = Driver.Value[10]

  
def Checkpoint(Driver):
  aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.Price, "wText", cmpEqual, Driver.Value[11], False)
  aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.Discount, "wText", cmpEqual, Driver.Value[12], False)
  aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.groupBox1.Total, "wText", cmpEqual, Driver.Value[13], False)

def CloseForm(orderForm):
  orderForm.ButtonOK.ClickButton()
  
def CloseApplication():
  mainForm.Close()
  orders.dlgConfirmation.btnNo.ClickButton()
  
def Main():
  Driver = DDT.ExcelDriver("../../../TestBook.xlsx", "TestSheet", True)
  TestedApps.RunAll()
  orders = Aliases.Orders
  mainForm = orders.MainForm
  while not Driver.EOF():
    OpenForm(mainForm)
    orderForm = orders.OrderForm
    groupBox = orderForm.Group
    PopulateForm(groupBox, Driver)
    Checkpoint(Driver)
    CloseForm(orderForm)
    Driver.Next()
  CloseApplication(mainForm, orders)

VBScript

Sub OpenForm(mainForm)
  Call mainForm.MainMenu.Click("Orders|New order...")
End Sub

Sub PopulateForm(groupBox,Driver)
  Dim numericUpDown, textBox

  Call groupBox.ProductNames.ClickItem(Driver.Value(1))
  Set numericUpDown = groupBox.Quantity
  Call numericUpDown.Click(37, 9)
  numericUpDown.wValue = Driver.Value(2)
  groupBox.Date.wDate = Driver.Value(3)
  Set textBox = groupBox.Customer
  Call textBox.Click(39, 7)
  textBox.wText = Driver.Value(0)
  Set textBox = groupBox.Street
  Call textBox.Click(66, 7)
  textBox.wText = Driver.Value(4)
  Set textBox = groupBox.City
  Call textBox.Click(72, 9)
  textBox.wText = Driver.Value(5)
  Set textBox = groupBox.State
  Call textBox.Click(98, 9)
  textBox.wText = Driver.Value(6)
  Set textBox = groupBox.Zip
  Call textBox.Click(31, 12)
  textBox.wText = Driver.Value(7)
  groupBox.WinFormsObject(Driver.Value(8)).ClickButton
  Set textBox = groupBox.CardNo
  Call textBox.Click(53, 12)
  textBox.wText = Driver.Value(9)
  groupBox.ExpDate.wDate = Driver.Value(10)
End Sub

Sub Checkpoint(Driver)
  Call aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.Price, "wText", cmpEqual, Driver.Value(11), False)
  Call aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.Discount, "wText", cmpEqual, Driver.Value(12) , False)
  Call aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.groupBox1.Total, "wText", cmpEqual, Driver.Value(13), False)
End Sub

Sub CloseForm(orderForm)
 orderForm.ButtonOK.ClickButton
End Sub

Sub CloseApplication(orders, mainForm)
  mainForm.Close
  orders.dlgConfirmation.btnNo.ClickButton
End Sub

Sub Main
  Dim orders, mainForm, orderForm, groupBox
  Set Driver = DDT.ExcelDriver("../../TestBook.xlsx", "TestSheet", True)
  TestedApps.RunAll
  Set orders = Aliases.Orders
  Set mainForm = orders.MainForm
  While Not Driver.EOF
    Call OpenForm(mainForm)
    Set orderForm = orders.OrderForm
    Set groupBox = orderForm.Group
    Call PopulateForm(groupBox, Driver)
    Call Checkpoint(Driver)
    Call CloseForm(orderForm)
    Driver.Next
  Wend
  Call CloseApplication(orders, mainForm)
End Sub

DelphiScript

procedure OpenForm(mainForm);
begin
  mainForm.MainMenu.Click('Orders|New order...');
end;

procedure PopulateForm(groupBox, Driver);
var numericUpDown, textBox;
begin
  groupBox.ProductNames.ClickItem(Driver.Value(1));
  numericUpDown := groupBox.Quantity;
  numericUpDown.Click(37, 9);
  numericUpDown.wValue := Driver.Value(2);
  groupBox.Date.wDate := Driver.Value(3);
  textBox := groupBox.Customer;
  textBox.Click(67, 17);
  textBox.wText := Driver.Value(0);
  textBox := groupBox.Street;
  textBox.Click(31, 5);
  textBox.wText := Driver.Value(4);
  textBox := groupBox.City;
  textBox.Click(47, 15);
  textBox.wText := Driver.Value(5);
  textBox := groupBox.State;
  textBox.Click(82, 4);
  textBox.wText := Driver.Value(6);
  textBox := groupBox.Zip;
  textBox.Click(10, 8);
  textBox.wText := Driver.Value(7);
  groupBox.WinFormsObject(Driver.Value(8)).ClickButton;
  textBox := groupBox.CardNo;
  textBox.Click(46, 9);
  textBox.wText := Driver.Value(9);
  groupBox.ExpDate.wDate := Driver.Value(10);
end;

procedure Checkpoint(Driver);
begin
  aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.Price, 'wText', cmpEqual, Driver.Value(11), false);
  aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.Discount, 'wText', cmpEqual, Driver.Value(12), false);
  aqObject.CheckProperty(Aliases.Orders.OrderForm.Group.groupBox1.Total, 'wText', cmpEqual, Driver.Value(13), false);
end;

procedure CloseForm(orderForm);
begin
  orderForm.ButtonOK.ClickButton;
end;

procedure CloseApplication(orders, mainForm);
begin
  mainForm.Close;
  orders.dlgConfirmation.btnNo.ClickButton;
end;

procedure Main;
var orders, mainForm, orderForm, groupBox, Driver;
begin
  Driver:=DDT.ExcelDriver('../../TestBook.xlsx', 'TestSheet', true);
  TestedApps.RunAll;
  orders := Aliases.Orders;
  mainForm := orders.MainForm;
  while not Driver.EOF do
  begin
    OpenForm(mainForm);
    orderForm := orders.OrderForm;
    groupBox := orderForm.Group;
    PopulateForm(groupBox,Driver);
    Checkpoint(Driver);
    CloseForm(orderForm);
    Driver.Next;
  end;
  CloseApplication(orders, mainForm);
end;

C++Script, C#Script

function OpenForm(mainForm)
{
  mainForm["MainMenu"]["Click"]("Orders|New order...");
}

function PopulateForm(groupBox, Driver)
{
  var numericUpDown, textBox;

  groupBox["ProductNames"]["ClickItem"](Driver.Value(1));
  numericUpDown = groupBox["Quantity"];
  numericUpDown["Click"](37, 9);
  numericUpDown["wValue"] = Driver.Value(2);
  groupBox["Date"]["wDate"] = Driver.Value(3);
  textBox = groupBox["Customer"];
  textBox["Click"](43, 7);
  textBox["wText"] = Driver.Value(0);
  textBox = groupBox["Street"];
  textBox["Click"](31, 11);
  textBox["wText"] = Driver.Value(4);
  textBox = groupBox["City"];
  textBox["Click"](24, 6);
  textBox["wText"] = Driver.Value(5);
  textBox = groupBox["State"];
  textBox["Click"](31, 8);
  textBox["wText"] =Driver.Value(6);
  textBox = groupBox["Zip"];
  textBox["Click"](24, 17);
  textBox["wText"] = Driver.Value(7);
  groupBox["WinFormsObject"](Driver.Value(8))["ClickButton"]();
  textBox = groupBox["CardNo"];
  textBox["Click"](19, 7);
  textBox["wText"] = Driver.Value(9);
  groupBox["ExpDate"]["wDate"] = Driver.Value(10);
}

function Checkpoint(Driver)
{
  aqObject.CheckProperty(Aliases["Orders"]["OrderForm"]["Group"]["Price"], "wText", cmpEqual, Driver.Value(11), false);
  aqObject.CheckProperty(Aliases["Orders"]["OrderForm"]["Group"]["Discount"], "wText", cmpEqual, Driver.Value(12), false);
  aqObject.CheckProperty(Aliases["Orders"]["OrderForm"]["Group"]["groupBox1"]["Total"], "wText", cmpEqual, Driver.Value(13), false);
}

function CloseForm(orderForm)
{
  orderForm["ButtonOK"]["ClickButton"]();
}

function CloseApplication(mainForm, orders)
{
  mainForm["Close"]();
  orders["dlgConfirmation"]["btnNo"]["ClickButton"]();
}

function Main()
{
  var orders, mainForm, orderForm, groupBox, Driver;

  Driver = DDT["ExcelDriver"]("../../TestBook.xlsx", "TestSheet", true);
  TestedApps["RunAll"]();
  orders = Aliases["Orders"];
  mainForm = orders["MainForm"];
  while(!Driver.EOF())
  {
    OpenForm(mainForm);
    orderForm = orders["OrderForm"];
    groupBox = orderForm["Group"];
    PopulateForm(groupBox,Driver);
    Checkpoint(Driver);
    CloseForm(orderForm);
    Driver["Next"]();
  }
  CloseApplication(mainForm, orders);
}

To run this script, right-click its node in the Project Explorer and select Run > Run Main from the context menu.

After the test is over, you can analyze test log. All of the warnings and errors occurred during the script execution are posted to the log. If there are “The property value does not equal the template value” informative messages in the log, the output value does not match the appropriate verifying value. This indicates that the application works incorrectly. You can include any information you need in log messages. For instance, you can specify the values of all input parameters that were used when the error occurred.

You can find the sample data-driven testing project in the following folder:

<TestComplete Samples>\Common\Data-Driven Testing\Scripts

If you do not have the sample, download the TestComplete Samples installation package from the https://support.smartbear.com/testcomplete/downloads/samples/ page of our website and run it.

Prev

See Also

Tutorial Home Page
Test Results

Highlight search results