Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts

Saturday, September 27, 2008

Some improvement for QTP in my project

I'm sorry, this is my brainstorming, not for publishing purpose

The most important idea: (as my experience in developing web crawler, apply artificial interllienge)

-If we use too much properties to identify an object, obviously, we assume that object identify will more accurately. But in some case, if the object in real life, sometime, miss some properties, our application cannot recognize the object (html object is rarely the same all the time). And this process is a result of training object identifier in a 'too large environment' where we have many object, and the application always try the best to unique the object (in test automation is a large set of test case that use the same object repository, and object in repository absolutely has many properties, and cause sometime it cannot recognize the object)
=> increase of number properties to identify object

Another case, if there are too much object has the same properties so to unique the object QTP will reject any duplicated properties, lead to
=> reduce number of properties to identify object. So QTP cannot identify any object (even in small environment)

==>This all is a result of training QTP in a large environment
-1/ too many object, window on the desktop at the time of training
-2/ you train QTP to recognize objects (then store in the same OBJECT REPOSITORY) but you train it many times, each time is of another Application (another test case)


-But, what if we use less properties to identify the object? In the small environment where there are several objects only, it is very easy to unique an object. But when we put the test in to large environment (where there are many test case that open many windows/object) the it will be very hard to unique an object

=> So, we are tester, developer, we understand much, which case will use which type of object. We can leverage dynamic object repository load functionality of QTP to:
1/ For each test case, we know exactly which object we would like to interact, so we can load exactly OR file of that object only. So if we have 2 more objects that similiar in different test cases, but we are testing 1 test case only, we can elimiate 1 remain test case,

2/ For each OR file, we will try to get as much unique properties as possible

Compose two above, we will have a good solution to avoid any duplicated object on the system by elimiate each OR / test case, interact objects/windows in sequence

3/ We need to get investigation, graph to balance, how many properties is good enough for our application to identify? for each test case if possible

1/ Separate our test case into small piece, to limit, and increase object identify performance, increase accurate
2/ Dynamic load object repository for each set of test case


- One more thing, there are some guys around the world, they use programatic to identify object, not relay on Object Repository anymore. That is perfect, so they how to identify their object clearly and to avoid any impact from the change of interface GUI , coding, what if developer, and sudently add some very funny properties into you object?
Ref: http://www.softwareinquisition.com/2006/04/new-object-repository-interface-in-quicktest-pro-9#comment-21844








Below is the detail:


-Dynamic load Object Repository, separate object repository by screen, test case, to increase performace, accurately identify

-In some case, update the object property in object repository to reflect the actually object that known by tester

-Try to understand and have good use of QTP Object properties
Objects Properties:

-Try to understand and have good use of QTP checkpoint functionalities

"
Mandatory Properties: Predefined sets of properties QuickTest learns for each test object.
Assistive Properties: Assistive properties are properties that QuickTest learns only if the mandatory properties are NOT sufficient to create a unique description.
Ordinal Identifier: The Ordinal Identifier assigns the object a numerical value that indicates its order relative to other objects for those have same values for all properties specified in the mandatory and Assistive property lists. This ordered value enables QuickTest to create a unique description when the mandatory and Assistive properties are not sufficient to do so.
SmartTesting @ January 28, 2008
"




"
ISSUE: How to set a property value of an object in the Object Repository during runtime?
Issues, Quick Test Pro, Test Automation

Solution: We can modify the properties of the temporary version of the object during the run session without affecting the permanent values in the object repository by adding a SetTOProperty method. The SetTOProperty method can be inserted from the Keyword view using step generator or inserted to the expert view.

How?

The regular expression checkbox needs to be selected for the specified object .

Either through the Object Repository or through the Object Properties window, the regular expression checkbox needs to be selected before running the test.

To go through the Object Repository:
1. Select Resources -> Object Repository.
2. Select the object that will be used with the SetTOProperty method.
3. Select the property that will be used with the SetTOProperty method.
4. Select the “Edit Constant Value Options” button, which is to the right of the Constant field.
5. Select the “Regular expression” checkbox.
6. Click .
7. Click .

After modifying the setting, you can specify the regular expression using the SetTOProperty method.

Example:
Window(”Notepad”).WinEditor(”Edit”).SetTOProperty “text”, “test.*”
"

QTP: dynamic load object repository

Thanks blogger for this information. I will apply it into my project, current Framework. So for each application/test case, window, it will has its own object repository, to increase accurately object identify, improve QTP performance during recognising object




Repository from the Script
Examples, Quick Test Pro, VB Scripts

