Interview Questions   Tutorials   Discussions   Programs   Videos   

QTP - How to get data from excel sheet to the script? write the script.

asked marvit August 19, 2014 01:47 AM  

How to get data from excel sheet to the script? write the script.


1 Answers

answered By Dharma   0  

Once we have the data ready, its time to write the code that will fetch the data from the datatable. To fetch the value from the DataTable, we will use DataTable.Value command. If you want to fetch the username from “Global” sheet, the command will be var = DataTable.Value(“UserName”, “Global”). When you run this statement, value “anish” will be stored in variable “var”.

Let’s see the entire script that will -
a) Open Flight Reservation Login screen.
b) Enter user id and password.
c) If Login is successful, QTP will close the application.
d) If Login is unsuccessful, then also QTP will close the application.

'Open Flight Reservation Application
SystemUtil.Run "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
'Enter UserId and Password
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set DataTable.Value("UserName", "Global")
Dialog("text:=Login").WinEdit("attached text:=Password:").Set DataTable.Value("Password", "Global")
'Click on Ok button
'Check if Login is Successful or Not
'Check if error message is displayed
If Dialog("text:=Login").Dialog("text:=Flight Reservations").Exist(4) Then
 'Click on Ok button to close the dialog
 Dialog("text:=Login").Dialog("text:=Flight Reservations").WinButton("text:=OK").Click
 'Click on Cancel to Close the Login Screen
 Reporter.ReportEvent micFail, "Login Unsuccessful", ""
 'Login is successful. close the application
 Reporter.ReportEvent micPass, "Login Successful", ""
 Window("text:=Flight Reservation").Close()
End If

   add comment

Your answer

Join with account you already have



Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!