Monday 30 June 2014

Data Driven testing with TestComplete.


Data-driven testing means running our automated tests script with different set of test data, it is simulate user actions over an application with different inputs.TestComplete allow us to perform data driven testing.

Let's consider in our application we are having 100 of users and we need to check login functionality of them, to find out which user credentials are working properly and which are not.

In order to complete this task, we can create a script in TC which would read each of the user credentials and try to login in application.

Let start step by step discussion of Data Driven Testing with TestComplete using CSV file-

CSV - comma-separated values (CSV) (also sometimes called character-separated values, because the separator character does not have to be a comma) file stores tabular data (numbers and text) in plain-text form. For creating a CSV file please refer : - http://www.computerhope.com/issues/ch001356.htm

CSV file one of the most popular data storage system for data-driven tests it is store comma-separated values.TestComplete supports this type of storage and allows us to retrieve data from it.

TestComplete provide CSVDriver() Method to create DDT driver (using DDT Driver object we can easily extract data which is stored in CSV file) for CSV file than contains values separated with your predefine delimiter character. (here Comma is separator)
Let us consider we have a CSV file (UserDetails.csv) along with number of UserId and Password.
First of all we need to initialize/create CSV Driver by using CSVDriver().
Syntax -
             DDT.CSVDriver("FilePath")

 Lets Consider we have saved (UserDetails.csv) file on path "D:\Automation\UserDetails.csv" 

Sub DDTCSVTest
             'create csv driver object
             DDT.CSVDriver(“D:\Automation\UserDetails.csv”)
End Sub

We are having multiple set of data in csv file, TestComplete read those set of data one by one from the file, hence we need to check whether DDT driver is end of the csv file, which is provides access for DDT.

DDT.CurrentDriver.EOF - this method is used to determine where is your file end point. it will be return true when DDT Driver at the End otherwise false.

Sub DDTCSVTest
             'create csv driver object
             DDT.CSVDriver(“D:\Automation\UserDetails.csv”)
             'Iterates through the records
             While Not DDT.CurrentDriver.EOF
             :
             :
             Wend
End Sub

TestComplete provide DDT.CurrentDriver.Value(index) method for reading data from the csv file.DDT.CurrentDriver.Value() method read column values at the index with 0 (zero)

Sub DDTCSVTest
 'create csv driver object
DDT.CSVDriver(“D:\Automation\UserDetails.csv”)
While Not DDT.CurrentDriver.EOF
    TestObj.Textbox("txtUserName").SetText(DDT.CurrentDriver.Value(0))
    TestObj.PasswordBox ("txtPwd").SetText(DDT.CurrentDriver.Value(1))
    TestObj.SubmitButton("btnLogin").Click  
    
Wend
End Sub

DDT.CurrentDriver.Value(0) : - Reading user name from the csv file.
DDT.CurrentDriver.Value(1) : -  Reading Password from the csv file.

Note :- TestComplete considering first row as header of csv file.

Above code just read a single set of data from the csv file, but we need to read next set of data, if available, then use DDT.CurrentDriver.Next method. DDT.CurrentDriver.Next goes to the next set of data from the csv file.

Sub DDTCSVTest
'create csv driver object
DDT.CSVDriver(“D:\Automation\UserDetails.csv”)
While Not DDT.CurrentDriver.EOF
     TestObj.Textbox("txtUserName").SetText(DDT.CurrentDriver.Value(0))
     TestObj.PasswordBox("txtPwd").SetText(DDT.CurrentDriver.Value(1))
     TestObj.SubmitButton("btnLogin").Click  
DDT.CurrentDriver.Next   
Wend
End Sub

This code would be read data as Username and Password from the second row (first row is header) then click on submit button and goes to the next record (if available) and it's reading all the records one by one until set of data is end.


1 comment:

  1. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you. Your videos are so good. Your work is amazing. You can also check out vstfine Crack for Free. You can also visit the
    Vstfine Crack
    TestComplete Crack
    idm Crack

    ReplyDelete