General Important scripts 2

1) Launch QTP From a note pad.

After writing the following script In a note pad, save it with "*.vbs" extension
Dim qtApp

Set qtApp = CreateObject( "QuickTest.Application" )
If Not qtApp.Launched Then
qtApp.Launch
qtApp.Visible = True
End If
qtApp.Test.Settings.Run.DisableSmartIdentification = False
Set qtApp = Nothing

2) GetTOProperties Method:
set a=dialog("Login").WinEdit("Agent Name:").GetTOProperties()

a_cnt=a.count
msgbox a_cnt
For i=0 to a_cnt-1
propname=a(i).name
propvalue=a(i).value
msgbox propname&"="&propvalue
Next

General Important scripts1

1) Open a msgbox and close it in a specified time
set messagebox = createobject("wscript.shell")
messagebox.popup"message",time in sec,"Title of message box (Optional)"

2) Find all the child objects with a specified text
Set oDes=description.Create()
oDes("micclass").value="WebElement"
oDes("html tag").value="FONT"
set AAA = Browser("name:=xxx").page("title:=yyy").ChildObjects(oDes)
cnt=AAA.count
For i= 0 To cnt-1
BBB= AAA.item(i).getroproperty("outertext")
If instr(1,BBB,"$") Then 'Displays all texts starting with $
print "Text starting with $ is= "& BBB
End If
Next

3) If u find text field is not enable until you send some keystroke to web edit, in that case we have to send key stroke to webedit by creating it as:
Set ws = createobject("wscript.shell")
Browser(brw).page(pge).webedit(usname).click
ws.sendkeys"username"

4) Find the properties of a text (Eg: Link)
Set a = Browser(browser).page(page).link(link_prop)
Set b = a.object
Color = b.currentStyle.color
BackgrColor = b.currentStyle.backgroundColor
FontSize = b.currentStyle.fontSize
FontStyle = b.currentStyle.fontStyle
FontFamily = b.currentStyle.fontFamily
FontWeight = b.currentStyle.fontWeight

Msgbox Color & vbnewline & BackgrColor & vbnewline & FontSize & vbnewline &FontStyle & vbnewline& FontFamily &vbnewline & FontWeight

5) Find the number of unread messages in inbox of Gmail using simple regular expression
systemutil.Run "https://www.gmail.com"
Set a =browser("name:=Gmail: Email from Google").page("title:=Gmail: Email from Google")
browser("name:=Gmail: Email from Google").sync
a.webedit("name:=Email").Set "sunilkumar284"
a.webedit("name:=Passwd").SetSecure "password"
a.webcheckbox("name:=PersistentCookie").click
a.webbutton("name:=Sign in").click

mails = Browser("name:=Gmail - Inbox *.*").page("title:=Gmail - Inbox *.*").link("name:=Inbox*.*").GetROProperty("outertext")
msgbox (mails)

Working with Excel files

1) In this let us discuss about the Data Driven testing using Excel sheet. Highlight the invalid validation with Red and valid one with green color based on the presence of the error message displaying ...

Set myexcel = createobject("excel.application") 'create an excelsheet object
Set myfile = myexcel.workbooks.open("C:\test1.xls") 'create an excel sheet in a specified folder
myexcel.visible = true
Set mysheet = myfile.worksheets("sheet1") 'assign the sheet in excel
Row_cnt = mysheet.usedrange.rows.count
For i = 2 to Row_cnt

FirstName = mysheet.cells(i,"A")
LastName = mysheet.cells(i,"B")

Set FirName = description.Create
FirName("name").value = "firstName"

Set LasName = description.Create
LasName("name").value = "lastName"

set erfir = description.create
erfir("outertext").value= "Enter valid First Name"
erfir("class").value = "errmessage"
erfir("Class Name").value = "WebElement"

Browser(hmbro).page(hmpage).webedit( FirName).set FirstName
If Browser(hmbro).page(hmpage).WebElement(erfir).Exist Then
print "Invalid First name: " & FirstName
mysheet.cells(i,"A").font.color =vbred
else
mysheet.cells(i,"A").font.color = vbgreen
End If

Browser(hmbro).page(hmpage).webedit(LasName).Set LastName
set erlast = description.create()
erlast("outertext").value= "Enter valid Last Name"
erlast("class").value = "errmessage"
erlast("Class Name").value = "WebElement"
If Browser(hmbro).page(hmpage).WebElement(erlast).Exist Then
print "Invalid Last name: " & LastName
mysheet.cells(i,"B").font.color = vbred
else
mysheet.cells(i,"B").font.color =vbgreen

End If
Next
myexcel.quit
set myexcel = nothing

2) Compare two excel sheets:

Set a = createobject ("excel.application")
a.visible= True
Set b = a.workbooks.open ("D:\test1.xls")
Set c = a.workbooks.open ("D:\test2.xls")
Set d = b.worksheets (1)
Set e = c.worksheets (1)
For each cell in d.usedRange
If cell.value<>e.range (cell.address).value Then
cell.interior.colorindex=3
cell.font.color = vbgreen
else
cell.interior.colorindex=5
cell.font.color = vbred
End If
Next
a.quit ' If u want to close the excel then use this syntax
Set a=nothing

3) Create an Excel, Edit and provide a hyperlink to the edited text

Set excel = createobject("excel.application")
excel.visible = true
Set myfile = excel.workbooks.add
Set sheet = excel.worksheets(1)
sheet.cells(1,1) = "testing"
Set range = excel.range("A1")
Set hyperlink = sheet.hyperlinks.add(range,"http://www.ssofttesting.blogspot.com")