The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:




Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> Micro Focus/Borland/Segue SilkTest

Pages: 1 | 2 | 3 | >> (show all)
rick_weth
Member


Reged: 09/02/99
Posts: 335
Loc: San Jose,CA,USA
Re: Donate a user defined function to this topic [Re: chinna_you]
      #338647 - 11/01/06 03:13 PM

Good topic:

Code:

[+] boolean ListContains (list of string tlist, string patt)
[ ] boolean ret_val = false
[ ] string thing
[+] for each thing in tlist
[+] if MatchStr(patt,thing)
[ ] ret_val = true
[ ] break
[ ]
[ ] return ret_val
[ ]
[ ]
[+] list of string SplitString(string target,string splitstr)
[ ] // makes up for Segues increadible lack of fore sight
[ ] string frag_ment = null
[ ] string sub_frag = null
[ ] boolean target_empty = FALSE
[ ] List Of String ret_list = {}
[ ] integer frag_pos = 0
[ ] integer ss_len = Len(splitstr)
[ ] integer nop = 0
[ ]
[ ] frag_ment = target
[+] while (! target_empty)
[ ] frag_pos = StrPos(splitstr,frag_ment)
[+] if frag_pos == 0
[ ] target_empty = TRUE
[+] if Len(frag_ment) > 0
[ ] ListAppend(ret_list,frag_ment)
[ ] continue
[+] else
[ ] sub_frag = SubStr(frag_ment,1,frag_pos - 1)
[ ] ListAppend(ret_list,sub_frag)
[ ] frag_ment = SubStr(frag_ment,frag_pos + ss_len)
[ ]
[+] if Len(frag_ment) > 0
[ ] nop++
[+] else
[ ] target_empty = TRUE
[ ]
[ ] return ret_list
[ ]
[+] list of int Range(int beg,int end optional)
[ ] list of int ret_lst = {}
[ ]
[+] if end == null
[ ] end = beg
[ ] beg = 1
[+] if beg == null
[ ] beg = 1
[ ]
[ ] int i
[+] for(i=beg;i<=end;i++)
[ ] ListAppend (ret_lst, i)
[ ]
[ ]
[ ] return ret_lst



--------------------
Smoke me a kipper, I'll be back for breakfast!
Sincerely
Richard Weth
Sr. QA Engineer


Post Extras: Print Post   Remind Me!   Notify Moderator  
spaceraider
Member


Reged: 09/27/02
Posts: 113
Loc: ONDlodnol
Re: Donate a user defined function to this topic [Re: chinna_you]
      #370889 - 04/04/07 10:29 AM

Here is a function that converts the Data&Time for a OLE object.

Code:
  
[-] private Match_DateTime()//compares date/time values from OLE fields
[ ] string sYear
[ ] string sMonth
[ ] string sDay
[ ] string sHour
[ ] string sMinute
[ ] string sAMPM
[ ] string sNum
[ ] datetime dtEnd
[ ] datetime dtStart
[ ] integer iMonth
[ ] integer iYear
[ ] integer iDay
[ ] integer iHour
[ ] integer iMinute
//Get the Time and Date from the Commint D/T field
[ ] iMonth = CMiscReport.SSScrollBase.FrameB1.OLEDTPicker("Commt D?T").iMonth//get the value of field in integer
[ ] sNum = Str (iMonth)//convert to string
[ ] MatchStr(sNum, sMonth)//match the 2 strings
[-] if sNum == sMonth//test comparing the 2 values
[ ] iYear = CMiscReport.SSScrollBase.FrameB1.OLEDTPicker("Commt D?T").iYear//get the value of field in integer
[ ] sNum = Str (iYear)//convert to string
[ ] MatchStr(sNum, sYear)//match the 2 strings
[-] if sNum == sYear//test comparing the 2 values
[ ] iDay = CMiscReport.SSScrollBase.FrameB1.OLEDTPicker("Commt D?T").iDay//get the value of field in integer
[ ] sNum = Str (iDay)//convert to string
[ ] MatchStr(sNum, sDay)//match the 2 strings
[-] if sNum == sDay//test comparing the 2 values
[ ] iHour = CMiscReport.SSScrollBase.FrameB1.OLEDTPicker("Commt D?T").iHour//get the value of field in integer
[ ] sNum = Str (iHour)//convert to string
[ ] MatchStr(sNum, sHour)//match the 2 strings
[-] if sNum == sHour//test comparing the 2 values
[ ] iMinute = CMiscReport.SSScrollBase.FrameB1.OLEDTPicker("Commt D?T").iMinute//get the value of field in integer
[ ] sNum = Str (iMinute)//convert to string
[ ] MatchStr(sNum, sMinute)//match the 2 strings
[-] if sNum == sMinute//test comparing the 2 values
[ ] sNum = Str(iMinute)//convert to string
[ ] MatchStr(sNum, sMinute)//match the 2 strings
//Formats the system time and date
[ ] dtStart = GetDateTime ()
[ ] sYear = FormatDateTime (dtStart, "yyyy")//year
[ ] sMonth = FormatDateTime (dtStart, "m")//month
[ ] sDay = FormatDateTime(dtStart, "dd") //day
[ ] sHour = FormatDateTime (dtStart, "hh")//hour
[ ] sMinute = FormatDateTime (dtStart, "nn")//minute
[ ] sAMPM = FormatDateTime (dtStart, "AM/PM")//time mode
[ ] dtEnd = "{sMonth}/{sDay}/{sYear} {sHour}:{sMinute}: {sAMPM}"//bring formatting togther
//compare and matches the time and date from commint D/T field
[ ] MatchStr(sNum, sYear)
[-] if sNum == sYear
[ ] print ("The Year field match")
[-] else
[ ] // val
[ ] LogError("The Year field doesn't match")
[ ] MatchStr(sNum, sMonth )
[-] if sNum == sMonth
[ ] print("The Month field match")
[-] else
[ ] LogError("The Month field doesn't match")
[ ] MatchStr(sNum, sDay )
[-] if sNum == sDay
[ ] print("The Day field match")
[-] else
[ ] LogError("The Day field doesn't match")
[ ] MatchStr(sNum, sHour )
[-] if sNum == sHour
[ ] print("The Hour field match")
[-] else
[ ] LogError("The Hour field doesn't match")
[ ] MatchStr(sNum, sMinute )
[-] if sNum == sMinute
[ ] print("The Minute field match")
[-] else
[ ] LogError("The Minute field doesn't match")
[ ]
[ ]
[ ] //***********************************************************************/




