Hybrid Driven Framework VBScript in QTP/UFT

Here i written VBScript for hybrid driven framework using QTP/UFT tool, the spreadsheet column name like,

S.No. Test case ID Test case Description Expected Result Actual Result Method Element(Object) Activity Data Message Status SampleData HtmlID Name Title Text InnerText OuterText InnerHtml OuterHtml HtmlTag Value Abs_x Abs_y Disabled ReadOnly Href Url FileName Class ChildItem Rows Columns Index Style
Browser iexplore http://cr1.qdxsoft.com/user/login
WebEdit Set QM54439 membership

VERSION: 2 (version: 3 will be released later…)

Dim objExcel, objWorkbook, objWorksheet, RowsCount
‘Set obj=Browser(“name:=.*”).Page(“name:=.*”)
‘Set obj=Browser(“title:=Welcome to QADEX – Internet Explorer”).Page(“title:=Welcome to QADEX”)
‘Set obj=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”)
On error resume next
Set dobj=Dialog(“text:=Message from webpage”)
Set objExcel=Createobject(“Excel.Application”)
Set objWorkbook=objExcel.workbooks.Open(“C:\Users\selvaganapathy\Desktop\hybrid.xlsx”)
Set objWorksheet=objWorkbook.WorkSheets(1)
RowsCount=objWorksheet.UsedRange.Count
‘msgbox RowsCount
‘val=”iexplore.exe”
‘val2=”http://cr1.qdxsoft.com/user/login”
‘SystemUtil.Run val,val2
‘Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Sync
‘wait 60s
‘Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Sync
‘FireEvents Operations – onchange,onclick,ondblclick,onblur,onfocus,onmousedown,onmouseup,onmouseover,onmouseoutQM54439,onsubmit,onreset,onpropertychange
Dim i
For i=9 To 34 Step 1
‘wait 2
otype=objWorkSheet.Cells(i,7)
act=objWorkSheet.Cells(i,8)
data=objWorkSheet.Cells(i,9)
message=objWorkSheet.Cells(i,10)
sdata=objWorkSheet.Cells(i,12)
hid=objWorkSheet.Cells(i,14)
oname=objWorkSheet.Cells(i,15)
title=objWorkSheet.Cells(i,16)
text=objWorkSheet.Cells(i,17)
itext=objWorkSheet.Cells(i,18)
otext=objWorkSheet.Cells(i,19)
ihtml=objWorkSheet.Cells(i,20)
ohtml=objWorkSheet.Cells(i,21)
htag=objWorkSheet.Cells(i,22)
ovalue=objWorkSheet.Cells(i,23)
citem=objWorkSheet.Cells(i,32)
rows=objWorkSheet.Cells(i,33)
cols=objWorkSheet.Cells(i,34)
index=objWorkSheet.Cells(i,35)
sclass=objWorkSheet.Cells(i,36)
‘SGPPHybridCall
Call SGPPHybridCall(otype,act,data,message,sdata,hid,oname,title,text,itext,otext,ihtml,ohtml,htag,ovalue,citem,rows,cols,index,sclass)
Next

‘SGPPHybridCall Description

Function SGPPHybridCall(otype,act,data,message,sdata,hid,oname,title,text,itext,otext,ihtml,ohtml,htag,ovalue,citem,rows,cols,index,sclass)
Select Case otype

Case “Browser”
Set oBrowser=Description.Create()
‘ oBrowser(“micClass”).value=”Browser”
‘BrowserCall
Call browsercall(act,data)

Case “WebEdit”
Set oWebEdit=Description.Create()
oWebEdit(“micClass”).value=”WebEdit”
oWebEdit(“html id”).value=hid
oWebEdit(“name”).value=oname
oWebEdit(“text”).value=text
oWebEdit(“innertext”).value=itext
oWebEdit(“outertext”).value=otext
oWebEdit(“outertext”).value=otext
oWebEdit(“html tag”).value=htag
oWebEdit(“index”).value=index
oWebEdit(“class”).value=sclass

‘WebEditCall
Call SGPPWebEdit(oWebEdit,act,data)

Case “WebButton”
Set oWebButton=Description.Create()
oWebButton(“micClass”).value=”WebButton”
oWebButton(“html id”).value=hid
oWebButton(“name”).value=oname
oWebButton(“text”).value=text
oWebButton(“innertext”).value=itext
oWebButton(“outertext”).value=otext
oWebButton(“outertext”).value=otext
oWebButton(“html tag”).value=htag
oWebButton(“index”).value=index
oWebButton(“class”).value=sclass
‘WebButtonCall
Call SGPPWebButtont(oWebButton,act,data)

Case “Link”
Set oLink=Description.Create()
oLink(“micClass”).value=”Link”
oLink(“html id”).value=hid
oLink(“name”).value=oname
oLink(“text”).value=text
oLink(“innertext”).value=itext
oLink(“outertext”).value=otext
oLink(“outertext”).value=otext
oLink(“html tag”).value=htag
oLink(“index”).value=index
oLink(“class”).value=sclass
‘LinkCall
Call SGPPLink(oLink,act,data)

Case “WebList”
Set oWebList=Description.Create()
oWebList(“micClass”).value=”WebList”
oWebList(“html id”).value=hid
oWebList(“name”).value=oname
oWebList(“text”).value=text
oWebList(“innertext”).value=itext
oWebList(“outertext”).value=otext
oWebList(“outertext”).value=otext
oWebList(“html tag”).value=htag
oWebList(“index”).value=index
oWebList(“class”).value=sclass
‘WebListCall
Call SGPPWebList(oWebList,act,data)

Case “WebElement”
Set oWebElement=Description.Create()
oWebElement(“micClass”).value=”WebElement”
oWebElement(“html id”).value=hid
oWebElement(“name”).value=oname
oWebElement(“text”).value=text
oWebElement(“innertext”).value=itext
oWebElement(“outertext”).value=otext
oWebElement(“outertext”).value=otext
oWebElement(“html tag”).value=htag
oWebElement(“index”).value=index
oWebElement(“class”).value=sclass
‘WebElementCall
Call SGPPWebElement(oWebElement,act,data)

Case “WebCheckBox”
Set oWebCheckBox=Description.Create()
oWebCheckBox(“micClass”).value=”WebCheckBox”
oWebCheckBox(“html id”).value=hid
oWebCheckBox(“name”).value=oname
oWebCheckBox(“text”).value=text
oWebCheckBox(“innertext”).value=itext
oWebCheckBox(“outertext”).value=otext
oWebCheckBox(“outertext”).value=otext
oWebCheckBox(“html tag”).value=htag
oWebCheckBox(“index”).value=index
oWebCheckBox(“class”).value=sclass
‘WebCheckBoxCall
Call SGPPWebCheckBox(oWebCheckBox,act,data)

Case “WebRadioGroup”
Set oWebRadioGroup=Description.Create()
oWebRadioGroup(“micClass”).value=”WebRadioGroup”
oWebRadioGroup(“html id”).value=hid
oWebRadioGroup(“name”).value=oname
oWebRadioGroup(“text”).value=text
oWebRadioGroup(“innertext”).value=itext
oWebRadioGroup(“outertext”).value=otext
oWebRadioGroup(“outertext”).value=otext
oWebRadioGroup(“html tag”).value=htag
oWebRadioGroup(“index”).value=index
oWebRadioGroup(“class”).value=sclass
‘WebRadioGroupCall
Call SGPPWebRadioGroup(oWebRadioGroup,act,data)

Case “WebTable”
Set oWebTable=Description.Create()
oWebTable(“micClass”).value=”WebTable”
oWebTable(“html id”).value=hid
oWebTable(“name”).value=oname
oWebTable(“text”).value=text
oWebTable(“innertext”).value=itext
oWebTable(“outertext”).value=otext
oWebTable(“outertext”).value=otext
oWebTable(“html tag”).value=htag
oWebTable(“index”).value=index
oWebTable(“class”).value=sclass
‘WebRadioGroupCall
Call SGPPWebTable(oWebTable,act,data,citem,rows,cols,index)

Case “Frame”
Set oFrame=Description.Create()
oFrame(“micClass”).value=”Frame”
oFrame(“html id”).value=hid
oFrame(“name”).value=oname
oFrame(“text”).value=text
oFrame(“innertext”).value=itext
oFrame(“outertext”).value=otext
oFrame(“outertext”).value=otext
oFrame(“html tag”).value=htag
oFrame(“index”).value=index
oFrame(“class”).value=sclass
‘FrameCall
Call SGPPFrame(oFrame,act,data)
End Select
End Function
‘BroserCall Description
Function browsercall(act,data)
Select Case act
Case “iexplore”
SystemUtil.Run “iexplore.exe”,data
Reporter.ReportEvent micPass,””,”Internet Explorer browser is opened”
Case “Firefox”
SystemUtil.Run “Firefox.exe”,data
Reporter.ReportEvent micPass,””,”Firefox browser is opened”
Case “Chrome”
SystemUtil.Run “chrome.exe”,data
Reporter.ReportEvent micPass,””,”Chrome browser is opened”
Case Else
SystemUtil.Run “iexplore.exe”,data
Reporter.ReportEvent micPass,””,”Else Part Internet Explorer browser is opened”
End Select
End Function

‘WebEditCall Description
Function SGPPWebEdit(oWebEdit,act,data)
Select Case act