Sometime there could be multiple object repositories in a test. It is possible the scripts or reusable actions browse through multiple application, and each apps has separate object repository. One of the problem with QTP8.2, we cannot associate multiple repositories at the same time. Here is a function that switches the repositories from the script.

###############################
‘Purpose: This function switches between desired object repositories
‘Example: Call Switch_ObjRepo(”C:\ObjectRepositories\”, “ApplicationRepGlb.tsr”)
‘###############################
Function Switch_ObjRepo (new_path, ObjRepo_name)
Dim qtApp, qtTestResources, fullpath
Set qtApp = CreateObject(”QuickTest.Application”) ‘ Create the Application object
Set qtTestResources = qtApp.Test.Settings.Resources
fullpath = new_path & ObjRepo_name
qtTestResources.ObjectRepositoryPath = fullpath
Set qtTestResources = Nothing
Set qtApp = Nothing
End Function


--------------------------------------------------------------------------------

QuickTest Pro, Object Repository export problem, recognize object

This should be in my todo list. In the current Framework, we did a lot of GUI interact actions, more than 1200 actions

Sometime, QTP got crash, stuck, cannot recognize object, the version 8.0 is quiet stable, but QTP9.5 is suck, even we submit ticket but didn't get any support from HP

So, what I want to do here is to write myself API for interacting some objects that QTP cannot or not stable enough. To support that goal, I really want to know deep inside how QTP organize objects. This link, post


"4. There is no fast way to export the object repository to plain text
Unlike WinRunner, where the GUI map was just a plain text file, it is not possible to easily export (and manipulate) the object repository. It is possible though, but you'll have to do it through COM automation on the QTP application. I tried it today, but I failed miserably because I could not access the ActiveX object (probably not enough authorization on my workstation).
However, if I get it working, I will post the code on Automated Chaos.
"

http://automated-chaos.blogspot.com/search/label/object%20repository


Little bit same what I need to know. If you have any experience, idea, can you please share with me? Nice to see you around

For doing Excel Dashboard, I had one, but not good enough, and here is now approach

http://automated-chaos.blogspot.com/2008/06/qtp-iban-validation-in-vbscript.html

"June 25, 2008
QTP: IBAN validation in VBScript
IBAN stands for International Bank Account Number and is the old new toy of the banking community. Also hot in Europe because of SEPA. IBAN should make life easier, and maybe it does. For IT guys, IBAN is just another standard. And despite IT guys like standards (that is why they have so many of them), IBAN is a standard designed by the banking people making things a little more complicated.

The things you want to do with IBAN is validate it or just calculate the checksum on your own. The formula for the checksum is not very complex, but has some twists in it. For example, when dealing with Alpha characters, the A is transposed to 10, the B to 11 etc. In the IT world, we would transpose A to 65, B to 66… The things you don't want is validate them exactly right for for every country on this little planet. Maybe they want it, but definitely, you don't. And if they want it, get yourself a new toy called SOAP and connect to it through a service.

After searching the internet, I discovered that code for IBAN validation through any Visual Basic language was rare. I gathered the snippets I found useful and created my own IBAN functions.

How it works is all in the comments in the code, keeping your scripts maintainable and documented if you want to use it:

' This code was created by Bas M. Dam and first published on
' http://automated-chaos.blogspot.com
' You can use and distribute this code freely, as long as you
' keep this commentblock intact.

' RETRIEVING THE CHECKSUM
' There are two methods to get the checksum. The first is the
' one used in automated processes where there is an iban prototype.
' the checksum is replaced by zeros:
' MsgBox getIBANchecksum("LC00BANK1234567890", empty) 'returns 86

' The other way is a more user fiendly appraoch if only the separate
' segments are known like bank code or clearing house:
' MsgBox getIBANchecksum("BANK1234567890", "LC") 'returns 86

' CREATE AN IBAN NUMBER
' This is implemented in the makeIBAN() function for your convenience
' Msgbox makeIBAN("LC", "BANK", empty, "1234567890")
' returns LC86BANK1234567890

' Or just the simple implementation:
' Msgbox makeIBAN("LCBANK1234567890", empty, empty, empty)
' returns LC86BANK1234567890

' CHECK AN IBAN NUMBER
' And finally, you want to check if something is IBAN. You can
' use the getIBANchecksum function for it. If the result is 97,
' then you have a real IBAN, when it returns -1, there is something
' wrong with the IBAN and if it returns another number, the checksum
' is not correct
' Msgbox getIBANchecksum("LC86BANK1234567890", empty) 'returns 97
' Msgbox getIBANchecksum("LC68BANK1234567890", empty) 'returns 18
' Msgbox getIBANchecksum("LC68BANK1234567891", empty) 'returns 88
' Msgbox getIBANchecksum("LC86BANK123456789%", empty) 'returns -1

