Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

DateTime Formatting In VSTS

DateTime Formatting In VSTS : How to Format Date and Time in various manner ?


Private Sub Page_Load(sender As Object, e As System.EventArgs)

  Response.Write("Default: " System.DateTime.Now "<br>")
  Response.Write("Local Time: " System.DateTime.Now.ToLocalTime() "<br>")
  Response.Write("Long Date: " System.DateTime.Now.ToLongDateString() "<br>")
  Response.Write("Long Time: " System.DateTime.Now.ToLongTimeString() "<br>")
  Response.Write("Short Date: " System.DateTime.Now.ToShortDateString() "<br>")
  Response.Write("Short Time: " System.DateTime.Now.ToShortTimeString() "<br>")
  Response.Write("ToString Default: " System.DateTime.Now.ToString() "<br>")
  Response.Write("Universal Time: " System.DateTime.Now.ToUniversalTime() "<br>"' returns a datetime, which can still be formatted
  
  ' Using Format Strings
  Response.Write("d - Short Date: " System.DateTime.Now.ToString("d") "<br>")
  Response.Write("D - Long Date: " System.DateTime.Now.ToString("D") "<br>")
  Response.Write("t - Short Time: " System.DateTime.Now.ToString("t") "<br>")
  Response.Write("T - Long Time: " System.DateTime.Now.ToString("T""<br>")
  Response.Write("f - Full date/time (short time): " System.DateTime.Now.ToString("f") "<br>")
  Response.Write("F - Full date/time (long time): " System.DateTime.Now.ToString("F") "<br>")
  Response.Write("g - General: " System.DateTime.Now.ToString("g""<br>")
  Response.Write("G - General: " System.DateTime.Now.ToString("G") "<br>")
  Response.Write("M/m - Month day: " System.DateTime.Now.ToString("M") "<br>")
  Response.Write("u - Universal Sortable: " System.DateTime.Now.ToString("u") "<br>")
  Response.Write("Y/y - Year month: " System.DateTime.Now.ToString("y") "<br>")

  ' Custom Format Strings
  Response.Write("d, day of month: " & System.DateTime.Now.ToString(" d""<br>"' can't use just "d"
  Response.Write("dd, zero-padded day of month: " & System.DateTime.Now.ToString("dd""<br>")
  Response.Write("ddd, abbreviated day of week: " & System.DateTime.Now.ToString("ddd""<br>")
  Response.Write("dddd, full day of week: " & System.DateTime.Now.ToString("dddd""<br>")

  Response.Write("h, hour: " & System.DateTime.Now.ToString(" h""<br>"' can't use just "h"
  Response.Write("hh, hour, zero padded " & System.DateTime.Now.ToString("hh""<br>")
  Response.Write("H, hour, 24-hr " & System.DateTime.Now.ToString(" H""<br>"' can't use just "H"
  Response.Write("H, hour, 24-hr, zero padded " & System.DateTime.Now.ToString("HH""<br>")
  
  Response.Write("m, minute: " & System.DateTime.Now.ToString(" m""<br>"' can't use just "m"
  Response.Write("M, month: " & System.DateTime.Now.ToString(" M""<br>"' can't use just "M"
  Response.Write("MM, month, zero padded: " & System.DateTime.Now.ToString("MM""<br>"
  Response.Write("MMM, month abbreviated: " & System.DateTime.Now.ToString("MMM""<br>"
  Response.Write("MMMM, month full name: " & System.DateTime.Now.ToString("MMMM""<br>"
  
  Response.Write("y, year (omits century): " & System.DateTime.Now.ToString(" y""<br>"' can't use just "y"
  Response.Write("yy, 2-digit year, zero padded: " & System.DateTime.Now.ToString("yy""<br>"
  Response.Write("yyyy, 4-digit year, zero padded: " & System.DateTime.Now.ToString("yyyy""<br>"
End Sub 'Page_Load


Datasheet Handling in Data driven Testing4 - QTP

QTP Datadriven testing : Parameter in Datasheet programming :

A parameter (column) in a sheet in the run-time Data Table. This object is not a built-in utility object, but can be accessed using one of the following methods:

    * DTSheet.AddParameter
    * DTSheet.GetParameter

      Note: All methods performed on this object apply to the run-time DataTable object only. Changes to the run-time DataTable object are reflected in the test results, but the design-time Data Table is not affected.

Associated Properties

    * Name Property
    * RawValue Property
    * Value Property
    * ValueByRow Property

Example:AddParameter

The following example uses the AddParameter method to create the new Parameter, "Arrival" within the new sheet, MySheet of the run-time Data Table, and sets the first cell in the column as "New York". Because the method also returns the newly created parameter, it is possible to use methods or check properties of the new sheet within the same statement.

ParamName=DataTable.AddSheet("MySheet").AddParameter("Arrival", "New York").Name

Note that if a parameter with the name "Arrival" already exists in the sheet, the example above will return "Arrival1" as the actual name assigned to the new parameter.

The example below performs the equivalent of renaming a column (parameter) in the DataTable by copying the data from one column to a new column with a new name, and then deleting the old column.

'add a new column
DataTable.GetSheet("dtGlobalSheet").AddParameter "NewColumn","Row1Value"

'copy the cells from the old column into the new column
cnt=DataTable.GetRowCount
For i=1 to cnt
       DataTable.SetCurrentRow(i)
       OldVal=DataTable.Value("OldColumn","dtGlobalSheet")
       DataTable.Value("NewColumn","dtGlobalSheet")=OldVal
Next

'delete the old column
DataTable.GetSheet("dtGlobalSheet").DeleteParameter("OldColumn")

GetParameter  Example

The following example uses the GetParameter method to return the "Destination" parameter from the run-time Data Table sheet: MySheet.

DataTable.GetSheet("MySheet").GetParameter("Destination")

Name  Example

The following example uses the Name method to return the name of the newly created parameter in the run-time Data Table and writes it in the report.

Dim paramname

paramname = DataTable.LocalSheet.AddParameter("Food", "pizza").Name

Reporter.ReportEvent 1, "The New Parameter name is", paramname

RawValue  Example

The following example uses the RawValue property to find the formula used in the current row of the Date column in the ActionA sheet of the run-time Data Table. The statement below returns the value: =NOW()

FormulaVal=DataTable.GetSheet("ActionA").GetParameter("Date").RawValue

Value Example

The following example uses the Value property to set the value in the current row of the Destination parameter (column) in the "ActionA" sheet of the run-time Data Table.

DataTable.GetSheet("ActionA").GetParameter("Destination").Value="New York"

Note: You could omit the word Value in the statement above, because Value is the default property for the DTParameter object.

Example ValueByRow

The following example uses the ValueByRow property to find the value in the 4th row of the Destination parameter (column) in the "ActionA" sheet of the run-time Data Table.

DataTable.GetSheet("ActionA").GetParameter("Destination").ValueByRow(4)

Datasheet Handling in Data driven Testing2 - QTP


The following example uses the AddParameter method to create the new Parameter, "Arrival" within the new sheet, MySheet of the run-time Data Table, and sets the first cell in the column as "New York". Because the method also returns the newly created parameter, it is possible to use methods or check properties of the new sheet within the same statement.

ParamName=DataTable.AddSheet("MySheet").AddParameter("Arrival", "New York").Name

Note that if a parameter with the name "Arrival" already exists in the sheet, the example above will return "Arrival1" as the actual name assigned to the new parameter.

The example below performs the equivalent of renaming a column (parameter) in the DataTable by copying the data from one column to a new column with a new name, and then deleting the old column.

'add a new column
DataTable.GetSheet("dtGlobalSheet").AddParameter "NewColumn","Row1Value"

'copy the cells from the old column into the new column
cnt=DataTable.GetRowCount
For i=1 to cnt
       DataTable.SetCurrentRow(i)
       OldVal=DataTable.Value("OldColumn","dtGlobalSheet")
       DataTable.Value("NewColumn","dtGlobalSheet")=OldVal
Next

'delete the old column
DataTable.GetSheet("dtGlobalSheet").DeleteParameter("OldColumn") 


The following example uses the DeleteParameter method to delete the parameter, "Arrival" from the "MySheet" sheet of the run-time Data Table.

DataTable.GetSheet("MySheet").DeleteParameter("Arrival")

Note that deleting a parameter from the sheet will cause the run to fail if a corresponding parameter exists in a step.

The example below performs the equivalent of renaming a column (parameter) in the DataTable by copying the data from one column to a new column with a new name, and then deleting the old column.

'add a new column
DataTable.GetSheet("dtGlobalSheet").AddParameter "NewColumn","Row1Value"

'copy the cells from the old column into the new column
cnt=DataTable.GetRowCount
For i=1 to cnt
       DataTable.SetCurrentRow(i)
       OldVal=DataTable.Value("OldColumn","dtGlobalSheet")
       DataTable.Value("NewColumn","dtGlobalSheet")=OldVal
Next

'delete the old column
DataTable.GetSheet("dtGlobalSheet").DeleteParameter("OldColumn")


The following example uses the GetCurrentRow method to retrieve the row currently being used by the run-time Data Table and writes it to the report.

row = DataTable.GetSheet("MySheet").GetCurrentRow

Reporter.ReportEvent 1, "Row Number", row 

The following example uses the GetParameter method to return the "Destination" parameter from the run-time Data Table sheet: MySheet.

DataTable.GetSheet("MySheet").GetParameter("Destination") 

The following example uses the GetParameterCount method to find the total number of parameters (columns) in the run-time Data Table sheet (MySheet) and writes it to the report.

paramcount = DataTable.GetSheet("MySheet").GetParameterCount

Reporter.ReportEvent 2, "There are " &paramcount, "columns in the data sheet."




The following example uses the GetRowCount method to find the total number of rows in the first column of the run-time Data Table sheet (MySheet) and writes it to the report.

rowcount = DataTable.GetSheet("MySheet").GetRowCount

Reporter.ReportEvent 2, "There are " &rowcount, "rows in the data sheet." 

The following example uses the SetCurrentRow method to change the active row to the second row in the MySheet run-time data sheet.

DataTable.GetSheet("MySheet").SetCurrentRow(2) 

The following example uses the SetNextRow method to change the active row to the next row in the run-time Data Table.

DataTable.GetSheet("MySheet").SetNextRow



The following example uses the SetPrevRow method to change the active row to the previous row in the run-time data sheet.

DataTable.GetSheet("MySheet").SetPrevRow


The following example uses the Name method to return the name of the active run-time data sheet and writes it in the report.

Sheetname = DataTable.LocalSheet.Name

Reporter.ReportEvent 1, "The Active Sheet is", Sheetname



Datasheet Handling in Data driven Testing1 - QTP

Description

A sheet in the run-time Data Table. This object is not a built-in utility object, but can be accessed using one of the following methods or properties:

  • DataTable.AddSheet  
  • DataTable.GetSheet
  • DataTable.GlobalSheet
  • DataTable.LocalSheet

    Notes:
    All methods performed on this object apply to the run-time DataTable object only. Changes to the run-time DataTable object are reflected in the test results, but the design time Data Table is not affected.
    When working with scripted components, the name of the (single) Data Sheet is identical to the name of scripted component. If you save the scripted component with a new name, the name of the data sheet changes accordingly.

Associated Methods

  • AddParameter Method

  • DeleteParameter Method

  • GetCurrentRow Method

  • GetParameter Method

  • GetParameterCount Method

  • GetRowCount Method

  • SetCurrentRow Method

  • SetNextRow Method

  • SetPrevRow Method

Associated Properties

  • Name Property



DataTable.AddSheet(SheetName)


Argument

Type

Description

SheetName

String

Assigns a name to the new sheet.

Return Value

DTSheet Object.

Example

The following example uses the AddSheet method to create the new sheet, "MySheet" in the run-time Data Table and then adds a parameter to the new sheet.

Variable=DataTable.AddSheet ("MySheet").AddParameter("Time", "8:00") 


DataTable.GetSheet(SheetID)


Argument

Type

Description

SheetID

Variant

Identifies the sheet to be returned. The Sheet ID can be the sheet name or index. Index values begin with 1.

Return Value

DTSheet Object

Examples

The following example uses the GetSheet method to return the "MySheet" sheet of the run-time Data Table and add a parameter to it.

MyParam=DataTable.GetSheet ("MySheet").AddParameter("Time", "8:00")

You can also use this to add a parameter to the "MySheet" local sheet (note that no value is returned).

DataTable.GetSheet ("MySheet").AddParameter "Time", "8:00"

The example below performs the equivalent of renaming a column (parameter) in the DataTable by copying the data from one column to a new column with a new name, and then deleting the old column.

'add a new column
DataTable.GetSheet("dtGlobalSheet").AddParameter "NewColumn","Row1Value"

'copy the cells from the old column into the new column
cnt=DataTable.GetRowCount
For i=1 to cnt
       DataTable.SetCurrentRow(i)
       OldVal=DataTable.Value("OldColumn","dtGlobalSheet")
       DataTable.Value("NewColumn","dtGlobalSheet")=OldVal
Next

'delete the old column
DataTable.GetSheet("dtGlobalSheet").DeleteParameter("OldColumn")

DataTable.GlobalSheet

Example

The following example uses the GlobalSheet property to return the global sheet of the run-time Data Table in order to add a parameter (column) to it.

ParamValue=DataTable.GlobalSheet.AddParameter("Time", "5:45")

You can also use this method to add a parameter to the global sheet (note that no value is returned).

DataTable.GlobalSheet.AddParameter "Time", "5:45"


DataTable.LocalSheet

Example

The following example uses the LocalSheet property to return the local sheet of the run-time Data Table in order to add a parameter (column) to it.


QTP Extern Objects

QTP object identification and the object properties for Automation testing :
Description

Declares references to external procedures in a dynamic-link library (DLL).

After you use the Declare method for a method, you can use the Extern object to call the declared method.

Syntax

Extern.Declare(RetType, MethodName, LibName, Alias [, ArgType(s)])


Argument

Type

Description

RetType

String

Data type of the value returned by the method. For available data types, see Declare Data Types.

MethodName

String

Any valid procedure name.

LibName

String

Name of the DLL or code resource that contains the declared procedure.

Alias

String

Name of the procedure in the DLL or code resource.

Note: DLL entry points are case sensitive.

Note: If Alias is an empty string, MethodName is used as the Alias.

ArgType(s)

String

A list of data types representing the data types of the arguments that are passed to the procedure when it is called. For available data types, see Declare Data Types.

Note: For out arguments, use the micByRef flag.

Example

The following example uses the Extern.Declare and Extern. methods to change the title of the Notepad window.

'Declare FindWindow method

Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString

'Declare SetWindowText method

Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString

'Get HWND of the Notepad window

hwnd = Extern.FindWindow("Notepad", vbNullString)

if hwnd = 0 then

MsgBox "Notepad window not found"

end if

'Change the title of the notepad window

res = Extern.SetWindowText(hwnd, "kuku")

The following example retrieves information from an external INI file using GetPrivateProfileString, and uses it in the test. Note the use of the micByRef flag to indicate the out argument.

Extern.Declare micInteger,"GetPrivateProfileStringA", "kernel32.dll","GetPrivateProfileStringA", micString, micString, micString, micString+micByRef, micInteger, micString

Dim key, i, key2

key = String(32, "-")

i = Extern.GetPrivateProfileStringA("WREnv","addons","xxx", key, 32, "wrun.ini")

key2 = Left(key,i)

msgbox key & ";" & key2 & ";" & CStr(i)

The following example checks when the cursor is displayed as an hour glass.

extern.Declare micLong,"GetForegroundWindow","user32.dll","GetForegroundWindow"

extern.Declare micLong,"AttachThreadInput","user32.dll","AttachThreadInput",micLong,
micLong,micLong

extern.Declare micLong,"GetWindowThreadProcessId","user32.dll",
"GetWindowThreadProcessId",micLong,micLong

extern.Declare micLong,"GetCurrentThreadId","kernel32.dll","GetCurrentThreadId"

extern.Declare micLong,"GetCursor","user32.dll","GetCursor"

function get_cursor()

               hwnd = extern.GetForegroundWindow()

               pid = extern.GetWindowThreadProcessId(hWnd, NULL)

               thread_id=extern.GetCurrentThreadId()

               extern.AttachThreadInput pid,thread_id,True

               get_cursor=extern.GetCursor()

               extern.AttachThreadInput pid,thread_id,False

end function

Msgbox get_cursor()

QTP Recovery Objects - Associated Properties

Object Identification in QTP Automation testing 
Description

Returns the number of recovery scenarios associated with the current test.

Syntax

Recovery.Count

Return Value

Number

Example

The following example uses the Count property to return the number of recovery scenarios associated with the current test and then uses this information to perform various operations on the scenarios.

msgbox Recovery.Count,, "Number of Recovery Scenarios"

msgbox Recovery,, "Is Recovery enabled?"

for Iter = 1 to Recovery.Count

       Recovery.GetScenarioName Iter, ScenarioFile, ScenarioName

       Position = Recovery.GetScenarioPosition( ScenarioFile, ScenarioName )

       msgbox Recovery.GetScenarioStatus( Position ),, "Is scenario " & _
       ScenarioName & " from " & ScenarioFile & " enabled ?"

       ScenarioFile = Empty

       ScenarioName = Empty

Next

Description

Recovery default property. Retrieves or sets the status of the recovery scenario mechanism for the current test.

Syntax

To retrieve the recovery scenario mechanism status:

Recovery.Enabled

or

Recovery

To set the recovery scenario mechanism status:

Recovery.Enabled =Status

or

Recovery =Status


Argument

Type

Description

Status

Boolean

The status of the specified scenario (True = enabled or False = disabled).

Example

The following example uses the Enabled property to check the status of the recovery mechanism, and enables it if it is disabled. It then activates any recovery scenarios associated with the test, and then returns the recovery mechanism to its former status.

MyCurrentStatus=Recovery.Enabled
If Not( MyCurrentStatus ) Then
Recovery.Enabled=True
End If
Recovery.Activate
Recovery = MyCurrentStatus

Note: You could omit the word Enabled in the statement above, because Enabled is the default property for the Recovery object.

QTP Recovery Objects - Associated Methods

Recovery scenarios handling in QTP and the associated methods in the Automation testing.
Description

Enables you to control the recovery scenario mechanism programmatically during the run session. The recovery scenario mechanism enables you to instruct QuickTest to recover from unexpected events and errors that occur in your testing environment during a run session.

For more information on the recovery scenario mechanism, see the HP QuickTest Professional User Guide.

Associated Methods

  • Activate Method

  • GetScenarioName Method

  • GetScenarioPosition Method

  • GetScenarioStatus Method

  • SetScenarioStatus Method

Associated Properties

  • Count Property

  • Enabled Property
Activate Description

Explicitly activates the recovery scenario mechanism at a specific point in the run.

Note: The Activate method only works if the recovery mechanism is enabled, and only activates those recovery scenarios that are currently enabled.

If the recovery mechanism is currently disabled, the Activate method does not activate any recovery scenarios. You can use the Recovery object's Enabled property to change the status of the recovery mechanism.

Syntax

Recovery.Activate

Example

The following example uses the Activate method to explicitly activate recovery scenarios three times—the first time it explicitly activates the three scenarios associated with the current test; the second time it activates only the first and third scenario, since the second scenario is disabled; the third time it does not activate any scenarios, since the entire recovery mechanism is disabled.

msgbox Recovery.Count,, "Number of Recovery Scenarios"

msgbox Recovery,, "Is Recovery enabled?"

for Iter = 1 to Recovery.Count

       Recovery.GetScenarioName Iter, ScenarioFile, ScenarioName

       Position = Recovery.GetScenarioPosition( ScenarioFile, ScenarioName )

       msgbox Recovery.GetScenarioStatus( Position ),, "Is scenario " & _       ScenarioName & " from " & ScenarioFile & " enabled ?"

       ScenarioFile = Empty

       ScenarioName = Empty

Next

Recovery.Activate

Recovery.SetScenarioStatus 2, False

Recovery.Activate

Recovery = False

Recovery.Activate 

GetScenarioName  Description

Retrieves the name and source file of a recovery scenario, according to the specified position in the list of recovery scenarios associated with the test.

Syntax

Recovery.GetScenarioName Position, out_ScenarioFile, out_ScenarioName


Argument

Type

Description

Position

Number

The index position of the recovery scenario in the list.

Index position values begin with 1.

out_ScenarioFile

String

Variable that stores the retrieved name of the recovery scenario.

out_ScenarioName

String

Variable that stores the retrieved source file path of the recovery scenario.

Example

The following example uses the GetScenarioName method to retrieve the name of each of the recovery scenarios associated with the current test, and then displays the name in a message box.

msgbox Recovery.Count,, "Number of Recovery Scenarios"

msgbox Recovery,, "Is Recovery enabled?"

for Iter = 1 to Recovery.Count

       Recovery.GetScenarioName Iter, ScenarioFile, ScenarioName

       Position = Recovery.GetScenarioPosition( ScenarioFile, ScenarioName )

       msgbox Recovery.GetScenarioStatus( Position ),, "Is scenario " & _
       ScenarioName & " from " & ScenarioFile & " enabled ?"

Next

GetScenarioPosition  Description

Returns the index position of a recovery scenario in the list of recovery scenarios associated with the test, according to the specified name and source file.

Syntax

Recovery.GetScenarioPosition (ScenarioFile, ScenarioName)


Argument

Type

Description

ScenarioFile

String

The source file path of the recovery scenario.

ScenarioName

String

The name of the recovery scenario.

Return Value

Number

Example

The following example uses the GetScenarioPosition method to retrieve the index position of each of the recovery scenarios associated with the current test, and then displays the index position in a message box.

msgbox Recovery.Count,, "Number of Recovery Scenarios"

msgbox Recovery,, "Is Recovery enabled?"

for Iter = 1 to Recovery.Count

       Recovery.GetScenarioName Iter, ScenarioFile, ScenarioName

       Position = Recovery.GetScenarioPosition( ScenarioFile, ScenarioName )

       msgbox Recovery.GetScenarioStatus( Position ),, "Is scenario " &_
       ScenarioName & " from " & ScenarioFile & " enabled ?"

Next

GetScenarioStatus Description

Returns the status of a recovery scenario (True = enabled or False = disabled), according to the specified index position in the list of recovery scenarios associated with the test.

Syntax

Recovery.GetScenarioStatus Position


Argument

Type

Description

Position

Number

The index position of the recovery scenario in the list.

Index position values begin with 1.

Return Value

Boolean

Example

The following example uses the GetScenarioStatus method to retrieve the status (True = enabled or False = disabled) of each of the recovery scenarios associated with the current test, and then displays the status in a message box.

msgbox Recovery.Count,, "Number of Recovery Scenarios"

msgbox Recovery,, "Is Recovery enabled?"

for Iter = 1 to Recovery.Count

       Recovery.GetScenarioName Iter, ScenarioFile, ScenarioName

       Position = Recovery.GetScenarioPosition( ScenarioFile, ScenarioName )

       msgbox Recovery.GetScenarioStatus( Position ),, "Is scenario " & _
       ScenarioName & " from " & ScenarioFile & " enabled ?"

       ScenarioFile = Empty

       ScenarioName = Empty

Next

SetScenarioStatus Description

Enables or disables the specified recovery scenario, according to its index position in the list of recovery scenarios associated with the test.

Syntax

Recovery.SetScenarioStatus Position, Status


Argument

Type

Description

Position

Number

The index position of the recovery scenario in the list.

Index position values begin with 1.

Status

Boolean

The status to set for the specified scenario (True = enabled or False = disabled).

Example

The following example uses the SetScenarioStatus method to disable the status of the second scenario associated with the test.

msgbox Recovery.Count,, "Number of Recovery Scenarios"

msgbox Recovery,, "Is Recovery enabled?"

for Iter = 1 to Recovery.Count

       Recovery.GetScenarioName Iter, ScenarioFile, ScenarioName

       Position = Recovery.GetScenarioPosition( ScenarioFile, ScenarioName )

       msgbox Recovery.GetScenarioStatus( Position ),, "Is scenario " & _
       ScenarioName & " from " & ScenarioFile & " enabled ?"

       ScenarioFile = Empty

       ScenarioName = Empty

Next

Recovery.Activate

Recovery.SetScenarioStatus 2, False

Recovery.Activate