Search This Blog

Saturday, March 24, 2012

Reterive Number from a string.

We will do this test using two examples of script.

Here is example 1.
You have an string "You have sucessfully saved your order and your order no is 110."
Now your task is to get order number out of this string i.e. 110.further more you can use this order number in you other scripts. To achieve this follwing steps need to be followed.

1. var1 = "You have sucessfully saved your order and your order no is 110."
' In order to reterive the order number you have to first  determine length of  the message box.

2. msgbox len(Var1)
' Gives length of the variable.In order to get  110 if you determine positon of  "is" you can easily determine position of 110. But  take care that "is" is not duplicated.

3. MyPos = instr (1, var1, "is")
'  Instr returns location of  "is" in string. Here 1 is location form where you want to start your search in string. if search start location is not given search will always start from 1st location of search string ,Var1 is string in which you have to search & "is" the string you are searching in var1.

4. msgbox mypos
' Returns location of "is". now using mid function you can get order number .'mid function is used to reterive specified number of  characters. Mid function is defined as mid (string,start,length)
'Here String is var1.MyPos is starting location where you want to reterieve characters.As we want to reterive whole string after "is" we will not define any length so it will capture complete string after "is". if you want to capture specified number of characters you can define number of charecter you want to reterive.

5. MyOrderNumber1= mid(var1,MyPos) 
 'Using this expression you will get order number but it will not be in integer form it will be "is 110."

6. msgbox MyOrderNumber1
'As you know the starting location of "is"  (MyPos) & you know that order number start after 3rd location from starting location of " is"  we add  +3 in MyOrderNumber so that it will give you 100, as order number start from 3rd location from "is"same way if there are more characters you can add them.

7. MyOrderNumber2=mid(var1,MyPos+3)
8. msgbox MyOrderNumber2

'In variable myordernumber you will get order number "110." but  you may required to reterive only 100 & remove this dot .As we have defined in line number11 for Mid function, we have not taken length after position of "is" . Lets say we take length as 3 so myordernumber=mid(var1,MyPos+3,3) will be used & it  will give you myordernumber = 100.

9. MyOrderNumber3=mid(var1,mypos+3,3)

10. msgbox MyOrderNumber3

Example 2 :

1. var1= "You have sucessfully saved your order, your order no is 2564359. You can edit your order details in future."

2. msgbox len (var1)

3. MyPos1 = instr(1,var1,"is")
'Reterive position of "is"
4. msgbox MyPos1

5. Str1=mid (var1,MyPos1+3)
'Reterive starting position of order number as order number is starting 3rd character from starting position of "is".
6. msgbox Str1

7. MyPos2=instr(1,str1,".")
'Reterive position of dot.as we already know starting position of order number if we know ending postion of order number we can extract using mid function which Returns a specified number of characters from a string.

8. msgbox MyPos2

9. Str2=mid (Str1,1,MyPos2-1)           
'  -1 have taken, to remove extra dot.You can use MyPos2 as well but it will show ordernumber with dot.
10. msgbox str2

Thursday, June 9, 2011

Flex 4_5 Plugin for testing flex aplication with QTP

As we know QTP does not support Flex application. To automate Flex application you have to install Adobe Flex plugin for QTP which is an additional plugin & provided by Adobe to enabled Flex application to be automated by QTP.

Requirements for Using the QTP Plug-in :

HP QuickTest Professional 10 with Internet Explorer 7 & Internet Explorer 8 or HP QuickTest Professional 9.5 with Internet Explorer 6 & Internet Explorer 7
• Adobe Flex 4 Plug-in for Mercury QuickTest Pro (This you have to download from Adobe site)
• Microsoft Internet Explorer, version 6 or later
• Flash Player ActiveX control – the version of Flash Player required is the same as that supported by the Flex SDK being used to compile the application for testing.

Installing the Plug-in :

To install QTP :

1. First Install Flash Player for Microsoft Internet Explorer. This is currently the only supported browser/player.
2. If you are using Mercury QTP on Microsoft Windows Vista you need to turn off the User Account Control (UAC) feature.
3. Restart your computer.

To install the Flex 4 Plug-in for Mercury QuickTest Pro :