Case “Set”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Exist Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Set data
Reporter.ReportEvent micPass, “oWebEdit”, data &” is entered.”
Else
Reporter.ReportEvent micFail, “oWebEdit”, data &” is not entered.”
End If
Case “Empty”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Exist Then
valTXT=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).GetRoProperty(“value”)
If valTXT=”” Then
Dim inputdata
inputdata=InputBox(“Please Enter the Correct data”)
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Set inputdata
End If
Reporter.ReportEvent micPass, “oWebEdit”, inputdata &” is entered.”
Else
Reporter.ReportEvent micFail, “oWebEdit”, inputdata &” is not entered.”
End If

Case “SetSecure”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Exist Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).SetSecure data
Reporter.ReportEvent micPass, “oWebEdit”, data &” is entered.”
Else
Reporter.ReportEvent micFail, “oWebEdit”, data &” is not entered.”
End If
Case “Submit”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Exist Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Submit
Reporter.ReportEvent micPass, “oWebEdit”, ” WebEdit is Submitted.”
Else
Reporter.ReportEvent micFail, “oWebEdit”, ” WebEdit is not Submitted”
End If
Case “Click”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Exist Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Click
Reporter.ReportEvent micPass, “WebEdit”,”WebEdit is Clicked”
Else
Reporter.ReportEvent micFail, “WebEdit”,”WebEdit is not Clicked”
End If
Case “Display”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Exist Then
Reporter.ReportEvent micPass, “oWebEdit”, “Text Field is displaying or present”
Else
Reporter.ReportEvent micFail, “oWebEdit”, “Text Field is not displaying”
End If

Case “Length”
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Set data
data=Len(data)
limit=sdata
msgbox limit
msgbox data
If data > limit Then
Reporter.ReportEvent micPass, “oWebEdit”, “The string length is “&data&” exceeded the “&limit
If Dialog(“text:=Message from webpage”).Exist Then
Dialog(“text:=Message from webpage”).Activate
Dialog(“text:=Message from webpage”).WinButton(“text:=OK”).Click
Reporter.ReportEvent micPass, “oWebEdit”, “Alert-Box is present for the string length is exceeded the limit”
Else
Reporter.ReportEvent micFail, “oWebEdit”, “Alert-Box is not present for the string length is not exceeded the limit”
End If
Reporter.ReportEvent micFail, “oWebEdit”, “The string length is “&data&” exceeded the “&limit
Else
End If

Case “Numeric”
‘ Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Set data
val=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).GetROProperty(“value”)
If IsNumeric(val) Then
Reporter.ReportEvent micPass, “oWebEdit”, “Only Numeric is present”
Else
Reporter.ReportEvent micFail, “oWebEdit”, “Non Numeric also present”
End If

Case “Alpha”
‘ Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Set data
val=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).GetROProperty(“value”)
set reNonAplha = new RegExp
reNonAplha.pattern = “[^A-Za-z]”
If reNonAplha.test(val) Then
Reporter.ReportEvent micFail, “oWebEdit”, “The string is non-alpha”
Else
Reporter.ReportEvent micPass, “oWebEdit”, “The string is only alpha”
End If

Case “SpecialChar”
‘ Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Set data
val=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).GetROProperty(“value”)
set reNonAplha = new RegExp
reNonAplha.pattern = “[(?*””,\\<>&#~%{}+_.@:\/!;]+”
If reNonAplha.test(val) Then
Reporter.ReportEvent micPass, “oWebEdit”, “Special Char is presentt”
Else
Reporter.ReportEvent micFail, “oWebEdit”, “Special Char is not Present”
End If

Case “TypeName”
‘ Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).Set data
val=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(oWebEdit).GetROProperty(“value”)
dtype=TypeName(val)
Select Case dtype
Case “Integer”
Reporter.ReportEvent micPass, “”, dtype&” is present”
Case “Double”
Reporter.ReportEvent micPass, “”, dtype&” is present”
Case “String”
Reporter.ReportEvent micPass, “”, dtype&” is present”
Case Else
Reporter.ReportEvent micPass, “”, dtype&” is present”
End Select

Case “Alert”
If dBrowser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Exist Then
dBrowser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Activate
dBrowser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WinButton(“text:=OK”).Click
Reporter.ReportEvent micPass, “oWebEdit”, “Alert-Box is presentt”
Else
Reporter.ReportEvent micFail, “oWebEdit”, “Alert-Box is not present”
End If

End Select
End Function

‘WebButtonCall Description
Function SGPPWebButtont(oWebButton,act,data)
Select Case act
Case “Display”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).Exist Then
Reporter.ReportEvent micPass, “oWebButton”, “WebButton is displaying or present”
Else
Reporter.ReportEvent micFail, “oWebButton”, “WebButton is not displaying”
End If

Case “Click”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).Exist Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).Click
Reporter.ReportEvent micPass, “oWebButton”,”WebButton is Clicked”
Else
Reporter.ReportEvent micFail, “oWebButton”,”WebButton is not exist and not clicked”
End If

Case “FireEvent”
Setting.WebPackage(“ReplayType”) = 2
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).FireEvent data
Setting.WebPackage(“ReplayType”) = 2

Case “Color”
color= Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).Object.currentStyle.color
Reporter.ReportEvent micPass, “oWebElement”,color & ” color is displaying”
Case “BGColor”
bgcolor=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).Object.currentStyle.backgroundColor
Reporter.ReportEvent micPass, “oWebElement”,bgcolor & ” Background color is displaying”
Case “FSize”
fsize=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).Object.currentStyle.fontSize
Reporter.ReportEvent micPass, “oWebElement”,fsize & ” Font Size is displaying”
Case “FStyle”
fstyle=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).Object.currentStyle.fontStyle
Reporter.ReportEvent micPass, “oWebElement”,fstyle & ” Font Style is displaying”
Case “FFamily”
ffamily=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).Object.currentStyle.fontFamily
Reporter.ReportEvent micPass, “oWebElement”,ffamily & ” Font Family is displaying”
Case “SWeight”
fweight=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).Object.currentStyle.fontWeight
Reporter.ReportEvent micPass, “oWebElement”,fweight & ” Font Weight is displaying”
Case “TextAlign”
talign=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(oWebButton).Object.currentStyle.textAlign
Reporter.ReportEvent micPass, “oWebElement”,talign & ” Align is displaying”
Case Else

End Select
End Function

‘LinkCall Description
Function SGPPLink(oLink,act,data)
Select Case act
Case “Display”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).Exist Then
Reporter.ReportEvent micPass, “oLink”, “Link is displaying or present”
Else
Reporter.ReportEvent micFail, “oLink”, “Link is not displaying”
End If
Case “Click”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).Exist Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).Click
Reporter.ReportEvent micPass,”oLink”,”Link is Clicked”
Else
Reporter.ReportEvent micFail, “oLink”,”Link is not clicked and not exist”
End If

Case “FireEvent”
Setting.WebPackage(“ReplayType”) = 2
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).FireEvent data
Setting.WebPackage(“ReplayType”) = 2

Case “Color”
color= Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).Object.currentStyle.color
Reporter.ReportEvent micPass, “oWebElement”,color & ” color is displaying”
Case “BGColor”
bgcolor=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).Object.currentStyle.backgroundColor
Reporter.ReportEvent micPass, “oWebElement”,bgcolor & ” Background color is displaying”
Case “FSize”
fsize=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).Object.currentStyle.fontSize
Reporter.ReportEvent micPass, “oWebElement”,fsize & ” Font Size is displaying”
Case “FStyle”
fstyle=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).Object.currentStyle.fontStyle
Reporter.ReportEvent micPass, “oWebElement”,fstyle & ” Font Style is displaying”
Case “FFamily”
ffamily=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).Object.currentStyle.fontFamily
Reporter.ReportEvent micPass, “oWebElement”,ffamily & ” Font Family is displaying”
Case “SWeight”
fweight=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).Object.currentStyle.fontWeight
Reporter.ReportEvent micPass, “oWebElement”,fweight & ” Font Weight is displaying”
Case “TextAlign”
talign=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(oLink).Object.currentStyle.textAlign
Reporter.ReportEvent micPass, “oWebElement”,talign & ” Align is displaying”

Case Else

End Select
End Function

‘WebList Call Description
Function SGPPWebList(oWebList,act,data)
Select Case act
Case “Display”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Exist Then
Reporter.ReportEvent micPass, “oWebList”, “WebList is displaying or present”
Else
Reporter.ReportEvent micFail, “oWebList”, “WebList is not displaying”
End If
Case “Random”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Exist Then
Itemcount=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).GetROProperty(“items count”)
‘ select random value from product drop down field
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Select “#” & RandomNumber.value(1, Itemcount -1)
Reporter.ReportEvent micPass, “oWebList”,”WebList is randomely selected”
Else
Reporter.ReportEvent micFail, “oWebList”,”Weblist is not selected and not exist”
End If

Case “Specific”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Exist Then
Itemcount=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).GetROProperty(“items count”)
If Itemcount > data Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Select “#”&data
End If
Reporter.ReportEvent micPass, “oWebList”,”WebList is selected in specific manner”
Else
Reporter.ReportEvent micFail, “oWebList”,”WebList is not selected is specific manner”
End If

