Search This Blog

Monday, February 11, 2013

Function to return only characters and numbers in any string

This function can be used to return only the characters and numbers in any string. It is useful for string comparison and data comparison. All spaces and other special characters will be removed from the return value.


Public Function ReturnOnlyCharactersandNumbers(myString)
mystr = NULL
sLen = Len(myString)
snewLen = sLen
For i = 1 to sLen
sChar = Left(myString,1)
sASCII= Asc(sChar)
myString = Right(myString,(snewLen-1))
snewLen = Len(myString)
If sASCII >64 and sASCII <91 span="" then="">
mystr = mystr & Chr(sASCII)
Elseif sASCII >96 and sASCII < 123 Then
mystr = mystr & Chr(sASCII)
Elseif IsNumeric(sChar) = True Then
mystr = mystr & sChar
End If
Next
ReturnOnlyCharactersandNumbers = Ucase(mystr)
End Function

Function to return only characters in any string

This function can be used to return only the characters in any string. It is useful for string comparison and data comparison. All spaces and other characters will be removed from the return value.



Public Function ReturnOnlyCharacters (myString)
mystr = NULL
sLen = Len(myString)
snewLen = sLen
For i = 1 to sLen
sChar = Left(myString,1)
sASCII= Asc(sChar)
myString = Right(myString,(snewLen-1))
snewLen = Len(myString)
If sASCII >64 and sASCII <91 p="" then=""> mystr = mystr & Chr(sASCII)
End If
If sASCII >96 and sASCII < 123 Then
mystr = mystr & Chr(sASCII)
End If
Next
ReturnOnlyCharacters = Ucase(mystr)
End Function

Sunday, December 9, 2012

Run QTP when the monitor is off/minimized


Change the following registry settings:-
Step 1: Goto HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest
Step 2: Locate the key “SkipEnvironmentChecks”
step 3: Change the value to “1″ (Default value is 0)
Step 4: Restart the QTP.

Thursday, November 15, 2012

Automating a checkbox in a combo box



val = Dialog(DialogName).WinComboBox(ComboBoxName).GetVisibleText
Num = Dialog(DialogName).WinComboBox(ComboBoxName).GetItemsCount

For i = 0 to Num-1
          selectitem = Dialog(DialogName).WinComboBox(ComboBoxName).GetItem(i)
          Pos = Instr(1, val,selectitem)
          If Pos <> 0 Then
                   On Error Resume Next
                   Dialog(DialogName).WinComboBox(ComboBoxName).Select i
          End If
          val = Dialog(DialogName).WinComboBox(ComboBoxName).GetVisibleText
Next


checkval = "Local"

For i = 1 to 2
          selectitem = Dialog(DialogName).WinComboBox(ComboBoxName).GetItem(i)
          Pos = Instr(1, checkval,selectitem)
          If Pos <> 0 Then
                   On Error Resume Next
                   Dialog(DialogName).WinComboBox(ComboBoxName).Select i
          End If
Next

Monday, May 9, 2011

Run Script - For associating all libraries, repositories and environment variables

Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
App.Launch
App.Visible = True
App.Test.Settings.Launchers("Windows Applications").Active = False
App.Test.Settings.Launchers("Windows Applications").Applications.RemoveAll
App.Test.Settings.Launchers("Windows Applications").RecordOnQTDescendants = True
App.Test.Settings.Launchers("Windows Applications").RecordOnExplorerDescendants = False
App.Test.Settings.Launchers("Windows Applications").RecordOnSpecifiedApplications = True
App.Test.Settings.Run.IterationMode = "rngAll"
App.Test.Settings.Run.StartIteration = 1
App.Test.Settings.Run.EndIteration = 1
App.Test.Settings.Run.ObjectSyncTimeOut = 120000
App.Test.Settings.Run.DisableSmartIdentification = False
App.Test.Settings.Run.OnError = "NextStep"
App.Open "D:\Ranger Automation\Main Script\SmokeTest", False
App.Test.Settings.Resources.DataTablePath = "D:\Ranger Automation\Data Folder\Session Data\SmokeTest.xls"
App.Test.Settings.Resources.Libraries.RemoveAll

App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\Ebeam_MainWindow.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\iAS-Div.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\IAS_FunctionalLayer.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\Review.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\Run_InspectionQueue_FunctionalLayer.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\SetUp.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\SetupRun_ReviewWafer_FunctionalLayer.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\Setup_Button_ValidationStatus.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\SetUp_Run.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\Test_TestSummaryGrid.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\Utilities.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\WaferSetup.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functional Layer\WaferSetup_FunctionalLayer.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\Applic_Path.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\Calling Logger.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\Framework_Functions.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\Job Queue.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\KT-Logger.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\MachineLaunch.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\New_TestCase.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\QTP_Logger.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\Ranger_Recipe.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\Ranger_SubFunction.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\RunJobQueue.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\Utility.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\WPP_Feature.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\WPP_FunctionLayer.vbs")
App.Test.Settings.Resources.Libraries.Add("D:\Ranger Automation\Class\Functions\WPP_Functions.vbs")
App.Test.Settings.Web.BrowserNavigationTimeout = 60000
App.Test.Settings.Web.ActiveScreenAccess.UserName = ""
App.Test.Settings.Web.ActiveScreenAccess.Password = ""

App.Folders.RemoveAll

Dim objRepositoryFolder,repositoryFolder,repositoryFiles,repositoryFile
Set objRepositoryFolder = CreateObject("Scripting.FileSystemObject")
Set repositoryFolder = objRepositoryFolder.GetFolder("D:\Ranger Automation\Object Repository")
Set repositoryFiles = repositoryFolder.Files

App.Test.Actions("Action1").ObjectRepositories.RemoveAll

For Each repositoryFile In repositoryFiles
App.Test.Actions("Action1").ObjectRepositories.Add "D:\Ranger Automation\Object Repository" & "\" & repositoryFile.Name
Next

Call App.Test.Environment.LoadFromFile("D:\Ranger Automation\Class\Environment.xml",true)

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' System Local Monitoring settings
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
App.Test.Settings.LocalSystemMonitor.Enable = false
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Log Tracking settings
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
With App.Test.Settings.LogTracking
.IncludeInResults = False
.Port = 18081
.IP = "127.0.0.1"
.MinTriggerLevel = "ERROR"
.EnableAutoConfig = False
.RecoverConfigAfterRun = False
.ConfigFile = ""
.MinConfigLevel = "WARN"
End With

Tuesday, January 18, 2011

Getting the number of files with same extension in a folder

Flag = 0
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sPath) 'Path of the folder
Set oFile = oFolder.Files
For each sFile in oFile
Pos = Instr(1,sFile.name,".jpeg",1) ' change the extn as required.
If Pos <> 0 Then
Flag =Flag +1
End If
Next
msgbox Flag

Monday, January 3, 2011

Reading data from a virtual table

This post will help you in reading data from a virtual table. This is really helpful and we took a very long time to come up with this solution. It is very simple but that thought process took some time to set in ;). So here we go.

Create the virtual table using the virtual objects manager. The properties available to you would be Width, Height, Rows, Columns, x, y.

Get the height and width of a single cell by dividing the table width and height by the column and row values respectively.

x and y are the values of the top left corner of the first cell, to get the bottom right corner add the height and width calculated for a single cell. Now use the GetVisibleText property with the parent object.

Like,
Say you have a grid or table that is recognized as a winobject, and you create a virtual table for it. Now the code to read the data from the first cell of the table would be:

val = Window(" ").Page(" ").WinObject(" ").GetVisibleText(x,y,x1,y1)
msgbox val