Monday, September 8, 2008

How to Schedule a script execution with Code?

Create a VBS file with the following code and create a Schedule task with the below navigation.
Navigation:- Start --> Settings --> control pannel --> Scheduled Tasks --> Add Scheduled task

Code:-

Call Schedule ("Path ") ' Give here Script Path (First Script)
Call Schedule("Path") ' Give here Script Path ( If you want to Execute Second, give Second script path)
Call Schedule("Path") ' Give here Script Path ( If you want to Execute Third, give third script path)
……
…….. Etc.
' Create function for script execution
Function Schedule(scriptPath)
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
Dim qtResultsOpt 'As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start QuickTest
qtApp.Visible = True ' Make the QuickTest application visible
' Set QuickTest run options
qtApp.Options.Run.CaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False
qtApp.Open scriptPath, False ' Open the test in
' set run settings for the test
Set qtTest = qtApp.Test
qtTest.Settings.Run.IterationMode = "rngIterations" ' Run only iterations 1 to 10
qtTest.Settings.Run.StartIteration = 1
qtTest.Settings.Run.EndIteration = 10
qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next step when error occurs
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object
qtResultsOpt.ResultsLocation = "C:\Result" & hour(now) & minute(now) & second(now) ' Set the results location
qtTest.Run qtResultsOpt ' Run the test
'MsgBox qtTest.LastRunResults.Status ' Check the results of the test run
qtTest.Close ' Close the test
Set qtResultsOpt = Nothing ' Release the Run Results Options object
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object
End Function

Saturday, September 6, 2008

Data Table Relating Code

1) How to import excel file from local machine to Datatable?

A) Datatable.Import "C:\import.xls"

2) How to Export datatable to local machine?

A) Datatable.Export "C:\Export.xls"

3) How to import specific sheet from local machine into datatable?

A) Datatable.importsheet file path,source sheet name,destination sheet name

4) How to export specific sheet from datatable into local machine?

A) Datatable.Exportsheet file path,Datatable sheet name / Index

5) How to get row count of a runtime data table sheet?

A)
Dim RowCount
For global sheet
RowCount=DataTable.GetRowCount

For specific sheet or Local sheet
RowCount=DataTable.GetSheet("SheetName").GetRowCount

6) How to add a sheet to the runtime data table?
A) Datatable.Addsheet(“SheetName”)

7) How to add a column to the runtime data table?
A) Datatable.GetSheet("Sheetname").AddParameter "ParameterName",""

8) How to get data from runtime datatable?
A) Datatable.value(“ColumnName”,”SheetName”)

We can get data in different way also
From global sheet:
Datatable.Value(“ColumnName”,dtGlobalSheet)
From Local Sheet:
Datatable.Value("ColumnName",dtLocalSheet)

9) How to import excel file from Quality center (9.2) to QTP (9.2) data table?

A)
We can import with data table import command, but file path we have to give in specified format only. See the below code.

Code:- DataTable.ImportSheet "[QC-ATTACH];;Subject\DomainName\Project Name\Automation\ScriptName;;\Excelfilename.xls","Source Sheet name","Destination sheet name(datat tale sheet name)"