Case “Color”
color= Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Object.currentStyle.color
Reporter.ReportEvent micPass, “oWebElement”,color & ” color is displaying”
Case “BGColor”
bgcolor=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Object.currentStyle.backgroundColor
Reporter.ReportEvent micPass, “oWebElement”,bgcolor & ” Background color is displaying”
Case “FSize”
fsize=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Object.currentStyle.fontSize
Reporter.ReportEvent micPass, “oWebElement”,fsize & ” Font Size is displaying”
Case “FStyle”
fstyle=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Object.currentStyle.fontStyle
Reporter.ReportEvent micPass, “oWebElement”,fstyle & ” Font Style is displaying”
Case “FFamily”
ffamily=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Object.currentStyle.fontFamily
Reporter.ReportEvent micPass, “oWebElement”,ffamily & ” Font Family is displaying”
Case “SWeight”
fweight=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Object.currentStyle.fontWeight
Reporter.ReportEvent micPass, “oWebElement”,fweight & ” Font Weight is displaying”
Case “TextAlign”
talign=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebList(oWebList).Object.currentStyle.textAlign
Reporter.ReportEvent micPass, “oWebElement”,talign & ” Align is displaying”
Case Else

End Select
End Function
Function SGPPWebElement(oWebElement,act,data)
Select Case act
Case “FireEvent”
Setting.WebPackage(“ReplayType”) = 2
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Link(“text:=India Net Neutrality”).FireEvent data
Setting.WebPackage(“ReplayType”) = 2
Case “Sync”
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Sync
Case “Color”
color= Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebElement(oWebElement).Object.currentStyle.color
Reporter.ReportEvent micPass, “oWebElement”,color & ” color is displaying”
Call color_name(color)
Case “BGColor”
bgcolor=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebElement(oWebElement).Object.currentStyle.backgroundColor
Reporter.ReportEvent micPass, “oWebElement”,bgcolor & ” Background color is displaying”
Case “FSize”
fsize=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebElement(oWebElement).Object.currentStyle.fontSize
Reporter.ReportEvent micPass, “oWebElement”,fsize & ” Font Size is displaying”
Case “FStyle”
fstyle=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebElement(oWebElement).Object.currentStyle.fontStyle
Reporter.ReportEvent micPass, “oWebElement”,fstyle & ” Font Style is displaying”
Case “FFamily”
ffamily=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebElement(oWebElement).Object.currentStyle.fontFamily
Reporter.ReportEvent micPass, “oWebElement”,ffamily & ” Font Family is displaying”
Case “SWeight”
fweight=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebElement(oWebElement).Object.currentStyle.fontWeight
Reporter.ReportEvent micPass, “oWebElement”,fweight & ” Font Weight is displaying”
Case “TextAlign”
talign=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebElement(oWebElement).Object.currentStyle.textAlign
Reporter.ReportEvent micPass, “oWebElement”,talign & ” Align is displaying”
Case Else

End Select
End Function

Function SGPPWebCheckBox(oWebCheckBox,act,data)
Select Case act
Case “Specific”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebCheckBox(oWebCheckBox).Exist Then
data=data
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebCheckBox(oWebCheckBox).Set data
Reporter.ReportEvent micPass, “oWebCheckBox”, data &” WebCheckBox is setted in specific manner”
Else
Reporter.ReportEvent micFail, “oWebCheckBox”, data &” WebCheckBox is not setted in specific manner”
End If
End Select
End Function

Function SGPPWebRadioGroup(oWebRadioGroup,act,data)
Select Case act
Case “Display”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebRadioGroup(oWebRadioGroup).Exist Then
Reporter.ReportEvent micPass, “oWebRadioGroup”, “WebRadioGroup is displaying or present”
Else
Reporter.ReportEvent micFail, “oWebRadioGroup”, “WebRadioGroup is not displaying”
End If
Case “Random”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebRadioGroup(oWebRadioGroup).Exist Then
‘Here u should pass common properties for all radio’s button
itemcount=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebRadioGroup(oWebRadioGroup).GetROProperty(“items count”)
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebRadioGroup(oWebRadioGroup).Select “#” & RandomNumber.value(1, itemcount -1)
End If

Case “Specific”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebRadioGroup(oWebRadioGroup).Exist Then
‘ Itemcount=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebRadioGroup(oWebRadioGroup).GetROProperty(“items count”)
‘ If Itemcount > data Then
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebRadioGroup(oWebRadioGroup).Exist Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebRadioGroup(oWebRadioGroup).Select “#1”
Reporter.ReportEvent micPass, “oWebRadioGroup”,”WebRadioGroup is Selected in specific manner”
Else
Reporter.ReportEvent micFail, “oWebRadioGroup”,”WebRadioGroup is Selected in specific manner and not exist”
End If

‘ End If
End If

Case Else

End Select
End Function
Function SGPPWebTable(oWebTable,act,data,citem,rows,cols,index)
Select Case act
Case “Display”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Exist Then
Reporter.ReportEvent micPass, “oWebTable”, “WebTable is displaying or present”
Else
Reporter.ReportEvent micFail, “oWebTable”, “WebTable is not displaying”
End If
Case “Click”
‘ msgbox Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).RowCount
‘ msgbox Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).ColumnCount(1)
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Exist Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).ChildItem(rows,cols,citem,index).Click
Reporter.ReportEvent micFail, “oWebTable”,”WebTable is Clicked”
Else
Reporter.ReportEvent micFail, “oWebTable”,”WebTable is not clicked and not exist”
End If

Case “Select”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Exist Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).ChildItem(rows,cols,data,index).Select “#1”
Reporter.ReportEvent micFail, “oWebTable”,”WebTable is Selected”
Else
Reporter.ReportEvent micFail, “oWebTable”,”WebTable is not Selected and not exist”
End If
” txt=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).ChildItem(rows,cols,data,index).GetROProperty(“items count”)
‘ rowcount=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).RowCount
‘ colscount= Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).ColumnCount(1)
‘ If rowcount < 0 Then
‘ msgbox “List is Empty”
‘ else
” itemcount=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebRadioGroup(oWebRadioGroup).GetROProperty(“items count”)
” Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebRadioGroup(oWebRadioGroup).Select “#” & RandomNumber.value(1, itemcount -1)
‘ Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).ChildItem(rows,cols,data,index).Select “#1″ ””””””””””’Need to change #1 to dynamic
‘ End If
Case “Set”
If Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Exist Then
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).ChildItem(rows,cols,citem,index).Set data
Reporter.ReportEvent micFail, “oWebTable”,”WebTable is setted”
Else
Reporter.ReportEvent micFail, “oWebTable”,”WebTable is not setted and not exist”
End If

Case “Color”
color= Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Object.currentStyle.color
Reporter.ReportEvent micPass, “oWebElement”,color & ” color is displaying”
Case “BGColor”
bgcolor=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Object.currentStyle.backgroundColor
Reporter.ReportEvent micPass, “oWebElement”,bgcolor & ” Background color is displaying”
Case “FSize”
fsize=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Object.currentStyle.fontSize
Reporter.ReportEvent micPass, “oWebElement”,fsize & ” Font Size is displaying”
Case “FStyle”
fstyle=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Object.currentStyle.fontStyle
Reporter.ReportEvent micPass, “oWebElement”,fstyle & ” Font Style is displaying”
Case “FFamily”
ffamily=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Object.currentStyle.fontFamily
Reporter.ReportEvent micPass, “oWebElement”,ffamily & ” Font Family is displaying”
Case “SWeight”
fweight=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Object.currentStyle.fontWeight
Reporter.ReportEvent micPass, “oWebElement”,fweight & ” Font Weight is displaying”
Case “TextAlign”
talign=Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(oWebTable).Object.currentStyle.textAlign
Reporter.ReportEvent micPass, “oWebElement”,talign & ” Align is displaying”

End Select
End Function

”Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Frame(“html id:=iframeResult”).WebElement(“innertext:=Double-click this paragraph to trigger a function.”).FireEvent -> For Frame

Function SGPPFrame(oFrame,act,data)
Select Case method
Case “WebEdit”
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Frame(“html id:=iframeResult”).WebEdit(oFrame).Set data
Case “WebElement”
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Frame(“html id:=iframeResult”).WebElement(oFrame).Set data
Case “WebList”
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Frame(“html id:=iframeResult”).WebList(oFrame).Select “#1”
Case “WebCheckBox”
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Frame(“html id:=iframeResult”).WebElement(oFrame).Select “#1”
Case “WebButton”
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Frame(“html id:=iframeResult”).WebButton(oFrame).Click
Case “Link”
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Frame(“html id:=iframeResult”).Link(oFrame).Click
Case “WebCheckBox”
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Frame(“html id:=iframeResult”).WebCheckBox(oFrame).Select “#1”
Case “WebTable”
Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).Frame(“html id:=iframeResult”).WebTable(oWebTable).ChildItem(rows,cols,data,index).Select “#1″

End Select
End Function

On Error Goto 0

objExcel.ActiveWorkbook.Close

”Close Excel
objExcel.Application.Quit

Set objWorksheet =nothing
Set objExcel = nothing

‘Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebTable(“name:=Date Added”).ChildItem(2,9,”WebButton”,0).Click

‘Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(“name:=Add New Complaint”,”index:=0″).Click
‘Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(“name:=Add New Complaint”).Click

‘Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(“html id:=voucher_code_0”).Set “2654”
‘Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebEdit(“html id:=voucher_amount_0”).Set “2”
‘Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebButton(“name:=Add More”).Click