--------------------
Goodness is a part of life just like the Devil

Edited by spaceraider (04/04/07 10:55 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
bhanukiran
Newbie


Reged: 03/05/07
Posts: 7
Re: Donate a user defined function to this topic [Re: TonyM]
      #374873 - 04/22/07 03:47 AM

Hi Tony Thanks for provding very useful method, i used above user defined method(to get max input allowed in a textbox) but i am getting 'DLL can't be loaded -Error 193
error in test report.
I am using Browser:IE 6.0 DOM, SP2,OS: Windows XP, Tool:SilkTest 6.5.
I chaged HtmalTextField inplace of TestField class as i am using it in webapplication testing.

Can you please guide me why i am getting above problem, do I need to change anything in my script or any changes in tool or browser settings.

-Thanks
Bhanu


Post Extras: Print Post   Remind Me!   Notify Moderator  
bhanukiran
Newbie


Reged: 03/05/07
Posts: 7
Re: Donate a user defined function to this topic [Re: TonyM]
      #375003 - 04/23/07 03:59 AM

Hi Tony thanks for providing very useful method, i used above user defind method(to get max input allowed in a textbox) but i am gettubg 'DLL can't be loaded-Error 193'
I am using Browser: IE 6 DOM,SP2, Openration system: WindowsXp SilkTest 6.5

I changed HTMLTextFiled inplace of TextField class as i am using a webapllication for testing.

Can you please guide me why i am getting above problem, do i need to change anything in my script or any changes in tool or broser settings .

Thanks
Bhanu


Post Extras: Print Post   Remind Me!   Notify Moderator  
April_20
Junior Member


Reged: 02/24/06
Posts: 195
Loc: Princeton, NJ
Re: Donate a user defined function to this topic [Re: bhanukiran]
      #377632 - 05/02/07 01:23 PM

GetMaxInput() method would only work on TextField class. To work with HtmlTextField use GetMaxLength() method from the class below:

Code:
 
use "msw32.inc"

[-] public winclass TextField: TextField
[ ] //*********************************************************************
[ ] // This class extends standard TextField class.
[ ] //*********************************************************************
[ ]
[-] hidecalls INT GetMaxLength()// Returns max length of HtmlTextField:
[ ] //the max number of characters stored in it.
[ ] //***** Warning: this method should only be used on HtmlTextField
[ ] //class only. Extending HtmlTextField class causes compilation error.
[ ] return Val(this.ExecMethod('getAttribute("maxlength")'))
[-] hidecalls LONG GetMaxInput()// Returns max length of standard TextField:
[ ] integer hTxt
[ ] long lMaxLngth
[ ]
[ ] hTxt = this.GetHandle()
[ ] lMaxLngth = SendMessage(hTxt,213,0,0)
[ ] return lMaxLngth




Post Extras: Print Post   Remind Me!   Notify Moderator  
manoj3
Junior Member


Reged: 06/24/02
Posts: 8
Loc: Bay Area, CA
Re: Donate a user defined function to this topic [Re: chinna_you]
      #417984 - 09/20/07 04:04 PM

Here is a simple function to Verify the Credit Card type with the number intered in the CC field.
Code:

[ ] // **** Function to Get the CC Type ***** //
[ ] // Parameters
[ ] // sCCNumber ------------> Credit Card Number
[ ] // Returns the CCType based on the First Number
[ ] // **** ***** //
[+] STRING GetCCType (STRING sCCNumber)
[ ] STRING sFirstNum = SubStr(sCCNumber,1,1)
[ ] print(SubStr(sCCNumber,1,1))
[+] switch(Val(sFirstNum))
[+] case(3)
[ ] print("American Express")
[ ] return "American Express"
[+] case(4)
[ ] print("VISA")
[ ] return "VISA"
[+] case(5)
[ ] print("Mastercard")
[ ] return "Mastercard"
[+] case(6)
[ ] print("Discover")
[ ] return "Discover"
[+] default
[ ] LogError ("Type for the Credit Card with CC Number {sCCNumber} is not Automated")
[ ] return NULL
[ ]
[ ]
[ ]



Edited by jamesso (10/19/07 01:21 PM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
dimaj
Active Member


Reged: 05/05/05
Posts: 828
Loc: Fremont, CA
Re: Donate a user defined function to this topic [Re: manoj3]
      #420851 - 10/02/07 09:37 AM Attachment (431 downloads)

Hello All!

Here's an API that I have compiled to use SilkTest with ABBYY ScreenShot Reader.

NOTE: API is in the attached to the message (ABBYY_ScreenShot_Reader.zip)

Hope this is useful.

dimaj

Edited by dimaj (10/02/07 09:38 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
dimaj
Active Member


Reged: 05/05/05
Posts: 828
Loc: Fremont, CA
Re: Donate a user defined function to this topic [Re: dimaj]
      #426806 - 10/23/07 05:56 PM

Here's a function that I wrote to disable any Device class (i.e. "mouse"). It talks to DevCon.exe. DevCon.exe is an application developed by Microsoft as a command line alternative to "Device Manager" for Windows.

This function was written for 1 reason: disable mouse devices during testcase execution. Sometimes you can accidentally touch your mouse and your entire testcase fails.

NOTE: Please use this at your own risk. There might be a possibility that enable/disable will fail and you will have to manually enable those devices using actual device manager or reboot your machine.

Here's my code:
Code:

[+] // Function Description
[ ] // This function is going to disable / enable a hardware device installed on your computer
[+] // Input parameters
[ ] // STRING sDeviceClass = Class of a device as showd in the DeviceManager (i.e. Mouse)
[ ] // BOOLEAN bEnable = if TRUE device will be enabled, otherwise it will be disabled
[ ] // STRING sDevConPath = Path to DevCon application
[+] // Example of usage
[ ] // to enable, do this HardwareManipulation ("Mouse", TRUE, "C:\Tools\DevCon\i386\DevCon.exe")
[ ] // to disable, do this HardwareManipulation ("Mouse", FALSE, "C:\Tools\DevCon\i386\DevCon.exe")
[-] Void EnableDisableHardware (STRING sDeviceClass, BOOLEAN bEnable, STRING sDevConPath)
[ ] // local variables
[ ] LIST OF STRING lsRetVal
[ ] STRING sCommand
[ ]
[ ] // check if path exists
[+] if (!SYS_FileExists (sDevConPath))
[ ] raise 1, "File '{sDevConPath}' does not exist!"
[ ]
[ ] // generate a commnad line to execute to get list of all devices under a device class
[+] if (bEnable)
[ ] sCommand = '"{sDevConPath}" enable ={sDeviceClass}'
[+] else
[ ] sCommand = '"{sDevConPath}" disable ={sDeviceClass}'
[ ]
[ ] // check if program exuted correctly
[+] if (iProgramExitCode != 0)
[+] switch (iProgramExitCode)
[+] case 1
[ ] raise 1, "Computer restart is required to complete this action"
[+] case 2
[ ] raise 1, "Couldn't complete requested action"
[+] case 3
[ ] raise 1, "There was an error while executing application"


[-] testcase TestEnableDisableHardware () appstate none
[ ] HardwareManipulation ("Mouse", FALSE, "C:\tools\DevCon\i386\DevCon.exe")
[ ] sleep (10)
[ ] HardwareManipulation ("Mouse", TRUE, "C:\tools\DevCon\i386\DevCon.exe")



dimaj


Post Extras: Print Post   Remind Me!   Notify Moderator  
dimaj
Active Member


Reged: 05/05/05
Posts: 828
Loc: Fremont, CA
Re: Donate a user defined function to this topic [Re: dimaj]
      #427063 - 10/24/07 07:59 AM

Sorry guys,

I forgot to include the SYS_Execute (sCommand, lsRetVal) right before the if (iProgrameExitCode)

dimaj


Post Extras: Print Post   Remind Me!   Notify Moderator  
solutionprovider
Junior Member


Reged: 03/28/01
Posts: 34
Loc: USA
Re: Donate a user defined function to this topic [Re: chinna_you]
      #436876 - 11/28/07 07:16 AM

Restart a Computer using VBS

http://searchcode.tm-sol.com/codeid.php?Code_ID_Code=114&dowhattodo=

reading a config file to be used in QTP which can be loaded as Env variables

http://searchcode.tm-sol.com/codeid.php?Code_ID_Code=127&dowhattodo=

--------------------
Cheers,
Solution Provider

http://searchcode.tm-sol.com
Post and find code for quite a lot of problems.


Post Extras: Print Post   Remind Me!   Notify Moderator  
hemangihere
Junior Member


Reged: 06/09/05
Posts: 37
Loc: Bangalore
Re: Donate a user defined function to this topic [Re: chinna_you]
      #444428 - 12/28/07 02:41 AM

Hi Friends I would like to share the code to get the recursive children for a window.
(wWin.GetChildren()-Gives the Children of only 1 Hierarchy level)
Code:

[+] type CHILD is record
[+] //@HELP
[ ] //==================================
[ ] // Data Type name : CHILD
[ ] // Purpose : To get the all components of a window
[ ] // Input : Null
[ ] // Output : Null
[ ] // Created on : 12th Dec 07
[ ] // Updated on :
[ ] //Created By : Hemangi
[ ] //==================================
[ ] LIST OF WINDOW lwWin
[ ] DATACLASS dcClass
[ ] STRING sCaption
[ ] LIST OF STRING lsChildCaption
[ ] INT Count
[ ]
[-] CHILD GetChild(WINDOW wName)
[+] //@HELP
[ ] //==================================
[ ] // Function name : GetChild
[ ] // Purpose : To get the all Child components of the input window
[ ] // Input : window name
[ ] // Output : 1) List of child objects for this window 2) Count of the objects
[ ] // Created on : 12th Dec 07
[ ] // Updated on :
[ ] //Created By : Hemangi
[ ] //==================================
[ ] CHILD chC
[ ] LIST OF WINDOW lwWin
[ ] chC.lwWin = wName.GetChildren()
[ ] chC.Count =ListCount(chC.lwWin)
[ ] return chC
[ ]
[+] LIST OF WINDOW GetRecursiveChildren(WINDOW wx)
[+] //@HELP
[ ] //==================================
[ ] // Function name : GetRecursiveChildren
[ ] // Purpose : To get the all Child components of the input window recursively(all the objects within objects)
[ ] // Input : window name
[ ] // Output : all child components of all the window objects
[ ] // Created on : 12th Dec 07
[ ] // Updated on :
[ ] //Created By : Hemangi
[ ] //==================================
[ ] ARRAY [1000] OF CHILD aC1
[ ] List of window lwWin1,lwWin2
[ ] iCnt=1
[ ] aC1[iCnt] = GetChild( wx)
[ ] lwWin1 = aC1[iCnt].lwWin
[ ] window wWin
[-] if ListCount(lwWin1) !=0
[-] for each wWin in lwWin1
[ ] //Print(lwWin1)
[ ] ListAppend (lwWin2,wWin)
[ ] //Print(lwWin2)
[-] if ListCount(lwWin2) != 0
[ ] ListMerge(lwWin,lwWin2)
[-] if aC1[iCnt].Count !=0
[ ] iCnt++
[-] for each wWin in aC1[iCnt-1].lwWin
[ ] GetRecursiveChildren (wWin)
[ ] return lwWin
[ ]
[-] testcase GetRecChildrenTC() appstate none
[ ] MainWin_GMO.SetActive()
[ ] Browser.Maximize()
[ ] Print( GetRecursiveChildren(MainWin_GMO))
[ ]



--------------------
Thanks & Regards,
-Hemangi

Edited by jamesso (11/19/08 07:29 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
PixelJunction
Member


Reged: 12/14/07
Posts: 110
Loc: Boston, MA - USA
Re: Donate a user defined function to this topic [Re: Bapanna Setti]
      #444969 - 01/02/08 04:58 AM

Here are a couple simple functions I use a lot in my automation to make the experience as random as possible:
Code:

// ANYTYPE Functions
[-] ANYTYPE ReturnRandomSingle(LIST OF ANYTYPE laPassedIn)
[ ] return laPassedIn[RandInt(1,ListCount(laPassedIn))]
[ ]
[ ] // LIST OF ANYTYPE Functions
[-] LIST OF ANYTYPE ReturnRandomList(INTEGER iCount, LIST OF ANYTYPE laPassedIn)
[ ] LIST OF ANYTYPE laRandomItems
[ ] INTEGER iLoop
[ ]
[-] for iLoop = 1 to iCount
[ ] ListAppend(laRandomItems, ReturnRandomSingle(laPassedIn))
[ ]
[ ] return laRandomItems

And since our code uses records (pulled from XLS files) for a large portion of the verification, a function to compare two records:

[-] VOID Compare2Records(ANYTYPE aRecord1, ANYTYPE aRecord2, LIST OF STRING lsFieldsIgnore)
[ ] STRING sField
[ ]
[ ] // Make sure both records are the same type.
[-] if(TypeOf(aRecord1) != TypeOf(aRecord2))
[ ] LogError("*** Type of aRecord1: {TypeOf(aRecord1)} is not equal to the type of aRecord2: {TypeOf(aRecord2)} ***")
[ ]
[ ] // Pull all the record values to be compared.
[ ] LIST OF STRING lsRecordFields = FieldsOfRecord(TypeOf(aRecord1))
[ ]
[ ] // Loop through to compare each value in the records.
[-] for each sField in lsRecordFields
[ ]
[ ] // If the current field is contained in lsFieldsIgnore, skip to next one.
[-] if(ListFind(lsFieldsIgnore,sField))
[ ] continue
[ ]
[ ] Print("Comparing: {aRecord1.@(sField)} with {aRecord2.@(sField)}")
[ ]
[ ] // Compare the current field from the record.
[-] if(aRecord1.@(sField) != [Email]aRecord2.@(sField))[/Email]
[ ] LogError("*** Error: Records values not equal --> {aRecord1.@(sField)}, {aRecord2.@(sField)} ***")



--------------------
Co-Founder
Pixel Junction - Websites Done Right!
www.mypixeljunction.com

Edited by jamesso (11/19/08 07:36 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
smahmed
Junior Member


Reged: 11/21/04
Posts: 18
Loc: India
Re: Donate a user defined function to this topic [Re: PixelJunction]
      #456757 - 02/10/08 11:59 PM

Here is the function which reads the Directory frecursively and write the result to Out Put file.
Code:

[+] void Dir_Contents (String dirname,String sOutFileName)
[ ]
[ ] List of FILEINFO LfiFolderContents
[ ]
[ ]
[ ] INTEGER iCount
[ ] // print (dirname)
[ ] SYS_SetDir (dirname)
[ ] LfiFolderContents = SYS_GetDirContents (dirname)
[ ]
[-] for iCount = 1 to ListCount (LfiFolderContents)
[-] if !(LfiFolderContents[iCount].bIsDir )
[ ] Listappend (GlsFoldervalues,"{dirname}"+"\"+"{LfiFolderContents[iCount].sName}" )
[-] else
[ ] // print ("{dirname}"+"\"+"{LlsFolderContents[iCount].sName}")
[ ] Listappend (GlsFoldervalues,"{dirname}"+"\"+"{LfiFolderContents[iCount].sName}" )
[ ] Dir_Contents ("{dirname}"+"\"+"{LfiFolderContents[iCount].sName}")
[ ]
[ ] ListWrite (GlsFoldervalues,"{sOutFileName}")



thanks
Syed

Edited by jamesso (11/19/08 07:35 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
tmpalaniselvam
Veteran


Reged: 09/18/01
Posts: 2511
Loc: Bangalore,India
Re: Donate a user defined function to this topic [Re: smahmed]
      #457559 - 02/13/08 01:30 AM

This function is useful, if user tries to get all children of particular CLASS object. I have used recursive technique here.
I have put few code snippets here Silktest tips

Code:


[-] public LIST OF WINDOW GetChildObjects(Window wContainer, DATACLASS dcObject)
[ ] // To get All child objects.
[ ] // Used recursive method.
[ ] LIST OF WINDOW lwndObjects, lwTemp1, lwTemp2
[ ] LIST OF WINDOW lwndChildren = {...}
[ ] WINDOW wParent, wChild, wTemp
[ ]
[-] do
[-] if (wContainer.Exists (10))
[ ] lwndChildren = wContainer.GetChildren (TRUE, FALSE)
[ ]
[-] for each wChild in lwndChildren
[-] if wChild.IsOfClass(dcObject)
[ ] ListAppend (lwndObjects,wChild)
[-] else
[ ] lwTemp1 = wChild.GetChildren(TRUE, FALSE)
[-] if (ListCount(lwTemp1) > 1)
[ ] lwTemp2 = GetChildObjects(wChild,dcObject) //To get particular objects
[-] if (ListCount(lwTemp2) > 0)
[ ] ListMerge (lwndObjects, lwTemp2)
[-] else
[ ] Print ("Container {[STRING]wContainer} window is not available.")
[+] except
[ ] ExceptLog ()
[ ]
[ ] return lwndChildren




--------------------
Thanks & Regards,
Palani.
http://tips-testing.blogspot.com/index.html
Quote: Dont hesitate to initiate!

Edited by tmpalaniselvam (02/13/08 01:33 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
dimaj
Active Member


Reged: 05/05/05
Posts: 828
Loc: Fremont, CA
Re: Donate a user defined function to this topic [Re: tmpalaniselvam]
      #458943 - 02/18/08 09:41 AM

Here's a function to check current CPU usage of a computer.

Code:

[-] dll "Kernel32.dll"
[ ] long GetSystemTimes(out long lpIdleTime, out long lpKernelTime, out long lpUserTime)

[+] // Function Description
[ ] // This function is going to loop until CPU usage drops to a desired %
[ ]
[+] // INPUT PARAMETERS
[ ] // LONG - value of CPU usage at which loop gets terminated
[ ] // BOOLEAN - Output readings into result file
[+] // RETURN
[ ] // VOID
[+] // EXAMPLE
[ ] // WaitForCPU (20, TRUE)
[ ] // WaitForCPU (20, FALSE)
[+] void WaitForCPU (long lCPUThreshold, boolean bPrintReading optional)
[ ] // initialize bPrintReading if it hasn't been passed in
[+] if (bPrintReading == null)
[ ] bPrintReading = false
[ ]
[ ] // open a list for CPU reading results
[+] if (bPrintReading)
[ ] ResOpenList ("Processor Times")
[ ]
[ ] // local vars
[ ] long lCurIdleReading, lCurKernelReading, lCurUserReading
[ ] long lPrevIdleReading, lPrevKernelReading, lPrevUserReading
[ ] long lIdle, lKernel, lUser, lSys, lCPULoad
[ ]
[ ] // get system times
[ ] GetSystemTimes (lCurIdleReading, lCurKernelReading, lCurUserReading)
[ ] lPrevIdleReading = lCurIdleReading
[ ] lPrevKernelReading = lCurKernelReading
[ ] lPrevUserReading = lCurUserReading
[ ]
[ ] // get system time
[ ] lSys = lCurUserReading + lCurKernelReading
[ ]
[ ] // get CPU load time
[+] if (lSys == 0)
[ ] lCPULoad = 0
[+] else
[ ] lCPULoad = ((lSys - lCurIdleReading) * 100) / lSys
[ ]
[+] if (bPrintReading)
[ ] print ("{lCPULoad}")
[ ]
[ ] // loop until desired value is not reached
[+] while ((lCPULoad > lCPUThreshold) || (lCPULoad == 0))
[ ] sleep (1)
[ ] // get system times
[ ] GetSystemTimes (lCurIdleReading, lCurKernelReading, lCurUserReading)
[ ]
[ ] // assign current times to the last times
[ ] lIdle = lCurIdleReading - lPrevIdleReading
[ ] lKernel = lCurKernelReading - lPrevKernelReading
[ ] lUser = lCurUserReading - lPrevUserReading
[ ]
[ ] lPrevIdleReading = lCurIdleReading
[ ] lPrevKernelReading = lCurKernelReading
[ ] lPrevUserReading = lCurUserReading
[ ]
[ ] lSys = lUser + lKernel
[ ]
[+] if (lSys == 0)
[ ] lCPULoad = 0
[-] else
[ ] lCPULoad = ((lSys - lIdle) * 100) / lSys
[ ]
[+] if (bPrintReading)
[ ] print ("{lCPULoad}")
[ ]
[ ]
[ ] // close list of CPU Readings
[+] if (bPrintReading)
[ ] ResCloseList ()



dimaj


Post Extras: Print Post   Remind Me!   Notify Moderator  
Bond1984
Newbie


Reged: 12/10/06
Posts: 24
Re: Donate a user defined function to this topic [Re: dimaj]
      #463093 - 03/03/08 11:51 AM

Code:

// returns the extension from a filepath string
[+] STRING GetFileExtension (STRING s)
[ ] INTEGER iLen = Len(s)
[ ] INTEGER iDot = 0
[ ] INTEGER j
[ ] STRING sExt = NULL
[-] for j = 0 to iLen-1
[ ] INTEGER iPos = iLen-j
[ ] STRING sChar = SubStr (s, iPos, 1)
[-] if sChar == "."
[ ] iDot = iPos
[ ] break
[-] if iDot > 0
[ ] sExt = SubStr (s, iDot+1, iLen-iDot)
[ ] return sExt



--------------------
~AK

Edited by jamesso (11/19/08 07:30 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
PiseAmol
Member


Reged: 07/09/07
Posts: 33
Re: Donate a user defined function to this topic [Re: Bond1984]
      #468387 - 03/19/08 11:56 PM

During the execution of test script, if your application is scrolling either upward or downward abnormally then try the following line of code...

Agent.SetOption (OPT_SCROLL_INTO_VIEW, False)

Thanks,
Amol Pise.


Post Extras: Print Post   Remind Me!   Notify Moderator  
April_20
Junior Member


Reged: 02/24/06
Posts: 195
Loc: Princeton, NJ
Re: Donate a user defined function to this topic [Re: Chris Mead]
      #473922 - 04/09/08 10:51 AM

Quote:

Here is the International/2006 version of the DLL and the corresponding declaration. My MUT posting above also requires that you change ShellExecuteA to ShellExecuteW with International/2006.

http://www.mobie.us/code/qaUtilsW.zip

Code:

dll "qaUtilsW.dll"
LONG GetRunningProcessesW(inout ARRAY OF CHAR longString, inout LONG bufferNeed, LONG onlyGetBufferSize)





Small correction:
function declaration should read:
Code:
  
Code:

dll "qaUtilsW.dll"
LONG GetRunningProcesses(inout ARRAY OF CHAR longString, inout LONG bufferNeed, LONG onlyGetBufferSize)


without W at the end.


Post Extras: Print Post   Remind Me!   Notify Moderator  
KrisrisK
Member


Reged: 04/21/08
Posts: 340
Loc: Hyderabad
Re: Donate a user defined function to this topic [Re: chinna_you]
      #490235 - 06/10/08 03:28 AM

Code:

[ ] //******************************************************
[ ] // Function NumberInWords() - converts a number in to words and returns that string
[ ] //******************************************************
[ ]
[+] STRING NumberInWords(INTEGER iNumber)
[ ]
[ ] STRING sNumber = Str(iNumber)
[ ] STRING sNumberString = ""
[ ] INTEGER iLength = Len(sNumber)
[ ] STRING sOnes = ""
[ ] STRING sTens = ""
[ ] STRING sHundreds = ""
[ ] STRING sThousands = ""
[ ]
[-] switch(iLength)
[ ] // for single digit numbers
[+] case 1
[ ] sOnes = sNumber
[+] switch(sOnes)
[+] case "1"
[ ] sOnes = "One"
[+] case "2"
[ ] sOnes = "Two"
[+] case "3"
[ ] sOnes = "Three"
[+] case "4"
[ ] sOnes = "Four"
[+] case "5"
[ ] sOnes = "Five"
[+] case "6"
[ ] sOnes = "Six"
[+] case "7"
[ ] sOnes = "Seven"
[+] case "8"
[ ] sOnes = "Eight"
[+] case "9"
[ ] sOnes = "Nine"
[+] case "0"
[ ] sOnes = ""
[ ] sNumberString = sOnes
[ ]
[ ] // for 2 digit numbers
[+] case 2
[ ] sOnes = Right(sNumber,1)
[ ] sTens = Left(sNumber,1)
[+] switch(sOnes)
[+] case "1"
[ ] sOnes = "One"
[+] case "2"
[ ] sOnes = "Two"
[+] case "3"
[ ] sOnes = "Three"
[+] case "4"
[ ] sOnes = "Four"
[+] case "5"
[ ] sOnes = "Five"
[+] case "6"
[ ] sOnes = "Six"
[+] case "7"
[ ] sOnes = "Seven"
[+] case "8"
[ ] sOnes = "Eight"
[+] case "9"
[ ] sOnes = "Nine"
[+] case "0"
[ ] sOnes = ""
[+] switch(sTens)
[+] case "1"
[+] switch(sOnes)
[+] case "One"
[ ] sOnes = ""
[ ] sTens = "Eleven"
[+] case "Two"
[ ] sOnes = ""
[ ] sTens = "Twelve"
[+] case "Three"
[ ] sOnes = ""
[ ] sTens = "Thirteen"
[+] case "Four"
[ ] sOnes = ""
[ ] sTens = "Fourteen"
[+] case "Five"
[ ] sOnes = ""
[ ] sTens = "Fifteen"
[+] case "Six"
[ ] sOnes = ""
[ ] sTens = "Sixteen"
[+] case "Seven"
[ ] sOnes = ""
[ ] sTens = "Seventeen"
[+] case "Eight"
[ ] sOnes = ""
[ ] sTens = "Eighteen"
[+] case "Nine"
[ ] sOnes = ""
[ ] sTens = "Ninteen"
[+] case ""
[ ] sTens = "Ten"
[ ]
[+] case "2"
[ ] sTens = "Twenty"
[+] case "3"
[ ] sTens = "Thirty"
[+] case "4"
[ ] sTens = "Forty"
[+] case "5"
[ ] sTens = "Fifty"
[+] case "6"
[ ] sTens = "Sixty"
[+] case "7"
[ ] sTens = "Seventy"
[+] case "8"
[ ] sTens = "Eighty"
[+] case "9"
[ ] sTens = "Ninty"
[+] case "0"
[ ] sTens = ""
[ ]
[ ]
[ ] sNumberString = sTens +" " + sOnes
[ ]
[ ] // for 3 digit numbers
[+] case 3
[ ] sOnes = Right(sNumber,1)
[ ] sTens = SubStr(sNumber,2,1)
[ ] sHundreds = Left(sNumber,1)
[+] switch(sOnes)
[+] case "1"
[ ] sOnes = "One"
[+] case "2"
[ ] sOnes = "Two"
[+] case "3"
[ ] sOnes = "Three"
[+] case "4"
[ ] sOnes = "Four"
[+] case "5"
[ ] sOnes = "Five"
[+] case "6"
[ ] sOnes = "Six"
[+] case "7"
[ ] sOnes = "Seven"
[+] case "8"
[ ] sOnes = "Eight"
[+] case "9"
[ ] sOnes = "Nine"
[+] case "0"
[ ] sOnes = ""
[ ]
[+] switch(sTens)
[+] case "1"
[+] switch(sOnes)
[+] case "One"
[ ] sOnes = ""
[ ] sTens = "Eleven"
[+] case "Two"
[ ] sOnes = ""
[ ] sTens = "Twelve"
[+] case "Three"
[ ] sOnes = ""
[ ] sTens = "Thirteen"
[+] case "Four"
[ ] sOnes = ""
[ ] sTens = "Fourteen"
[+] case "Five"
[ ] sOnes = ""
[ ] sTens = "Fifteen"
[+] case "Six"
[ ] sOnes = ""
[ ] sTens = "Sixteen"
[+] case "Seven"
[ ] sOnes = ""
[ ] sTens = "Seventeen"
[+] case "Eight"
[ ] sOnes = ""
[ ] sTens = "Eighteen"
[+] case "Nine"
[ ] sOnes = ""
[ ] sTens = "Ninteen"
[+] case ""
[ ] sTens = "Ten"
[ ]
[+] case "2"
[ ] sTens = "Twenty"
[+] case "3"
[ ] sTens = "Thirty"
[+] case "4"
[ ] sTens = "Forty"
[+] case "5"
[ ] sTens = "Fifty"
[+] case "6"
[ ] sTens = "Sixty"
[+] case "7"
[ ] sTens = "Seventy"
[+] case "8"
[ ] sTens = "Eighty"
[+] case "9"
[ ] sTens = "Ninty"
[+] case "0"
[ ] sTens = ""
[ ]
[+] switch(sHundreds)
[+] case "1"
[ ] sHundreds = "One"
[+] case "2"
[ ] sHundreds = "Two"
[+] case "3"
[ ] sHundreds = "Three"
[+] case "4"
[ ] sHundreds = "Four"
[+] case "5"
[ ] sHundreds = "Five"
[+] case "6"
[ ] sHundreds = "Six"
[+] case "7"
[ ] sHundreds = "Seven"
[+] case "8"
[ ] sHundreds = "Eight"
[+] case "9"
[ ] sHundreds = "Nine"
[+] case "0"
[ ] sHundreds = ""
[ ]
[+] if sTens=="" && sOnes==""
[ ] sNumberString = sHundreds + " Hundred "
[+] else
[ ] sNumberString = sHundreds + " Hundred and "+ sTens + " " + sOnes
[ ]
[ ] // for 4 digit numbers
[+] case 4
[ ] sOnes = Right(sNumber,1)
[ ] sTens = SubStr(sNumber,3,1)
[ ] sHundreds = SubStr(sNumber,2,1)
[ ] sThousands = Left(sNumber,1)
[+] switch(sOnes)
[+] case "1"
[ ] sOnes = "One"
[+] case "2"
[ ] sOnes = "Two"
[+] case "3"
[ ] sOnes = "Three"
[+] case "4"
[ ] sOnes = "Four"
[+] case "5"
[ ] sOnes = "Five"
[+] case "6"
[ ] sOnes = "Six"
[+] case "7"
[ ] sOnes = "Seven"
[+] case "8"
[ ] sOnes = "Eight"
[+] case "9"
[ ] sOnes = "Nine"
[+] case "0"
[ ] sOnes = ""
[+] switch(sTens)
[+] case "1"
[+] switch(sOnes)
[+] case "One"
[ ] sOnes = ""
[ ] sTens = "Eleven"
[+] case "Two"
[ ] sOnes = ""
[ ] sTens = "Twelve"
[+] case "Three"
[ ] sOnes = ""
[ ] sTens = "Thirteen"
[+] case "Four"
[ ] sOnes = ""
[ ] sTens = "Fourteen"
[+] case "Five"
[ ] sOnes = ""
[ ] sTens = "Fifteen"
[+] case "Six"
[ ] sOnes = ""
[ ] sTens = "Sixteen"
[+] case "Seven"
[ ] sOnes = ""
[ ] sTens = "Seventeen"
[+] case "Eight"
[ ] sOnes = ""
[ ] sTens = "Eighteen"
[+] case "Nine"
[ ] sOnes = ""
[ ] sTens = "Ninteen"
[+] case ""
[ ] sTens = "Ten"
[ ]
[+] case "2"
[ ] sTens = "Twenty"
[+] case "3"
[ ] sTens = "Thirty"
[+] case "4"
[ ] sTens = "Forty"
[+] case "5"
[ ] sTens = "Fifty"
[+] case "6"
[ ] sTens = "Sixty"
[+] case "7"
[ ] sTens = "Seventy"
[+] case "8"
[ ] sTens = "Eighty"
[+] case "9"
[ ] sTens = "Ninty"
[+] case "0"
[ ] sTens = ""
[ ]
[+] switch(sHundreds)
[+] case "1"
[ ] sHundreds = "One"
[+] case "2"
[ ] sHundreds = "Two"
[+] case "3"
[ ] sHundreds = "Three"
[+] case "4"
[ ] sHundreds = "Four"
[+] case "5"
[ ] sHundreds = "Five"
[+] case "6"
[ ] sHundreds = "Six"
[+] case "7"
[ ] sHundreds = "Seven"
[+] case "8"
[ ] sHundreds = "Eight"
[+] case "9"
[ ] sHundreds = "Nine"
[+] case "0"
[ ] sHundreds = ""
[ ]
[+] switch(sThousands)
[+] case "1"
[ ] sThousands = "One"
[+] case "2"
[ ] sThousands = "Two"
[+] case "3"
[ ] sThousands = "Three"
[+] case "4"
[ ] sThousands = "Four"
[+] case "5"
[ ] sThousands = "Five"
[+] case "6"
[ ] sThousands = "Six"
[+] case "7"
[ ] sThousands = "Seven"
[+] case "8"
[ ] sThousands = "Eight"
[+] case "9"
[ ] sThousands = "Nine"
[+] case "0"
[ ] sThousands = ""
[ ]
[ ]
[+] select
[+] case sTens=="" && sOnes=="" && sHundreds==""
[ ] sNumberString = sThousands + " Thousand "
[+] case sHundreds==""
[ ] sNumberString = sThousands + " Thousand " + sTens + " " + sOnes
[+] case sTens=="" && sOnes==""
[ ] sNumberString = sThousands + " Thousand " + sHundreds + " Hundred "
[+] default
[ ] sNumberString = sThousands + " Thousand " + sHundreds + " Hundred and " + sTens + " " + sOnes
[ ]
[ ]
[ ] // other cases
[-] default
[ ] Print("*** Number length is invalid")
[ ]
[ ]
[ ]
[ ] return sNumberString



--------------------
Regards,
Krishna Chaitanya

=====================
Try and fail, but don't fail to try
=====================

Edited by jamesso (11/19/08 07:33 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
KrisrisK
Member


Reged: 04/21/08
Posts: 340
Loc: Hyderabad
Re: Donate a user defined function to this topic [Re: chinna_you]
      #490237 - 06/10/08 03:33 AM

Code:

******************************************************
RandomSelect()- this method selects an item randomly
and returns the string
Note: can be applied to popup list, radio list etc.
******************************************************
[+] STRING RandomSelect()

[ ] INTEGER iRandSelect
[ ] STRING sSelectedItem
[ ] iRandSelect = RandInt (1,this.GetItemCount())
[ ] sSelectedItem = this.GetItemText(iRandSelect)
[ ] this.Select(sSelectedItem)
[ ] return sSelectedItem



--------------------
Regards,
Krishna Chaitanya

=====================
Try and fail, but don't fail to try
=====================

Edited by jamesso (11/19/08 07:31 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1 | 2 | 3 | >> (show all)



Extra information
0 registered and 11 anonymous users are browsing this forum.

Moderator:  AJ, jamesso, DJGray, David Reed 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating: ****
Topic views: 52668

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5