1. To download QTP plugin for Flex application Goto (https://www.adobe.com/cfusion/entitlement/index.cfm?e=flex4_5_automation_plugin). Login to Adobe site with existing login or create new login & download this zip file.
2. After fetting the Adobe Flex 4 Plug-in for HP QuickTest Pro zip file , unzip it on the machine where you want to install the plug-in. 2. Double Click on the Install_QTP_Plugin.bat.
3. Restart your machine.

The plug-in installer will include the following in the installation directory:
• AIR folder which will have the AIR related dlls
• FLEX folder which will have the Flex related dlls
• Uninstall_QTP_Plugin.bat Double clicking on this bat file will uninstall the QTP Plug-in.
• ReadMe.txt file.

If you want to uninstall this plugin simply run Uninstall_QTP_Plugin.bat & restart your system. Always remember do not delete you plugin installer folder.
To check if you installation is sucessfull.Check TEAPluginIE.dll,TEAPluginQTP.dll files in registery.

Now Open QTP you should see Flex & AIR plaugin in you Add-IN Manager. 
You can test http://examples.adobe.com/flex2/inproduct/sdk/flexstore/flexstore.html application as this is sample application created by adobe for you to know if your plugin is working.

Some more links related to flex automation :
http://blogs.adobe.com/vikaschandran/2010/10/18/basic-flex-automation-work-flow/
http://blogs.adobe.com/vikaschandran/category/flex-automation/page/2/

Monday, June 6, 2011

Count number of checkboxes & set them ON.

Dim obj,AllObj

Set obj= description.Create()
obj("html tag").value = "input"
obj("type").value=("checkbox")
Set obj= browser(" Browser Name").Page("Page Name").ChildObjects(obj)
AllObj=obj.count
msgbox Allobj
For i = 0 to Allobj -1
Allobj(i).set"on"
Next

Working with files

Create text file & adding a line to it :

Dim f1, fso
Set fso= createobject ("scripting.filesystemobject")
Set f1= fso.createtextfile ("D:\QTP\QTP_FSO\file2.txt", true)
f1.writeline "Hello This is new file"

Open a Text file & read line :

Dim f1, fso,ReadLineTextFile,
forreading=1
Set fso= createobject ("scripting.filesystemobject")
Set f1= fso.opentextfile ("D:\QTP\QTP_FSO\file2.txt" ,ForReading)
ReadLineTextFile = f1.ReadLine
msgbox ReadLineTextFile

Check if file already exist :

Dim f1, fso,ReadLineTextFile,file1
forreading=1
Set fso= createobject ("scripting.filesystemobject")
If fso.FileExists("D:\QTP\QTP_FSO\file2.txt") Then
 msgbox "File Already Exists"
 else
msgbox "File does not exist"
Set f1= fso.createtextfile ("D:\QTP\QTP_FSO\file2.txt", true)
f1.writeline "Hello This is new file"
End If
Set f1= fso.opentextfile ("D:\QTP\QTP_FSO\file2.txt" ,ForReading)
ReadLineTextFile = f1.ReadLine
msgbox ReadLineTextFile
f1.Close
set file1= fso.GetFile("D:\QTP\QTP_FSO\file2.txt")
file1.delete

Appending a file :

Dim f1, fso,ReadLineTextFile,Readfile
forappending=8,forReading= 1
Set fso= createobject ("scripting.filesystemobject")
 If fso.FileExists("D:\QTP\QTP_FSO\file2.txt") Then
  msgbox "File Already Exists"
 else
msgbox "File does not exist"
 Set f1= fso.createtextfile ("D:\QTP\QTP_FSO\file2.txt",false)
f1.writeline "Hello This is new file"
 end if
 Set f1= fso.OpenTextFile("D:\QTP\QTP_FSO\file2.txt", 8)
f1.WriteLine" This line is appended as second"
 Set f1= fso.OpenTextFile("D:\QTP\QTP_FSO\file2.txt",1)
ReadFile = f1.readall
msgbox ReadFile
f1.close

Search a Specific String in a Text File :

Dim fso, f1, MyPos, SearchString, SearchChar
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f1 = fso.OpenTextFile("D:\QTP\QTP_FSO\file2.txt", 1,True)
 Do while f1.AtEndofStream <> True
     SearchString = f1.Readall
      SearchChar = "Hello"
msgbox SearchString
msgbox SearchChar
MyPos = Instr( 1, SearchString, SearchChar, 1)
   If MyPos >=0 Then
  msgbox "TextFound"
   Exit Do 
  else
msgbox "Text Not Found"
         End If
Loop
msgbox MyPos

Wednesday, June 1, 2011

FileSystemObject : Working with Folders

The FSO object model gives your server-side applications the ability to create, alter, move, and delete folders, or to detect if particular folders exist, and if so, where. You can also find out information about folders, such as their names, the date they were created or last modified, and so forth.
The FSO object model also makes it easy to process files. When processing files, the primary goal is to store data in a space- and resource-efficient, easy-to-access format. You need to be able to create files, insert and change the data, and output (read) the data.

FileSystemObject is main object. Contains methods and properties that allow you to create, delete, gain information about, and generally manipulate drives, folders, and files. Many of the methods associated with this object duplicate those in other FSO objects; they are provided for convenience.

Here I am presenting some basic scripts to Create Folder, Copy Folder,Delete Folder, Move Folder , See if Folder Exist or not.
working with this rich set of properties of FSO you need to firset cretae your FSO objec than use FileSystemObject methods provided.

Script to Create Folder :

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")  
Set ofolder= fso.createfolder ("C:\QTP_FSO")                                

Script to Delete Folder :

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")
fso.DeleteFolder (""C:\QTP_FSO")

Script To Copy Folder from One location to other:

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")
fso.CopyFolder "C:\QTP_FSO" , "D:\QTP\Functions\" ,True

Script To Move Folder from one location to other :

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")
fso.MoveFolder "C:\QTP_FSO" , "D:\QTP\Functions\"

Script to Check if folder already exist :

Dim fso , ofolder
Set fso = createobject ("scripting.filesystemobject")
If fso.FolderExists("C:\QTP_FSO") Then
MsgBox "Folder Already Exist"
else
msgbox "Folder does not exist"
Set ofolder= fso.createfolder ("C:\QTP_FSO")
End If

Friday, January 21, 2011

SetTo Property,GetToProperty & GetRoProperty

SetToProperty : SetToProperty change the value of test object during runtime. For example while testing a web application "name" property of web button was "Login" but in next release it changes to "Sign-In" but chnage is only for one build only & you got build very frequently so if you run your test , it will fail as in OR "name" is set as "Login" & in object it is "Sign-In". By using "SetToProperty" you can change its name property to "Login" to  again & pass you test.
This chnaged value is applicable for duration of test run only & does not affect OR,Active screen etc.Basic use of this property is when you dont want to add same type of multiple objects with different property description.

GetToProperty : GetToProperty is used to reterive the property value of test object during run time.

GetRoProperty : GetRoProperty methos is used to reterive runtime properties.

systemutil.Run "C:\Program Files\Internet Explorer\iexplore.exe" , "http://www.google.co.in/"
iname= browser("iGoogle").Page("iGoogle").GetROProperty("title")
'##############Using GetRoProperty method to reterive "name" property of Editbox.###########
iwebeditname= Browser("iGoogle").Page("iGoogle").WebEdit("q").GetROProperty("name")
msgbox iwebeditname
'##############Using SetRoProperty method to set "name" property of Editbox as Neeraj.###########
Browser("iGoogle").Page("iGoogle").WebEdit("q").SetToProperty  "name", "Neeraj"
igetro=Browser("iGoogle").Page("iGoogle").WebEdit("q").gettoproperty ("name")
msgbox igetro '######## Check if "name" Proerty value is changed or not.##########
Browser("iGoogle").Page("iGoogle").WebEdit("q").Set "neeraj"
Browser("iGoogle").Page("iGoogle").WebButton("Google Search").Click
Browser("iGoogle").Page("neeraj - Google Search").Sync

Friday, January 7, 2011

Count number of Links , display their names & URL on webpage

Dim obj,oAllLink_Page,Link_Count_Page,iName,iURL
Set obj=description.Create()
obj1("micclass").value="Link"
Set oAllLink_Page=browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").ChildObjects(obj1)
Link_Count_Page=oAllLink_Page.count
msgbox Link_Count_Page
For i = 0 to Link_Count_Page -1
 iName= oAllLink_Page(i).getroproperty("name")
 iURL= oAllLink_Page(i).getroproperty("url")
 msgbox " Name of Link - " &iName
 msgbox " URL - " &iURL