‘Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebElement(“innertext:=Use this screen to detail, categorise and investigate your complaints.”,”class:=content_text1″).Object.currentStyle.color
Dim ctrlWebEl, objWebEl

msgbox Browser(“title:=Welcome to QADEX”).Page(“title:=Welcome to QADEX”).WebElement(“innertext:=Line”,”class:=content_text1″).Object.currentStyle.textAlign
Set objWebEl = ctrlWebEl.Object

msgbox objWebEl.currentStyle.textAlign
msgbox objWebEl.currentStyle.color
msgbox objWebEl.currentStyle.backgroundColor
msgbox objWebEl.currentStyle.fontSize
msgbox objWebEl.currentStyle.fontStyle
msgbox objWebEl.currentStyle.fontFamily
msgbox objWebEl.currentStyle.fontWeight

Dim d, msg ‘ Create some variables.
Set d = CreateObject(“Scripting.Dictionary”)
d.Add “a”, “Apple” ‘ Add some keys and items.
d.Add “b”, “BlueTooth”
d.Add “c”, “C++”
For i = 0 to d.Count – 1

If d.Exists(“c”) Then
keys = d.Keys

msgbox Keys(i) & ” = ” & d.item(Keys(i))

End If
next
Function color_name(color)
msgbox “Function called”
Dim d, msg ‘ Create some variables.
Set d = CreateObject(“Scripting.Dictionary”)
d.Add “#000000”, “black” ‘ Add some keys and items.
d.Add “b”, “BlueTooth”
d.Add “c”, “C++”
msgbox color
c=CInt(color)

If d.Exists(c) Then
msgbox c
keys = d.Keys
msgbox d.item(Keys(c))
msgbox “If Exit”
End If
End Function

 

 

Advertisements

MySQL Database Connection with ASP or VBScript using QTP tool

To query a MySQL database using Classic ASP you will need to use one of  the MySQL ODBC drivers installed on our system:
  • MySQL ODBC 5.3 Unicode Driver
  • MySQL ODBC 5.3 ANSI Driver

Suppose if your not installed odbc mysql driver means, first need to install. To install mysql odbc driver please follow the given link
http://sql-articles.com/articles/dba/creating-linked-server-to-mysql-from-sql-server/

 Example connection string using Classic ASP or VBScript(QTP tool) to call on a MySQL database:
Dim obj’‘ create a connection object
Set conn = createobject(“ADODB.connection”)’‘ create recordset object
Set MyRecordset = CreateObject(“ADODB.Recordset”)

‘‘ Connection string to connect MySQL database using ODBC 3.51 driver
‘Srvname = “driver={MySQL ODBC 3.51 Driver};server=192.168.10.18;port = 3306 ;User Id=root;Password=qadex_16Mar15; database=qadex_16Mar15”
‘Srvname = “driver={MySQL ODBC 5.3.4 Driver};server=192.168.10.18;port = 3306 ;User Id=root;Password=password; database=qadex_16Mar15” ‘Statndard Driver
Srvname = “DRIVER={MySQL ODBC 5.3 Unicode Driver};SERVER=192.168.10.18; DATABASE=qadex_16Mar15;USER=root;PASSWORD=password;OPTION=3;” ‘Unicode Driver
‘Srvname = “DRIVER={MySQL ODBC 5.3 ANSI Driver};SERVER=192.168.10.18; DATABASE=qadex_16Mar15;USER=root;PASSWORD=password;OPTION=3;” ‘ANSI Driver

‘‘ established connection with server using provided data in to query string.
conn.open Srvname

‘‘ A database operation query which needs to be performed.
‘SQL=”SELECT * FROM members where title=SGPP”
‘SQL=”insert into members(title,content,manufacturer,supplier,file_name)values(‘SGPP Correct’,’hi hello’,’Aaron’,’Sumner’,’testfile’)”
val=”select * from members order by id desc limit 1″

‘val=”select * from members where title=SGPP”
SQL=val’‘ Execute database query using already established connection and store result in to my record set.
MyRecordset.Open SQL,conn’‘ Store value of any fieldm
obj = MyRecordset.fields.item(“title”)

‘‘ message box to show that value
msgbox obj

‘‘ close my recordset
MyRecordset.Close

‘‘Close db connection
conn.Close

Hybrid Driven Framework VBScript in QTP/UFT

Here i written VBScript for hybrid driven framework using QTP/UFT tool, the spreadsheet column name like,

S.No. Test case ID Test case Description Expected Result Actual Result Method Element(Object) Activity Data Message Status SampleData HtmlID Name Title Text InnerText OuterText InnerHtml OuterHtml HtmlTag Value Abs_x Abs_y Disabled ReadOnly Href Url FileName Class ChildItem Rows Columns Index
Browser iexplore http://cr1.qdxsoft.com/user/login
WebEdit Set QM54439 membership

 

VERSION: 1 (version: 2 will be released later…)

Dim objExcel, objWorkbook, objWorksheet, RowsCount
‘Set obj=Browser(“name:=.*”).Page(“name:=.*”)
Set obj=Browser(“title:=Welcome to QADEX – Internet Explorer”).Page(“title:=Welcome to QADEX”)
Set dobj=Dialog(“text:=Message from webpage”)
Set objExcel=Createobject(“Excel.Application”)
Set objWorkbook=objExcel.workbooks.Open(“C:\Users\selvaganapathy\Desktop\hybrid.xlsx”)
Set objWorksheet=objWorkbook.WorkSheets(1)
RowsCount=objWorksheet.UsedRange.Count
‘msgbox RowsCount
‘val=”iexplore.exe”
‘val2=”http://cr1.qdxsoft.com/user/login&#8221;
‘SystemUtil.Run val,val2
‘obj.Sync
‘wait 60s
‘obj.Sync
‘FireEvents Operations – onchange,onclick,ondblclick,onblur,onfocus,onmousedown,onmouseup,onmouseover,onmouseoutQM54439,onsubmit,onreset,onpropertychange
Dim i
For i=9 To RowsCount Step 1
‘wait 2
otype=objWorkSheet.Cells(i,7)
act=objWorkSheet.Cells(i,8)
data=objWorkSheet.Cells(i,9)
message=objWorkSheet.Cells(i,10)
sdata=objWorkSheet.Cells(i,12)
hid=objWorkSheet.Cells(i,14)
oname=objWorkSheet.Cells(i,15)
title=objWorkSheet.Cells(i,16)
text=objWorkSheet.Cells(i,17)
itext=objWorkSheet.Cells(i,18)
otext=objWorkSheet.Cells(i,19)
ihtml=objWorkSheet.Cells(i,20)
ohtml=objWorkSheet.Cells(i,21)
htag=objWorkSheet.Cells(i,22)
ovalue=objWorkSheet.Cells(i,23)
citem=objWorkSheet.Cells(i,32)
rows=objWorkSheet.Cells(i,33)
cols=objWorkSheet.Cells(i,34)
index=objWorkSheet.Cells(i,35)
‘SGPPHybridCall
Call SGPPHybridCall(otype,act,data,message,sdata,hid,oname,title,text,itext,otext,ihtml,ohtml,htag,ovalue,citem,rows,cols,index)
Next

‘SGPPHybridCall Description

Function SGPPHybridCall(otype,act,data,message,sdata,hid,oname,title,text,itext,otext,ihtml,ohtml,htag,ovalue,citem,rows,cols,index)

Set obj=Browser(“name:=.*”).Page(“name:=.*”)

Select Case otype

Case “Browser”
Set oBrowser=Description.Create()
‘ oBrowser(“micClass”).value=”Browser”
‘BrowserCall
Call browsercall(act,data)

Case “WebEdit”
Set oWebEdit=Description.Create()
oWebEdit(“micClass”).value=”WebEdit”
oWebEdit(“html id”).value=hid
oWebEdit(“name”).value=oname
oWebEdit(“text”).value=text
oWebEdit(“innertext”).value=itext
oWebEdit(“outertext”).value=otext
oWebEdit(“outertext”).value=otext
oWebEdit(“html tag”).value=htag
‘WebEditCall
Call SGPPWebEdit(obj,oWebEdit,act,data)

Case “WebButton”
Set oWebButton=Description.Create()
oWebButton(“micClass”).value=”WebButton”
oWebButton(“html id”).value=hid
oWebButton(“name”).value=oname
oWebButton(“text”).value=text
oWebButton(“innertext”).value=itext
oWebButton(“outertext”).value=otext
oWebButton(“outertext”).value=otext
oWebButton(“html tag”).value=htag
‘WebButtonCall
Call SGPPWebButtont(obj,oWebButton,act,data)

Case “Link”
Set oLink=Description.Create()
oLink(“micClass”).value=”Link”
oLink(“html id”).value=hid
oLink(“name”).value=oname
oLink(“text”).value=text
oLink(“innertext”).value=itext
oLink(“outertext”).value=otext
oLink(“outertext”).value=otext
oLink(“html tag”).value=htag
‘LinkCall
Call SGPPLink(obj,oLink,act,data)

Case “WebList”
Set oWebList=Description.Create()
oWebList(“micClass”).value=”WebList”
oWebList(“html id”).value=hid
oWebList(“name”).value=oname
oWebList(“text”).value=text
oWebList(“innertext”).value=itext
oWebList(“outertext”).value=otext
oWebList(“outertext”).value=otext
oWebList(“html tag”).value=htag
‘WebListCall
Call SGPPWebList(obj,oWebList,act,data)