' To do this the simple way, you can make use of the isIBAN() function
' that simply returns True or False:
' Msgbox isIBAN("LC86BANK1234567890") 'returns True
' Msgbox isIBAN("LC68BANK1234567890") 'returns False
' Msgbox isIBAN("LC86BANK123456789%") 'returns False


' SPECIAL CHARACTERS
' You can use typographical characters as stated in the skipChars string.
' For now, the following characters can be used: space.-_,/
' These characters are often used to make an IBAN more readible, but are
' not taken into the checksum calculation. between the landcode
' and checksum, never a typographical character can be used.
' Msgbox isIBAN("LC86 BANK 1234 5678 90") 'returns True
' Msgbox isIBAN("LC86BANK1234.56.78.90") 'returns True
' Msgbox isIBAN("LC-86-BANK-1234-567890") 'returns False, there can not
'be a separation char between
'landcode and checksum.
' Msgbox isIBAN("LC*86*BANK*1234*567890") 'returns False, * is not a special char

' Function to check on an IBAN
Public Function isIBAN(sIban)

isIBAN = (getIBANchecksum(sIban, empty) = 97)

End Function

' Function to create an IBAN. Any of the arguments can be empty, as
' long as the first not empty argument starts with the landcode
Public function makeIBAN(landcode, bankcode, sortcode, accountnr)

dim realLandcode, sPurged

sPurged = mid(landcode & bankcode & sortcode & accountnr, 3)
realLandcode = left(landcode & bankcode & sortcode & accountnr, 2)

makeIBAN = realLandcode & getIBANchecksum(sPurged, realLandcode) & sPurged

End Function

' Function to get an IBAN checksum. Landcode can be empty, but then, the landcode
' must be included in the first two characters of sIban, followed by two zero's
Public Function getIBANchecksum(sIban, landcode)

Dim sLCCS 'Land Code and Check Sum
Dim sIbanMixed
Dim sIbanDigits
Dim char
Dim i
Dim skipChars
skipChars = " .-_,/"

' Marginal length check
If Len(sIban) < 5 Or Len(sIban) > 35 Then
getIBANchecksum = -1
Exit Function
End If

If landcode = empty Then
sLCCS = Left(sIban, 4) ' Extract land code and check sum
sIbanMixed = Right(sIban, Len(sIban) - 4) & UCase(sLCCS)
else
sLCCS = landcode & "00"
sIbanMixed = sIban & UCase(sLCCS)
End If

For i = 1 To Len(sIbanMixed)
char = Mid(sIbanMixed, i, 1)

'Check on digits
If IsNumeric(char) Then
sIbanDigits = sIbanDigits & char

'Check on typographical characters
elseif instr(skipChars, char) Then
'skip this character, but continue

'Check on non-uppercase other characters
elseif Asc(char) < 65 OR Asc(char) > 90 then
getIBANchecksum = -1
Exit function

'Transform characters to digits
else
sIbanDigits = sIbanDigits & (Asc(char) - 55)
End If
Next

getIBANchecksum = 98 - largeModulus(sIbanDigits, 97)

End Function

' Calculates the modulus of large integers that are actually
' strings. Also usefull for implementation in Excel VBA
' (there is a known bug in Excel and large number modulus)
Private Function largeModulus(sNumber, modulus)
Dim i, sRebuild(), j, r

j = 0
sNumber = cStr(sNumber)

For i = 1 To Len(sNumber) + 6 Step 6
ReDim Preserve sRebuild(j)

sRebuild(j) = Mid(sNumber, i, 6)
j = j + 1
Next

r = sRebuild(0) Mod modulus

For i = 0 To UBound(sRebuild) - 1
r = (r & sRebuild(i + 1)) Mod modulus
Next

largeModulus = r

End Function

The knowledge about the IBAN validation and some code tricks I retrieved from the internet, so it is my turn to to give it back to the community. The functions are also useful in Excel VBA, but not extensively tested. The isIBAN() function is great to use it in your spreadsheet itself, or use it as conditional formatting:
"


I will put this code into Excel file, instead of doing it as manual before. Woa, so many ideas today, too many stuffs need to do, which is good worth for doing?

Digital Inspiration Technology Guide

Change the world with your passion