Case “WebElement”
Set oWebElement=Description.Create()
oWebElement(“micClass”).value=”WebElement”
oWebElement(“html id”).value=hid
oWebElement(“name”).value=oname
oWebElement(“text”).value=text
oWebElement(“innertext”).value=itext
oWebElement(“outertext”).value=otext
oWebElement(“outertext”).value=otext
oWebElement(“html tag”).value=htag
‘WebElementCall
Call SGPPWebElement(obj,oWebElement,act,data)

Case “WebCheckBox”
Set oWebCheckBox=Description.Create()
oWebCheckBox(“micClass”).value=”WebCheckBox”
oWebCheckBox(“html id”).value=hid
oWebCheckBox(“name”).value=oname
oWebCheckBox(“text”).value=text
oWebCheckBox(“innertext”).value=itext
oWebCheckBox(“outertext”).value=otext
oWebCheckBox(“outertext”).value=otext
oWebCheckBox(“html tag”).value=htag
‘WebCheckBoxCall
Call SGPPWebCheckBox(obj,oWebCheckBox,act,data)

Case “WebRadioGroup”
Set oWebRadioGroup=Description.Create()
oWebRadioGroup(“micClass”).value=”WebRadioGroup”
oWebRadioGroup(“html id”).value=hid
oWebRadioGroup(“name”).value=oname
oWebRadioGroup(“text”).value=text
oWebRadioGroup(“innertext”).value=itext
oWebRadioGroup(“outertext”).value=otext
oWebRadioGroup(“outertext”).value=otext
oWebRadioGroup(“html tag”).value=htag
‘WebRadioGroupCall
Call SGPPWebRadioGroup(obj,oWebRadioGroup,act,data)

Case “WebTable”
Set oWebTable=Description.Create()
oWebTable(“micClass”).value=”WebTable”
oWebTable(“html id”).value=hid
oWebTable(“name”).value=oname
oWebTable(“text”).value=text
oWebTable(“innertext”).value=itext
oWebTable(“outertext”).value=otext
oWebTable(“outertext”).value=otext
oWebTable(“html tag”).value=htag
‘WebRadioGroupCall
Call SGPPWebTable(obj,oWebTable,act,data,citem,rows,cols,index)

Case “Frame”
Set oFrame=Description.Create()
oFrame(“micClass”).value=”Frame”
oFrame(“html id”).value=hid
oFrame(“name”).value=oname
oFrame(“text”).value=text
oFrame(“innertext”).value=itext
oFrame(“outertext”).value=otext
oFrame(“outertext”).value=otext
oFrame(“html tag”).value=htag
‘FrameCall
Call SGPPFrame(obj,oFrame,act,data)
End Select
End Function
‘BroserCall Description
Function browsercall(act,data)
Select Case act
Case “iexplore”
SystemUtil.Run “iexplore.exe”,data
Reporter.ReportEvent micPass,””,”Internet Explorer browser is opened”
Case “Firefox”
SystemUtil.Run “Firefox.exe”,data
Reporter.ReportEvent micPass,””,”Firefox browser is opened”
Case “Chrome”
SystemUtil.Run “chrome.exe”,data
Reporter.ReportEvent micPass,””,”Chrome browser is opened”
Case Else
SystemUtil.Run “iexplore.exe”,data
Reporter.ReportEvent micPass,””,”Else Part Internet Explorer browser is opened”
End Select
End Function

‘WebEditCall Description
Function SGPPWebEdit(obj,oWebEdit,act,data)
Select Case act

Case “Set”
obj.WebEdit(oWebEdit).Set data

Case “Empty”
‘If obj.GetROProperty(“value”) = “” Then
‘ msgbox “Empty”
‘Dim inputdata
‘inputdata=InputBox(“Please Enter the Correct data”)
‘obj.WebEdit(oWebEdit).Set inputdata
‘Else
‘msgbox “Not Empty”
‘End If

valTXT=obj.WebEdit(oWebEdit).GetRoProperty(“value”)
If valTXT=”” Then
Dim inputdata
inputdata=InputBox(“Please Enter the Correct data”)
obj.WebEdit(oWebEdit).Set inputdata
End If

Case “SetSecure”
obj.WebEdit(oWebEdit).SetSecure data

Case “Submit”
obj.WebEdit(oWebEdit).Submit

Case “Click”
obj.WebEdit(oWebEdit).Click

Case “Display”
If obj.WebEdit(oWebEdit).Exist Then
Reporter.ReportEvent micPass, “oWebEdit”, “Text Field is displaying or present”
Else
Reporter.ReportEvent micFail, “oWebEdit”, “Text Field is not displaying”
End If

Case “Length”
obj.WebEdit(oWebEdit).Set data
data=Len(data)
limit=sdata
msgbox limit
msgbox data
If data > limit Then
Reporter.ReportEvent micPass, “oWebEdit”, “The string length is exceeded the limit”
If Dialog(“text:=Message from webpage”).Exist Then
Dialog(“text:=Message from webpage”).Activate
Dialog(“text:=Message from webpage”).WinButton(“text:=OK”).Click
Reporter.ReportEvent micPass, “oWebEdit”, “Alert-Box is present for the string length is exceeded the limit”
Else
Reporter.ReportEvent micFail, “oWebEdit”, “Alert-Box is not present for the string length is not exceeded the limit”
End If
Reporter.ReportEvent micFail, “oWebEdit”,”The string length is not exceeded the limit”
Else
End If

Case “Numeric”
obj.WebEdit(oWebEdit).Set data
If IsNumeric(data) Then
Reporter.ReportEvent micPass, “oWebEdit”, “Only Numeric is present”
Else
Reporter.ReportEvent micFail, “oWebEdit”, “Non Numeric also present”
End If

Case “Alpha”
obj.WebEdit(oWebEdit).Set data
set reNonAplha = new RegExp
reNonAplha.pattern = “[^A-Za-z]”
If reNonAplha.test(data) Then
Reporter.ReportEvent micFail, “oWebEdit”, “The string is non-alpha”
Else
Reporter.ReportEvent micPass, “oWebEdit”, “The string is only alpha”
End If

Case “SpecialChar”
obj.WebEdit(oWebEdit).Set data
set reNonAplha = new RegExp
reNonAplha.pattern = “[(?*””,\\<>&#~%{}+_.@:\/!;]+”
If reNonAplha.test(data) Then
Reporter.ReportEvent micPass, “oWebEdit”, “Special Char is presentt”
Else
Reporter.ReportEvent micFail, “oWebEdit”, “Special Char is not Present”
End If

Case “TypeName”
obj.WebEdit(oWebEdit).Set data
dtype=TypeName(data)
Select Case dtype
Case “Integer”
Reporter.ReportEvent micPass, “”, dtype&” is present”
Case “Double”
Reporter.ReportEvent micPass, “”, dtype&” is present”
Case “String”
Reporter.ReportEvent micPass, “”, dtype&” is present”
Case Else
Reporter.ReportEvent micPass, “”, dtype&” is present”
End Select

Case “Alert”
If dobj.Exist Then
dobj.Activate
dobj.WinButton(“text:=OK”).Click
Reporter.ReportEvent micPass, “oWebEdit”, “Alert-Box is present for the string is non-alphat”
Else
Reporter.ReportEvent micFail, “oWebEdit”, “Alert-Box is not present for the string is non-alphat”
End If

End Select
End Function

‘WebButtonCall Description
Function SGPPWebButtont(obj,oWebButton,act,data)
Select Case act
Case “Display”
If obj.WebButton(oWebButton).Exist Then
Reporter.ReportEvent micPass, “oWebButton”, “WebButton is displaying or present”
Else
Reporter.ReportEvent micFail, “oWebButton”, “WebButton is not displaying”
End If

Case “Click”
obj.WebButton(oWebButton).Click
Case “FireEvent”
Setting.WebPackage(“ReplayType”) = 2
obj.WebButton(oWebButton).FireEvent data
Setting.WebPackage(“ReplayType”) = 2
Case Else

End Select
End Function

‘LinkCall Description
Function SGPPLink(obj,oLink,act,data)
Select Case act
Case “Display”
If obj.Link(oLink).Exist Then
Reporter.ReportEvent micPass, “oLink”, “Link is displaying or present”
Else
Reporter.ReportEvent micFail, “oLink”, “Link is not displaying”
End If
Case “Click”
obj.Link(oLink).Click
Case “FireEvent”
Setting.WebPackage(“ReplayType”) = 2
obj.Link(oLink).FireEvent data
Setting.WebPackage(“ReplayType”) = 2
Case Else

End Select
End Function

‘WebList Call Description
Function SGPPWebList(obj,oWebList,act,data)
Select Case act
Case “Display”
If obj.WebList(oWebList).Exist Then
Reporter.ReportEvent micPass, “oWebList”, “WebList is displaying or present”
Else
Reporter.ReportEvent micFail, “oWebList”, “WebList is not displaying”
End If
Case “Random”
Itemcount=obj.WebList(oWebList).GetROProperty(“items count”)
‘select random value from product drop down field
obj.WebList(oWebList).Select “#” & RandomNumber.value(1, Itemcount -1)
Case “Specific”
Itemcount=obj.WebList(oWebList).GetROProperty(“items count”)
If Itemcount > data Then
obj.WebList(oWebList).Select “#”&data
End If
Case Else

End Select
End Function
Function SGPPWebElement(obj,oWebElement,act,data)
Select Case act
Case “FireEvent”
Setting.WebPackage(“ReplayType”) = 2
obj.Link(“text:=India Net Neutrality”).FireEvent data
Setting.WebPackage(“ReplayType”) = 2
Case “Sync”
obj.Sync
Case Else

End Select
End Function

Function SGPPWebCheckBox(obj,oWebCheckBox,act,data)
Select Case act
Case “Specific”
data=data
obj.WebCheckBox(oWebCheckBox).Set data
End Select
End Function

Function SGPPWebRadioGroup(obj,oWebRadioGroup,act,data)
Select Case act
Case “Display”
If obj.WebRadioGroup(oWebRadioGroup).Exist Then
Reporter.ReportEvent micPass, “oWebRadioGroup”, “WebRadioGroup is displaying or present”
Else
Reporter.ReportEvent micFail, “oWebRadioGroup”, “WebRadioGroup is not displaying”
End If
Case “Random”
‘Here u should pass common properties for all radio’s button
itemcount=obj.WebRadioGroup(oWebRadioGroup).GetROProperty(“items count”)
obj.WebRadioGroup(oWebRadioGroup).Select “#” & RandomNumber.value(1, itemcount -1)
Case “Specific”
‘ Itemcount=obj.WebRadioGroup(oWebRadioGroup).GetROProperty(“items count”)
‘ If Itemcount > data Then
obj.WebRadioGroup(oWebRadioGroup).Select “#1”
‘ End If
Case Else

End Select
End Function
Function SGPPWebTable(obj,oWebTable,act,data,citem,rows,cols,index)
Select Case act
Case “Display”
If obj.WebTable(oWebTable).Exist Then
Reporter.ReportEvent micPass, “oWebTable”, “WebTable is displaying or present”
Else
Reporter.ReportEvent micFail, “oWebTable”, “WebTable is not displaying”
End If
Case “Click”
‘ msgbox obj.WebTable(oWebTable).RowCount
‘ msgbox obj.WebTable(oWebTable).ColumnCount(1)
obj.WebTable(oWebTable).ChildItem(rows,cols,citem,index).Click
Case “Select”
obj.WebTable(oWebTable).ChildItem(rows,cols,data,index).Select “#1″
” txt=obj.WebTable(oWebTable).ChildItem(rows,cols,data,index).GetROProperty(“items count”)
‘ rowcount=obj.WebTable(oWebTable).RowCount
‘ colscount= obj.WebTable(oWebTable).ColumnCount(1)
‘ If rowcount < 0 Then
‘ msgbox “List is Empty”
‘ else
” itemcount=obj.WebRadioGroup(oWebRadioGroup).GetROProperty(“items count”)
” obj.WebRadioGroup(oWebRadioGroup).Select “#” & RandomNumber.value(1, itemcount -1)
‘ obj.WebTable(oWebTable).ChildItem(rows,cols,data,index).Select “#1″ ””””””””””’Need to change #1 to dynamic
‘ End If
Case “Set”
obj.WebTable(oWebTable).ChildItem(rows,cols,citem,index).Set data
End Select
End Function

”obj.Frame(“html id:=iframeResult”).WebElement(“innertext:=Double-click this paragraph to trigger a function.”).FireEvent -> For Frame

Function SGPPFrame(obj,oFrame,act,data)
Select Case method
Case “WebEdit”
obj.Frame(“html id:=iframeResult”).WebEdit(oFrame).Set data
Case “WebElement”
obj.Frame(“html id:=iframeResult”).WebElement(oFrame).Set data
Case “WebList”
obj.Frame(“html id:=iframeResult”).WebList(oFrame).Select “#1”
Case “WebCheckBox”
obj.Frame(“html id:=iframeResult”).WebElement(oFrame).Select “#1”
Case “WebButton”
obj.Frame(“html id:=iframeResult”).WebButton(oFrame).Click
Case “Link”
obj.Frame(“html id:=iframeResult”).Link(oFrame).Click
Case “WebCheckBox”
obj.Frame(“html id:=iframeResult”).WebCheckBox(oFrame).Select “#1”
Case “WebTable”
obj.Frame(“html id:=iframeResult”).WebTable(oWebTable).ChildItem(rows,cols,data,index).Select “#1″

End Select
End Function

objExcel.ActiveWorkbook.Close

”Close Excel
objExcel.Application.Quit

Set objWorksheet =nothing
Set objExcel = nothing

Hybrid Driven Framework ruby script in Selenium Webdriver using TestWise Tool

Here i written ruby script for hybrid driven framework using testwise tool, the spreadsheet column name like,

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Element(Object) Method Keyword Data Message Status Id Name Linktext PartialLinktext TagName ClassName Xpath Dom
TextBox Type TextBoxType QM54439 Enter your Membership ID PASS membership

VERSION: 1 (version: 2 will be released later…)

############# keyword_01_spec.rb ################################
load File.dirname(__FILE__) + ‘/../test_helper.rb’
module Spreadsheet
class Workbook
attr_accessor :io
end
end
# $book=Spreadsheet.open ‘E:\Selva-Backup\testwise-xls\Keyword_25.xls’
# $sheet1 = $book.worksheet ‘Sheet1’
$book=Spreadsheet.open ‘E:\Selva-Backup\testwise-xls\keyword_25_orgs.xls’
$sheet1 = $book.worksheet ‘Sheet1’
$book.write ‘E:\Selva-Backup\testwise-xls\Keyword_25_copy.xls’
$book.io.close
$book=Spreadsheet.open ‘E:\Selva-Backup\testwise-xls\Keyword_25_copy.xls’

#FileUtils.rm ‘E:\Selva-Backup\testwise-xls\test_01.xls’

FileUtils.rm ‘E:\Selva-Backup\testwise-xls\keyword_25_orgs.xls’
$book.write ‘E:\Selva-Backup\testwise-xls\keyword_25_orgs.xls’
$sheet1 = $book.worksheet ‘Sheet1′
#book = Spreadsheet.open(“test.xls”)
# edit file
#$book.write(“E:\Selva-Backup\testwise-xls\temp_test.xls”)
#book = open_book(“E:\Selva-Backup\testwise-xls\temp_test.xls”)
#FileUtils.rm(“E:\Selva-Backup\testwise-xls\Keyword_25.xls”, :force => true)
#book.write(“E:\Selva-Backup\testwise-xls\Keyword_25.xls”)

#$driver.find_element(:id=> “lst-ib”).send_keys(val)
# for i in 2..5
# title=$sheet1[i,4]
#call(title)
# end

describe “Test Suite” do
include TestHelper
before(:all) do
#@driver = $browser = Selenium::WebDriver.for(browser_type)
#@driver.navigate.to(http://cr1.qdxsoft.com/user/login)
$driver=Selenium::WebDriver.for(browser_type)
#@base_url=”http://192.168.10.72:3001&#8243;
@base_url=”http://cr.qdxsoft.com&#8221;
@accept_next_alert=true
@wait=Selenium::WebDriver::Wait.new(:timeout=>15)
$driver.get(@base_url+”/user/login”)
for i in 2..100
element=$sheet1[i,0]
method=$sheet1[i,1]
keyword=$sheet1[i,2]
data=$sheet1[i,3]
message=$sheet1[i,4]
#Choosing Locators#
id=$sheet1[i,7]
name=$sheet1[i,8]
linktext=$sheet1[i,9]
partiallink=$sheet1[i,10]
tagname=$sheet1[i,11]
classname=$sheet1[i,12]
xpath=$sheet1[i,13]
dom=$sheet1[i,14]
$sheet1[i,5]=”
$sheet1[i,5]=’FAIL’

if id
loc_type=”id”
loc_value=id
manufacturer_login(element,method,keyword,loc_type,loc_value,data,message,i)
elsif name
loc_type=”name”
loc_value=name
manufacturer_login(element,method,keyword,loc_type,loc_value,data,message,i)
elsif linktext
loc_type=”linktext”
loc_value=linktext
manufacturer_login(element,method,keyword,loc_type,loc_value,data,message,i)
elsif partiallink
loc_type=”partiallink”
loc_value=partiallink
manufacturer_login(element,method,keyword,loc_type,loc_value,data,message,i)
elsif tagname
loc_type=”tagname”
loc_value=tagname
manufacturer_login(element,method,keyword,loc_type,loc_value,data,message,i)
elsif classname
loc_type=”classname”
loc_value=classname
manufacturer_login(element,method,keyword,loc_type,loc_value,data,message,i)
elsif xpath
loc_type=”xpath”
loc_value=xpath
manufacturer_login(element,method,keyword,loc_type,loc_value,data,message,i)
elsif dom
loc_type=”dom”
loc_value=dom
manufacturer_login(element,method,keyword,loc_type,loc_value,data,message,i)
else
loc_value=””
loc_type=””
manufacturer_login(element,method,keyword,loc_type,loc_value,data,message,i)
end

end

end
it “” do
end

after(:all) do
#@driver.quit unless debugging?
end

end

############# keyword_01_spec.rb ################################

############# test_helper.rb ################################
require ‘rubygems’
require ‘selenium-webdriver’
require ‘rspec’
#require ‘activerecord’
require ‘mysql2’
require ‘dbi’
require ‘spreadsheet’
require ‘fileutils’
#require ‘roo’

# use utils in RWebSpec and better integration with TestWise
require “#{File.dirname(__FILE__)}/rwebspec_utils.rb”
require “#{File.dirname(__FILE__)}/testwise_support.rb”

# this loads defined page objects under pages folder
require “#{File.dirname(__FILE__)}/pages/abstract_page.rb”
Dir[“#{File.dirname(__FILE__)}/pages/*_page.rb”].each { |file| load file }

# The default base URL for running from command line or continuous build process
$BASE_URL = “”

# This is the helper for your tests, every test file will include all the operation
# defined here.
module TestHelper

include RWebSpecUtils
include TestWiseSupport

#
# An Example helper function
#
# In you test case, you can use
#
# login_as(“homer”, “Password”)
# login_as(“bart”) # the password will be default to ‘TestWise’
# login(“lisa”) # same as login_as
#
#
# def login_as(username, password = “TestWise”)
# enter_text(“username”, username)
# enter_text(“password”, password)
# click_link(“Login”)
# end
# alias login login_as

def browser_type
if $TESTWISE_BROWSER then
$TESTWISE_BROWSER.downcase.to_sym
elsif ENV[“BROWSER”]
ENV[“BROWSER”].downcase.to_sym
else
RUBY_PLATFORM =~ /mingw/ ? “ie”.to_sym : “firefox”.to_sym
end
end
alias the_browser browser_type

def site_url(default = $BASE_URL)
$TESTWISE_PROJECT_BASE_URL || ENV[‘BASE_URL’] || default
end

def driver
@driver
end
alias browser driver

def page_text
driver.find_element(:tag_name => “body”).text
end

########### Selva Game Start ##################
def manufacturer_login(element,method,keyword,loc_type,loc_value,data,message,i)
#$driver.find_element(:id, “membership”).send_keys element
case element
when “TextBox”
case method
when “Type”
case loc_type
when “id”
message=message.downcase
if message.include?(“numeric”)
data=data.to_i
$driver.find_element(:id, loc_value).send_keys(data) if $driver.find_element(:id, loc_value).displayed?
#$sheet1.row(i).insert 5, ‘PASS’
$sheet1[i,5]=’PASS’
#$book.write ‘E:\Selva-Backup\testwise-xls\keyword_25_orgs.xls’
else
$driver.find_element(:id, loc_value).send_keys(data) if $driver.find_element(:id, loc_value).displayed?
#$sheet1.row(i).insert 5, ‘PASS’
$sheet1[i,5]=’PASS’
#$book.write ‘E:\Selva-Backup\testwise-xls\keyword_25_orgs.xls’
end
when “name”
message=message.downcase
if message.include?(“numeric”)
data=data.to_i
$driver.find_element(:name, loc_value).send_keys(data) if $driver.find_element(:name, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
$driver.find_element(:name, loc_value).send_keys(data) if $driver.find_element(:name, loc_value).displayed?
$sheet1[i,5]=’PASS’
end
when “linktext”
message=message.downcase
if message.include?(“numeric”)
data=data.to_i
$driver.find_element(:linktext, loc_value).send_keys(data) if $driver.find_element(:linktext, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
$driver.find_element(:linktext, loc_value).send_keys(data) if $driver.find_element(:linktext, loc_value).displayed?
$sheet1[i,5]=’PASS’
end
when “partiallink”
message=message.downcase
if message.include?(“numeric”)
data=data.to_i
$driver.find_element(:partiallink, loc_value).send_keys(data) if $driver.find_element(:partiallink, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
$driver.find_element(:partiallink, loc_value).send_keys(data) if $driver.find_element(:partiallink, loc_value).displayed?
$sheet1[i,5]=’PASS’
end
when “tagname”
message=message.downcase
if message.include?(“numeric”)
data=data.to_i
$driver.find_element(:tagname, loc_value).send_keys(data) if $driver.find_element(:tagname, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
$driver.find_element(:tagname, loc_value).send_keys(data) if $driver.find_element(:tagname, loc_value).displayed?
$sheet1[i,5]=’PASS’
end
when “classname”
message=message.downcase
if message.include?(“numeric”)
data=data.to_i
$driver.find_element(:classname, loc_value).send_keys(data) if $driver.find_element(:classname, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
$driver.find_element(:classname, loc_value).send_keys(data) if $driver.find_element(:classname, loc_value).displayed?
$sheet1[i,5]=’PASS’
end
when “xpath”
message=message.downcase
if message.include?(“numeric”)
data=data.to_i
$driver.find_element(:xpath, loc_value).send_keys(data) if $driver.find_element(:xpath, loc_value).displayed?
#$sheet1.row(i).insert 5, ‘PASS’
$sheet1[i,5]=’PASS’
#$book.write ‘E:\Selva-Backup\testwise-xls\keyword_25_orgs.xls’
else
$driver.find_element(:xpath, loc_value).send_keys(data) if $driver.find_element(:xpath, loc_value).displayed?
#$sheet1.row(i).insert 5, ‘PASS’
$sheet1[i,5]=’PASS’
#$book.write ‘E:\Selva-Backup\testwise-xls\keyword_25_orgs.xls’
end
when “dom”
message=message.downcase
if message.include?(“numeric”)
data=data.to_i
$driver.find_element(:dom, loc_value).send_keys(data) if $driver.find_element(:dom, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
$driver.find_element(:dom, loc_value).send_keys(data) if $driver.find_element(:dom, loc_value).displayed?
$sheet1[i,5]=’PASS’
end
else
end
#$driver.find_element(:id, “firstuserid”).send_keys(“Correct”)
else
end
when “Link”
case method
when “Click”
case loc_type
when “id”
$driver.find_element(:id, loc_value).click if $driver.find_element(:id, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “name”
$driver.find_element(:name, loc_value).click if $driver.find_element(:name, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “linktext”
$driver.find_element(:link, loc_value).click if $driver.find_element(:link, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “partiallink”
$driver.find_element(:partiallink, loc_value).click if $driver.find_element(:partiallink, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “tagname”
$driver.find_element(:tagname, loc_value).click if $driver.find_element(:tagname, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “classname”
$driver.find_element(:classname, loc_value).click if $driver.find_element(:classname, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “xpath”
$driver.find_element(:xpath, loc_value).click if $driver.find_element(:xpath, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “dom”
$driver.find_element(:dom, loc_value).click if $driver.find_element(:dom, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
end
#$driver.find_element(:id, “firstuserid”).send_keys(“Correct”)
else
end
when “List”
case method
when “Click”
case loc_type
when “id”
Selenium::WebDriver::Support::Select.new($driver.find_element(:id, loc_value)).select_by(:text, data) if $driver.find_element(:id, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “name”
Selenium::WebDriver::Support::Select.new($driver.find_element(:name, loc_value)).select_by(:text, data) if $driver.find_element(:name, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “linktext”
Selenium::WebDriver::Support::Select.new($driver.find_element(:link, loc_value)).select_by(:text, data) if $driver.find_element(:link, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “partiallink”
Selenium::WebDriver::Support::Select.new($driver.find_element(:partial_link, loc_value)).select_by(:text, data) if $driver.find_element(:partial_link, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “tagname”
Selenium::WebDriver::Support::Select.new($driver.find_element(:tag, loc_value)).select_by(:text, data) if $driver.find_element(:tag, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “classname”
Selenium::WebDriver::Support::Select.new($driver.find_element(:class, loc_value)).select_by(:text, data) if $driver.find_element(:class, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “xpath”
Selenium::WebDriver::Support::Select.new($driver.find_element(:xpath, loc_value)).select_by(:text, data) if $driver.find_element(:xpath, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “dom”
Selenium::WebDriver::Support::Select.new($driver.find_element(:dom, loc_value)).select_by(:text, data) if $driver.find_element(:dom, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
end
#$driver.find_element(:id, “firstuserid”).send_keys(“Correct”)
else
end
when “Button”
case method
when “Click”
case loc_type
when “id”
$driver.find_element(:id, loc_value).click if $driver.find_element(:id, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “name”
$driver.find_element(:name, loc_value).click if $driver.find_element(:name, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “linktext”
$driver.find_element(:linktext, loc_value).click if $driver.find_element(:linktext, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “partiallink”
$driver.find_element(:partiallink, loc_value).click if $driver.find_element(:partiallink, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “tagname”
$driver.find_element(:tagname, loc_value).click if $driver.find_element(:tagname, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “classname”
$driver.find_element(:classname, loc_value).click if $driver.find_element(:classname, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “xpath”

begin
$driver.find_element(:xpath, loc_value).click if $driver.find_element(:xpath, loc_value).displayed?
$sheet1[i,5]=’PASS’
return true
rescue
return false
end
when “dom”
$driver.find_element(:dom, loc_value).click if $driver.find_element(:dom, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
end
#$driver.find_element(:id, “firstuserid”).send_keys(“Correct”)
else
end
when “Text”
case method
when “Type”
case loc_type
when “id”
$driver.find_element(:id, loc_value).click if $driver.find_element(:id, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “name”
$driver.find_element(:name, loc_value).click if $driver.find_element(:name, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “linktext”
$driver.find_element(:linktext, loc_value).click if $driver.find_element(:linktext, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “partiallink”
$driver.find_element(:partiallink, loc_value).click if $driver.find_element(:partiallink, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “tagname”
$driver.find_element(:tagname, loc_value).click if $driver.find_element(:tagname, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “classname”
$driver.find_element(:classname, loc_value).click $driver.find_element(:classname, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “xpath”
$driver.find_element(:xpath, loc_value).click if $driver.find_element(:xpath, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “dom”
$driver.find_element(:dom, loc_value).click if $driver.find_element(:dom, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
end
#$driver.find_element(:id, “firstuserid”).send_keys(“Correct”)
else
end
when “Radio”
case method
when “Click”
case loc_type
when “id”
$driver.find_element(:id, loc_value).click if $driver.find_element(:id, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “name”
$driver.find_element(:name, loc_value).click if $driver.find_element(:name, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “linktext”
$driver.find_element(:linktext, loc_value).click if $driver.find_element(:linktext, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “partiallink”
$driver.find_element(:partiallink, loc_value).click if $driver.find_element(:partiallink, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “tagname”
$driver.find_element(:tagname, loc_value).click if $driver.find_element(:tagname, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “classname”
$driver.find_element(:classname, loc_value).click if $driver.find_element(:classname, loc_value).dispalayed?
$sheet1[i,5]=’PASS’
when “xpath”
$driver.find_element(:xpath, loc_value).click if $driver.find_element(:xpath, loc_value).displayed?
$sheet1[i,5]=’PASS’
when “dom”
$driver.find_element(:dom, loc_value).click if $driver.find_element(:dom, loc_value).displayed?
$sheet1[i,5]=’PASS’
else
end
#$driver.find_element(:id, “firstuserid”).send_keys(“Correct”)
else
end
when “CheckBox”
case method
when “Click”
case loc_type
when “id”
$driver.find_element(:id, loc_value).click if $driver.find_element(:id, loc_value).displayed? #if $driver.find_element(:id, loc_value).selected?
$sheet1[i,5]=’PASS’
when “name”
$driver.find_element(:name, loc_value).click if $driver.find_element(:name, loc_value).displayed? #if $driver.find_element(:id, loc_value).selected?
$sheet1[i,5]=’PASS’
when “linktext”
$driver.find_element(:link, loc_value).click if $driver.find_element(:link, loc_value).displayed?#if $driver.find_element(:id, loc_value).selected?
$sheet1[i,5]=’PASS’
when “partiallink”
$driver.find_element(:partial_link, loc_value).click if $driver.find_element(:partial_link, loc_value).displayed?#if $driver.find_element(:id, loc_value).selected?
$sheet1[i,5]=’PASS’
when “tagname”
$driver.find_element(:tag, loc_value).click if $driver.find_element(:tag, loc_value).displayed? #if $driver.find_element(:id, loc_value).selected?
$sheet1[i,5]=’PASS’
when “classname”
$driver.find_element(:class, loc_value).click if $driver.find_element(:class, loc_value).displayed? #if $driver.find_element(:id, loc_value).selected?
$sheet1[i,5]=’PASS’
when “xpath”
$driver.find_element(:xpath, loc_value).click if $driver.find_element(:xpath, loc_value).displayed? #if $driver.find_element(:id, loc_value).selected?
$sheet1[i,5]=’PASS’
when “dom”
$driver.find_element(:dom, loc_value).click if $driver.find_element(:dom, loc_value).displayed? #if $driver.find_element(:id, loc_value).selected?
$sheet1[i,5]=’PASS’
else
end
#$driver.find_element(:id, “firstuserid”).send_keys(“Correct”)
else
end
when “Browser”
$base_url=”http://cr1.qdxsoft.com&#8221;
$driver = Selenium::WebDriver.for :data, :profile => profile
case method
when “get”
$driver.get($base_url+”/user/login”)
$sheet1[i,5]=’PASS’
when “navigate”
$driver.get($base_url+”/user/login”)
$sheet1[i,5]=’PASS’
when “close”
$driver.quit
$sheet1[i,5]=’PASS’
else
end
when “Div”
#do something
when “ErrorMsg”
case method
when “Alert”
begin
sleep 2
alert =$driver.switch_to.alert
alert.accept
return true
$sheet1[i,5]=’PASS’
rescue
puts “No alert present.”
return false
end

# alert =$driver.switch_to.alert
# if alert
# sleep 2
# alert.accept
# else
# return false
# end

#sleep 5
#sleep 2
# alerts1=$driver.switch_to.alert
# sleep 2
# alerts1.accept if alerts1
# sleep 2
# alerts2=$driver.switch_to.alert
# sleep 2
# alerts2.accept if alerts2

else
end
when “PopUp”
#do something
when “Element”
#do something
else
#do default case
end
#$book.write ‘E:\Selva-Backup\testwise-xls\keyword_25_orgs.xls’
end

#def params(Element,Method,Keyword,Data)
# $driver.find_element(:id, “membership”).clear
# $driver.find_element(:id, “membership”).send_keys Element
# $driver.find_element(:id, “firstuserid”).clear
# $driver.find_element(:id, “firstuserid”).send_keys Method
# $driver.find_element(:id, “password”).clear
# $driver.find_element(:id, “password”).send_keys Keyword
# $driver.find_element(:xpath, “.//input[@value=’Login’]”).click
#end
$book.write ‘E:\Selva-Backup\testwise-xls\keyword_25_orgs.xls’
end

########### Selva Game Continue ##################

############# test_helper.rb ################################

Spreadsheet Gem Ruby Windows[Errno::EACCESS(Permission denied)]

If your getting permission denied error using SpreadSheet gem in windows linux.Please follow the given example.
Example 1:-
require ‘spreadsheet’
Spreadsheet.client_encoding = ‘UTF-8’
$book=Spreadsheet.open ‘D:\testing_02.xls’
$sheet1 = $book.worksheet ‘Sheet1’
val=$sheet1[1,0]
$driver.find_element(:id, “lst-ib”).send_keys(val)

OR
Example 2:-
require ‘spreadsheet’
Spreadsheet.client_encoding = ‘UTF-8’
Spreadsheet.open ‘D:\testing_02.xls’ do |book|
$sheet1 = book.worksheet ‘Sheet1’
val=$sheet1[4,0]
$driver.find_element(:id, “lst-ib”).send_keys(val)
end
Related Links:-
http://spreadsheet.rubyforge.org/GUIDE_txt.html
http://makandracards.com/makandra/5361-how-to-create-excel-sheets-with-spreadsheet-gem-and-use-number-formats-for-cells-like-money-or-date
http://findnerd.com/list/view/Removing-file-using-Spreadsheet-in-windows-ErrnoEACCESSPermission-denied/457/

How to Access MySql database in Testwise tool

Here, i explained how to access mysql database in testwise tool.Please find the below details

load File.dirname(__FILE__) + ‘/../test_helper.rb’

RSpec.describe “something” do
include TestHelper

before(:all) do
# my=ActiveRecord::Base.establish_connection(
# :adapter => “mysql”,
# :host => “192.168.10.18”,
# :username => “root”,
# :password => “password”,
# :database => “qadex_16Mar15”)

#sth = dbh.prepare(“select * from members where id=64”)
$client = Mysql2::Client.new(:host => “192.168.10.18”, :database => ‘qadex_16Mar15’, :username => “root”, :password => ‘password’)

#begin
# connect to the MySQL server
#dbh = DBI.connect(“DBI:Mysql2:qadex_16Mar15:192.168.10.18″,”root”, “password”)
# sth = dbh.prepare(“DELETE FROM members WHERE AGE > ?”)
# sth.execute(20)
# sth.finish
# dbh.commit
#rescue DBI::DatabaseError => e
# puts “An error occurred”
# puts “Error code: #{e.err}”
# puts “Error message: #{e.errstr}”
# dbh.rollback
#ensure
#disconnect from server
# dbh.disconnect if dbh
#end

#my = Mysql2.connect(“192.168.10.18”, “root”, “password”, “qadex_16Mar15”)

end

it “addition” do
results = $client.query(“SELECT * FROM members”)
results.each do |row|
print row
end
end

#it “is valid with a firstname, lastname and email” do
# contact = Member.new(
# title: ‘Billa’,
# content: ‘2007’,
# manufacturer: ‘Aaron’,
# supplier: ‘Sumner’,
# file_name: ‘testfile’)
# expect(contact).to be_valid
# comp_id= my.query(” SELECT * FROM members”)
# comp_id.each do |c|
# print c.title
# end # comp_id.each_hash do |c|
# product= my.query(” SELECT * FROM members”)
# product.each_hash do |p|
# @id=p[‘id’]
# @product_id=p[‘title’]
# puts “#{@id} : #{@product_id}”

#end
# begin
#db = Mysql.new(‘localhost’, ‘user’, ‘password’, ‘database’)
# db = Mysql.new(“192.168.10.18”, “root”, “password”, “qadex_16Mar15”)
#rescue Mysql::Error
# puts “Oh noes! We could not connect to our database. -_-;;”
# exit 1
#end
#db.query(‘select * from members where id=64’)
#end

it “creating a new member” do
$client.query(” insert into members(title,content,manufacturer,supplier,file_name)values(‘Testing’,’hi hello’,’Aaron’,’Sumner’,’testfile’)”)

end

end