Wednesday, January 25, 2017

Investment banking, equities, trading.

Knowledge of Investment banking, equities, trading.

Good knowledge of investment banking, equities and Trading.
https://www.youtube.com/watch?v=xlYDonZLoHg

1. Retail bnaking - Morgages, loan, saving account ( 1 time investement will be get from customers)

2. Investment Banking - Jp Mordan, Goldman sach  ( Which has high risk )

What do Investement Banks Actually do? ( Risk activities)
  1. Prop Trading - they will do gambling the banks money to make profit.
  2. Market Making - Retail investor or investment bank will trade in the Stock exchange( Subjected to rules)
  3. M&A Advisory - Mergers & accocation - In airlies one company buy other company. ( When to buy)
  4. Corporate Events / New issues - To raise more capital ( When to raise the issue? \ How to sell? \ Underwriting will collect a fee \  XXX Million amount to raise)
  5. Structured Products - we need a procuts to sell in market - ie.  Leand a money for 2 years, get back with 18% interest )
                           Will have time and money involved.

https://www.youtube.com/watch?v=wTQMYg0LLFQ
* What is equity? - Are risky shares - Every financial year we will get dividen.
It's what a company is "worth"
It can also refer to the "Value" of your equity stake in a business

Preference Shares  - Assured returns as a divident based on the finical position.

* Trading Basics
https://www.youtube.com/watch?v=0O8uM9WE_RM
Individual markets are composed of various financial instruments
Bonds stocks currencies and commodities
Stocks - Prices move up and down according to supply and demand; more buy -up price \ more sell - down price
         Brokers helps to trade, we can do online as well.
different type of order -
Market order - offer price (place order) - as of now $550 - Buying for $540/- ( will get profit if we buy else minimum loss
limit order - Stop order - fixed price.

* Understanding Long and Short Terms in Stock Market Trading
https://www.youtube.com/watch?v=O__aZ4jxrJ8
Long - You are positive to go up in the market
Short - You are Negative to go Down in the market

I have nike In hand -> + 1000 - 500 Sold =  I will still have 500 in hand
I sold shares - 1000 and Purchase + 300 = - 700

------
* Stocks - Stock market - Where buying and selling of share\equities will happen here.
How The Stock Exchange Works (For Dummies)

* Currencies - Forex - Exchange of currencies - exchange rate Change based of supply and demand
( Mostly in USD )We can do online.
Global Currenciez: What Is Forex? - Foreign Exchange, Currency Trading Market
https://www.youtube.com/watch?v=-KoLWdk5dMs

Commodities - Commodities General Introduction - Real products ( Physical Commodities
https://www.youtube.com/watch?v=wVzi6902qUM&list=PLF089570B189A2BA4
Oil, gold, corn, cattle, life stocks - will be do by the traders

Furutres market  - Future contract
Standard furutre contract - 1000 Barrels of oil
we are just peclating the price of the product.

* FUTURES CONTRACT - a fuctures contract gives you the right to make or take DELIVERY of the physical commoditiy.
A futures contract has an EXPIRATION DATE and a FIRST NOTICE date.
If you still own the contract at the expiration date you will take delivery of commoditiy!

Based on the Seasonal Climate of the world.
Who actually trades the furutes marketfor the underlying commodity?
Crude oil is the best produt to do commodities!
  Eg. Southwest Airlines
      HEDGED(or Locked in) 70$ of thier crude oil requirements at a price of $51 a barrel
using Ftures contracts.

Their competitors who weren't hedged had to pay $120 a barrel!

2007 - Southwest Airlines secuted a significant competitive advantage by using the futures market.
$727 million in cost!.

Wednesday, January 11, 2017

Micro Focus UFT \ QTP Learnings, Challenges and Findings

Micro Focus UFT\ QTP Learnings, Challenges and Findings

''#######################################################################
''# Version 1.0 Dated 28/10/2011
''# Version 1.1 Dated 10/12/2011
''# Version 1.2 Dated 28/12/2011
''#######################################################################

1. TD80 folder to be cleared when we use QC with QTP.
2. Try to avoid using
SwfWin("regexpwntitle").value = "XXXABC 100 Asset Inventory"'
Regexpwntitle property in your code.... It might get clash with other object property
3. Notepad++ to check for the duplication, using compare option
4. Check for Menu Enable and Disable:
''#######################################################################
To Check the CheckOutAsset(s) is enable or disable in Menus
Window(Fwindow).Activate
VerifyHotKeys( "%Oc")
VerifyHotKeys( "{Enter}")

Set ChkOutAssWin = Description.Create
ChkOutAssWin("Class Name").value = "SwfWindow"
ChkOutAssWin("swfname").value = "CheckOutAssetForm"
Set ChkOutAssBut = Description.Create
ChkOutAssBut("Class Name").value = "SwfButton"
ChkOutAssBut("swfname").value = "btnCancel"

If SwfWindow(ChkOutAssWin).Exist Then
Reporter.ReportEvent micPass, "Check Out Asset(s) is Enabled", ""
'======
SwfWindow(ChkOutAssWin).Activate
Dim ChTxt1
ChTxt1 =SwfWindow(ChkOutAssWin).SwfButton(ChkOutAssBut).GetROProperty("Text")
Chactual = "&Cancel"
Reporter.ReportEvent micPass, "Actual Value :"+Chactual,"Expected Value :"+ChTxt1
SwfWindow(ChkOutAssWin).SwfButton(ChkOutAssBut).Type micAltDwn + "C" + micAltUp
'=======
Else
'It should be Failed but we are checking for the <Check out Assets > is Disable by micPass
Reporter.ReportEvent micPass, "Check Out Asset(s) is Disabled", ""
End If
'#######################################################################' To close the application
Window(Fwindow).Activate
VerifyHotKeys( "%FX")
VerifyHotKeys( "{Enter}")
''#######################################################################
'Hotkey Verifications
Public Function VerifyHotKeys(Keytopress)
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys Keytopress
Set WshShell = nothing
End Function
''#######################################################################

5. Dropdown Selection
a).
FC1=SwfWindow("XXXABC 100 Asset Accounting").SwfWindow("XXXABC 100 Asset Accounting").SwfObject("FieldCombo").Object.ListBox.FindStringExact(DataTable("LookIn",dtLocalSheet))
SwfWindow("XXXABC 100 Asset Accounting").SwfWindow("XXXABC 100 Asset Accounting").SwfObject("FieldCombo").Object.ListBox.SetSelected FC1,True

b).
Selecting a value from dropdown list.

Per=SwfWindow("XXXABC 100 Asset Accounting").SwfWindow("XXXABC 100 Asset Accounting").SwfObject("FieldCombo").Object.ListBox.FindStringExact("1st Year Business Use %")
SwfWindow("XXXABC 100 Asset Accounting").SwfWindow("XXXABC 100 Asset Accounting").SwfObject("FieldCombo").Object.ListBox.SetSelected Per,True
SwfWindow("XXXABC 100 Asset Accounting").SwfWindow("XXXABC 100 Asset Accounting").Activate
UpDown

Public Function UpDown
   VerifyHotKeysTab("{UP}")
   VerifyHotKeysTab("{DOWN}")
End Function

Public Function VerifyHotKeysTab(keytopress)
  Set WshShell = CreateObject("WScript.Shell")
  WshShell.SendKeys keytopress
  Set WshShell = nothing
End Function


6. i. Check – Check box and ii. Uncheck – Check box.

Functions for selecting multiple Checkbox can be selected.
SlctChkBox DataTable("RprtDef_Books",dtLocalSheet)

SlctChkBox(ChkBox)
Public Function SlctChkBox(ChkBox)
                                ChkBox = Split(ChkBox,",")
                                For i = 0 To UBound(ChkBox)
                                                SwfWindow("XXXABC 100 Asset Accounting").SwfObject("Tax").SetTOProperty "text", Trim(ChkBox(i))
                                                If SwfWindow("XXXABC 100 Asset Accounting").SwfObject("Tax").GetROProperty("checked") <> "True" Then
                                                SwfWindow("XXXABC 100 Asset Accounting").SwfObject("Tax").Click
                                                End If
                                Next     
               
End Function
Unchk chkbox
Functions where multiple Checkbox can be Unselected.

UnSlctChkBox DataTable("RprtDef_Books",dtLocalSheet)
UnSlctChkBox(ChkBox)
Public Function UnSlctChkBox(ChkBox)
                ChkBox = Split(ChkBox,",")
                For i = 0 To UBound(ChkBox)
                                SwfWindow("XXXABC 100 Asset Accounting").SwfObject("Tax").SetTOProperty "text", Trim(ChkBox(i))
                                If SwfWindow("XXXABC 100 Asset Accounting").SwfObject("Tax").GetROProperty("checked") <> "False" Then
                                SwfWindow("XXXABC 100 Asset Accounting").SwfObject("Tax").Click
                                End If

                Next     
End Function

7. Grid info
Window(oMainWinobj).SwfWindow(oChldWinobj).SwfObject("Class Name:=SwfObject","swfname:=GroupViewGrid").Click
Window(oMainWinobj).SwfWindow(oChldWinobj).SwfObject("Class Name:=SwfObject","swfname:=GroupViewGrid").Type micAltDwn + "s" + micAltUp
ActValue = Trim(Window(oMainWinObj).SwfWindow(oChldWinobj).SwfObject("Class Name:=SwfObject","swfname:=BookInfoGrid").Object.GetViewStyleInfo(18,2).CellValue)
print actvalue
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.WorkBooks.Open("C:\Documents and Settings\Administrator\Desktop\Sample.xls")
Set objSheet = objWorkbook.Worksheets("TestData")
ExpValue=objSheet.Range("C2").Value

If (ActValue=ExpValue)Then
Reporter.ReportEvent micPass, "Depreciation Calulated","Correct Answer"
Print "PASS"
Else
Reporter.ReportEvent micFail, "Depreciation Calulated","Wrong Answer"
Print "FAIL"
End If
8. ExtendSelect for list box
Dim MyString, MyArray

MyString = DataTable("Companies_list", dtLocalSheet)
msgbox MyString
MyArray = Split(MyString, ",")
Window("XXXABC 100 Asset Accounting").Dialog("XXXABC 100 Asset Accounting").WinList("Companies:").Select MyArray(0)

If UBound(MyArray) > 0 Then
For j = 1 To UBound(MyArray)
msgbox MyArray(j)
Window("XXXABC 100 Asset Accounting").Dialog("XXXABC 100 Asset Accounting").WinList("Companies:").ExtendSelect MyArray(j)
Next
End If

9. For Date entry by Type method
'Asset date set
Set MainXXXABC = description.Create
MainXXXABC("Class Name").value = "Window"
'MainXXXABC("regexpwndtitle").value = "XXXABC 100 Asset Accounting"
MainXXXABC("regexpwndclass").value = "AfxFrameOrView80"

Set AssetDetail = description.Create
AssetDetail("Class Name").value = "SwfWindow"
AssetDetail("swfname").value = "WorkingArea"
AssetDetail("regexpwndtitle").value = "Newt Global" ‘This for the Newt global company its specific.

Set ADTP = description.Create
ADTP("Class Name").value = "SwfObject"
ADTP("swfname").value = "AcquisitionDateTimePicker"
ADTP("swfname path").value = "AcquisitionDateTimePicker;;DetailSplitter;DetailTab;tabControlAdv1;DetailViewControls;WorkingArea;"

Window(MainXXXABC).Activate
Window(MainXXXABC).SwfWindow(AssetDetail).SwfObject(ADTP).Click
Window(MainXXXABC).SwfWindow(AssetDetail).SwfObject(ADTP).Type DataTable("Acquisition_Date", dtLocalSheet)

10. UI Validation
Public Function VerifyLabel()
Set swfWdw = Description.Create
swfWdw("Class Name").value = "SwfWindow"
swfWdw("nativeclass").value = "WindowsForms10.Window.8.app.0.33c0d9d"
swfWdw("regexpwndclass").value = "WindowsForms10.Window.8.app.0.33c0d9d"

Set LblObj = Description.Create
LblObj("Class Name").Value = "SwfLabel"
LblObj("nativeclass").Value = "WindowsForms10.STATIC.app.0.33c0d9d"
LblObj("regexpwndclass").Value = "WindowsForms10.STATIC.app.0.33c0d9d"

Set AppLbl = SwfWindow(swfWdw).ChildObjects(LblObj)

For i = 0 To AppLbl.Count -1
print AppLbl(i).GetRoProperty("text")
Next
End Function

11.
Method to Access the Group-View-Grids:
Call GetCelVal(2,2)

Public Function GetCelVal(row,col)
Window("XXXABC 100 Asset Accounting").Activate
'Getting all the Information about the cell
Print Window("XXXABC 100 Asset Accounting").SwfWindow("Asset Detail - Sample").SwfObject("gridControl1").Object.GetViewStyleInfo(row,col)
'Getting the particular information in a particular cell
Print Window("XXXABC 100 Asset Accounting").SwfWindow("Asset Detail - Sample").SwfObject("gridControl1").Object.GetViewStyleInfo(row,col).CellValue
End Function

For further reference



12. Common function for SwfEdit, SwfWindow, SwfButton …..
For Customize field window

SwfWindow(swfWindowFun).SwfEdit(SwfEditFun("maskedDefault")).Set "MCSM"
SwfWindow(swfWindowFun).SwfEdit(SwfEditFun("maskedDefault")).Type micTab
Wait(1)
SwfWindow(swfWindowFun).SwfButton(SwfButtonFun("&Cancel")).Click
'SwfWindow(swfWindowFun).SwfWindow(swfWindowFun).SwfButton(SwfButtonFun("&No")).Click

Public function SwfEditFun(sMskdef)
Set oSwfEdit = Description.Create
oSwfEdit("Class Name").Value = "SwfEdit"
oSwfEdit("nativeclass").Value = "WindowsForms10.EDIT.app.0.33c0d9d"
oSwfEdit("regexpwndclass").Value = "WindowsForms10.EDIT.app.0.33c0d9d"
oSwfEdit("swfname").Value = sMskdef
Set SwfEditFun = oSwfEdit
End Function

Public Function swfWindowFun()

Set oSwfWindow = Description.Create
oSwfWindow("Class Name").Value = "SwfWindow"
oSwfWindow("nativeclass").Value = "WindowsForms10.Window.8.app.0.33c0d9d"
oSwfWindow("regexpwndclass").Value = "WindowsForms10.Window.8.app.0.33c0d9d"
Set swfWindowFun = oSwfWindow

End Function


Public Function SwfButtonFun(sBtntxt)

Set oSwfButton = Description.Create
oSwfButton("Class Name").Value = "SwfButton"
oSwfButton("nativeclass").Value = "WindowsForms10.BUTTON.app.0.33c0d9d"
oSwfButton("regexpwndclass").Value = "WindowsForms10.BUTTON.app.0.33c0d9d"
oSwfButton("text").Value = sBtntxt
Set SwfButtonFun = oSwfButton

End Function

12.
Hex Editor- to update the QTP Pro.exe
http://www.hhdsoftware.com/Downloads/free-hex-editor

13.
'********************************************
'Label Validation function
'*******************************************
Public Function VerifyLabel()
Set swfWdw = Description.Create
swfWdw("Class Name").value = "SwfWindow"
swfWdw("nativeclass").value = "WindowsForms10.Window.8.app.0.33c0d9d"
swfWdw("regexpwndclass").value = "WindowsForms10.Window.8.app.0.33c0d9d"

Set LblObj = Description.Create
LblObj("Class Name").Value = "SwfLabel"
LblObj("nativeclass").Value = "WindowsForms10.STATIC.app.0.33c0d9d"
LblObj("regexpwndclass").Value = "WindowsForms10.STATIC.app.0.33c0d9d"

Set AppLbl = SwfWindow(swfWdw).ChildObjects(LblObj)

For j = 1 To DataTable.LocalSheet.GetRowCount
DataTable.LocalSheet.SetCurrentRow(j)
ExpectedLabel=DataTable("Labels", dtLocalSheet)
ActualLabel=AppLbl(j-1).GetRoProperty("text")
CompareValues "Label Validation - "+Cstr(ExpectedLabel),ExpectedLabel,ActualLabel
Next
End Function

Public Function CompareValues(Stepname,Expected,Actual)
If Expected=Actual Then
ReporterFun micPass,Stepname, Actual
else
ReporterFun micFail,Stepname, Actual
End If

End Function

'*******************************************************************************
'Reporter function
'********************************************************************************
Public Function ReporterFun(RptStatus, ResExp, ResAct)
Res = Split(ResExp,"-")
Reporter.ReportEvent RptStatus, ResExp, "Expected:-"&Res(1)&" Actual:-"&ResAct
End Function






Selecting a Item From Drop Down Listbox
There was a issues for selecting a particular Item from Drop Down Listbox
Where the dropdown was clicked but the Item which should be clicked will not be selected.

Previous Code was :
RR=SwfWindow(AppMainFunc("SwfWindow","ReportWindow")).SwfObject(AppMainFunc("SwfObject","GrouplistStdReport")).Object.ListBox.FindStringExact (GroupNameValue)
SwfWindow(AppMainFunc("SwfWindow","ReportWindow")).SwfObject(AppMainFunc("SwfObject","GrouplistStdReport")).Object.ListBox.SetSelected RR, True

Update Code: (Which works fine)

SwfWindow(AppMainFunc("SwfWindow","ReportWindow")).SwfObject(AppMainFunc("SwfObject","GrouplistStdReport")).Object.ListBox.ClearSelected
RR=SwfWindow(AppMainFunc("SwfWindow","ReportWindow")).SwfObject(AppMainFunc("SwfObject","GrouplistStdReport")).Object.ListBox.FindStringExact (GroupNameValue)
SwfWindow(AppMainFunc("SwfWindow","ReportWindow")).SwfObject(AppMainFunc("SwfObject","GrouplistStdReport")).Object.ListBox.SetSelected RR, True

Selecting the Date from the calendar dropdown
There was a issues in selecting the date from the calendar option and entering the date in the run time from data table. Where the focus didn’t fall on the particular Calendar dropdown and the entered date at the run time was not entered.

Code:
SwfWindow("XXXABC 100 Asset Accounting").SwfObject("dtpAdvRunDate").Object.Focus
VerifyHotKeysTab "%{DOWN}"
SwfWindow("SwfWindow").SwfObject("SwfObject").SetCurrentCell 1,7
SwfWindow("XXXABC 100 Asset Accounting").SwfObject("dtpAdvRunDate").Type DataTable("Other_Date",dtLocalSheet)

Code for using Object Repository in Functional Library:

sFileName = "C:\XXXABC Automation\UDF\ZebraOR_Ver1.12.vbs"


Set oFS = CreateObject("Scripting.Filesystemobject")
if bIsUnicode(sFileName) then
Set oFile = oFS.OpenTextFile(sFileName,,,true)
else
Set oFile = oFS.OpenTextFile(sFileName)
end if

ExecuteGlobal oFile.ReadAll()


Function bIsUnicode( byVal filename)
'heck for Unicode BOM in file.
Dim fso, ts, char1, char2
set fso = createobject("Scripting.FileSystemObject")
set ts = fso.opentextfile(filename)
char1 =ts.read(1)
char2 =ts.read(1)
ts.close
bIsUnicode = asc(char1) = 255 and asc(char2) = 254
End Function

Function for comparing two excel files:
Notes:
Goldencopy = Path of excel file 1
Generated Path = Path of excel file 2
Public Function ReportValidation(GoldenCopy,GeneratedReport)
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open (GoldenCopy)' Path to actual golden copy of the report
Set objWorkbook2= objExcel.Workbooks.Open(GeneratedReport) ' Path to expected exported report
Set objWorksheet1= objWorkbook1.Worksheets(1)
Set objWorksheet2= objWorkbook2.Worksheets(1)
Dim actual1
Dim expected
For Each cell In objWorksheet1.UsedRange
actual1=CStr(objWorksheet2.Range(cell.Address).Value)
expected=CStr(objWorksheet1.Range(cell.Address).Value)
If(CStr(cell.value) <> empty and CStr(actual1)<>empty ) then 'Allow only non empty cells
If CStr(cell.Value) <> actual1 Then
'objWorksheet2.Range(cell.Address).Interior.ColorIndex = 3 ' Highlights in red color if any changes in Expected result cells
Reporter.ReportEvent micFail, "Report Data :"&cell.Address&" "&expected,"Expected Value:- "&""""&expected&""""&chr(13)&" Actual Value :"&""""&actual1&""""
Else
'cell.Interior.ColorIndex = 0
Reporter.ReportEvent micPass, "Report Data :"+expected,"Expected Value:- "&""""&expected&""""&chr(13)&" Actual Value :"&""""&actual1&""""
End if
End If
Next
Set objExcel=nothing
objWorkbook2.Close
objWorkbook1.Close
End Function


Set the Date in View Reportng Period Dialog using “swfname” property value
SwfWindow(AppMainFunc("SwfWindow","DepreciateWindow")).SwfButton(AppMainFunc("SwfButton","ReportingPeriodButton")).Click
DtBookName  = Datatable("Books", dtLocalsheet)
SetForBookName = Split(DtBookName,",")
For i = 0 to Ubound(SetForBookName)
BookNameVal = "dateTimePicker"&SetForBookName(i)
If BookNameVal = "dateTimePickerCustom 1" Then
                                BookNameVal = "dateTimePickerBook6"
                                Else if BookNameVal = "dateTimePickerCustom 2" Then
                                                                                BookNameVal = "dateTimePickerBook7"
                                                                                End IF
End If
SetForBookNam = Replace(SetForBookName(i)," ","_")
dtDate  = "ViewReportingPeriod_"&SetForBookNam

Set SetBookName=SwfWindow(AppMainFunc("SwfWindow","ViewReportingPeriodWind")).SwfObject(DateObjFun(BookNameVal))
DateSetter SetBookName,dtDate
Next

Public Function DateObjFun(ObjName)
  Set oDateObjFun=description.Create
  oDateObjFun("Class Name").value="SwfObject"
  oDateObjFun("swfname").value=ObjName
  oDateObjFun("nativeclass").value="WindowsForms10.Window.8.app.0.33c0d9d"
  oDateObjFun("regexpwndclass").value="WindowsForms10.Window.8.app.0.33c0d9d"
  Set DateObjFun=oDateObjFun
End Function

Public Function DateSetter(DateBookname,dtDateName)
   If DateBookname.GetROProperty("enabled")=true then
                DateBookname.Type(Datatable(dtDateName,dtLocalsheet))
End if
End Function

This function is used to set the date by passing its “swfname”, As if we don’t have the text property value,
Ex: In the View Reporting Period Dialog. (But we should have the corresponding dataTable columns.)




To add the Data table sheets from external XL files.

DataTable.AddSheet("Sheet_Name")
DataTable.ImportSheet "C:\Documents and Settings\Administrator\Desktop\Depre_Consolidated_UDF.xls","Source_SheetName","Designation_SheetName"
msgbox DataTable("ColumnName","SheetName")

Using Validation function for UI Validation:
Conditions:
Go to your test folder
1. Copy and paste Default.xls file in your test folder
2. Rename that excel file to Particular Action Name e.g (Sabre_AA_TaxReports_ACEReport_Validation.xls)
3. Change the sheet name as per window name which we need to validate
(For uniformity we can give like this Windowname_UIValidationData
E.g: AdjustedCurrentEarningsForm_ UIValidationData)
4. Enter the columns in the following order
Label_Text – Should contains all the Labels text
Label_Enabled – Should contain enable property of the particular Label text (True or False) – You can leave blank if no need
Button_Text – Should contain Button texts
Button_Enabled - Should contain enable property of the particular button text (True or False) – You can leave flank if no need
Object_Text – Should contains objects text
Object_Enabled - Should contain enable property of the particular object text (True or False) – You can leave flank if no need
Editbox_Text – Should contain default text values in edit boxes
Editbox_SwfName – Should contains swfname for all available edit boxes in the particular window
Editbox_Enabled - Should contain enable property of the particular editboxs swfname (True or False) – You can leave blank if no need
Listbox_Text – Should contain selected text in the listbox
Listbox_ SwfName – Should contain swfname of the listbox
Listbox_Enabled – should contain enabled property of the particular listbox


Notes:
1.File should be available in particular test folder.
2.File name should be Action Name

Calling UI Validation function:
Function name: Validation(wnd_swfname,sheetname_source)
Arguments: wnd_swfname – Swfname of the particular window
sheetname_source – Sheet name in the ActionName.xls for particular window
Example: if we need to validate Customized fields form then
swfname = CustomizeFieldsForm,sheetname= CustomizeFieldsForm_UIValidationData
so we should call like this

Validation “CustomizeFieldsForm”,” CustomizeFieldsForm_UIValidationData”

Note:
1. The particular window should be opened before calling the function.



Code for the Validation function:


REM '*******************************************************************************
REM 'Validation function - Used to validate UI
REM '********************************************************************************
Public Function Validation(wnd_swfname,sheetname_source)
Sname = Split(wnd_swfname,",")
If UBound(Sname) > 0 Then
Arr = GetObProperties(Sname(0),Sname(1))
Else
Arr = GetObProperties("",Sname(0))
End If
ActionName=Environment("ActionName")
FileDir=Environment("TestDir")&"\"&ActionName&".xls"


DataTable.AddSheet("Validation")
DataTable.ImportSheet FileDir,sheetname_source,"Validation"
ChkPpt = Split("swflabel,swfbutton,swfobject,swfedit,swflist",",")
ChkPptDtName = Split("Label_Text,Button_Text,Object_Text,Editbox_Text,Listbox_Text",",")
ChkPptDtNameEnable=Split("Label_Enabled,Button_Enabled,Object_Enabled,Editbox_Enabled,Listbox_Enabled",",")
For k = 0 To UBound(ChkPpt)
For l=1 to DataTable.GetSheet("Validation").GetRowCount
DataTable.GetSheet("Validation").SetCurrentRow(l)
explbl=DataTable(ChkPptDtName(k),"Validation")
expenabled=DataTable(ChkPptDtNameEnable(k),"Validation")

ExittheFor = "Yes"
If ChkPpt(k) = "swfedit" or ChkPpt(k) = "swflist" Then
expswfname = DataTable(Replace(ChkPptDtName(k),"_Text","_SwfName"),"Validation")
If expswfname = empty Then
ExittheFor = "Yes"
Else
ExittheFor = "No"
End If
explbl = expswfname
End If

If ExittheFor = "Yes" and explbl=empty Then
Exit for
End If
status="fail"
For m = 0 To UBound(Arr)
ClName = Split(Arr(m),"^")
ActClName = Split(ClName(0),":=")
ActClNametxt = Split(ClName(1),":=")
ActClNameenabled = Split(ClName(2),":=")
ActCINameSwfname=Split(ClName(3),":=")
If LCase(ActClNametxt(1)) = LCase(explbl) Then
Status = "pass"
explbl1=Replace(explbl,"&","")
If Lcase(ActClName(1))="swfedit" or Lcase(ActClName(1))="swflist" Then
explbl1=ActCINameSwfname(1)
End If

'Compare the values for the text validation
CompareValues explbl1&" text validation ",Trim(LCase(explbl)),Trim(Lcase(ActClNametxt(1)))

If expenabled <>"" and LCase(ChkPpt(k)) <> "swfedit" and LCase(ChkPpt(k)) <> "swflist" Then
If Lcase(ActClNameenabled(1)) =Lcase(expenabled) Then
CompareValues explbl1&" enabled validation ",Lcase(expenabled),Lcase(ActClNameenabled(1))
Else
CompareValues explbl1&" enabled validation ",Lcase(expenabled),Lcase(ActClNameenabled(1))
End If
End If
If LCase(ChkPpt(k)) <> "swfedit" and LCase(ChkPpt(k)) <> "swflist" Then
Exit For
End If
End If

If ChkPpt(k) = "swfedit" or ChkPpt(k) = "swflist" Then
If LCase(ActCINameSwfname(1)) = LCase(expswfname) Then
Status = "pass"
CompareValues expswfname&" swfname validation ",expswfname,ActCINameSwfname(1)
If expenabled <>"" Then
If Lcase(ActClNameenabled(1)) =Lcase(expenabled) Then
CompareValues expswfname&" enabled validation ",Lcase(expenabled),Lcase(ActClNameenabled(1))
Else
CompareValues expswfname&" enabled validation ",Lcase(expenabled),Lcase(ActClNameenabled(1))
End If
End If
Exit For
End If
End If

If Status <> "pass" and m = UBound(Arr) Then
Status = "fail"
End If
Next
If Status="fail" Then
CompareValues explbl&" text validation ",explbl,explbl&" - NOT found in the application"
End If

Next
Next
End Function

REM '*******************************************************************************
REM 'Get Object Properties function - Used to get the object properties
REM '********************************************************************************
Public Function GetObProperties(MainWindow,SwfwdwName)

ppt = Split("Class Name,text,enabled,swfname",",")

If MainWindow <> "" Then
Set MainWdw = Description.Create
MainWdw("Class Name").value = "Window"
MainWdw("regexpwndclass").value ="AfxFrameOrView80"
End If

Set swfWdw = Description.Create
swfWdw("Class Name").value = "SwfWindow"
If SwfwdwName <>"" Then
swfWdw("swfname").value = SwfwdwName
End If

swObj = Split("SwfButton,SwfEdit,SwfObject,SwfList,SwfLabel,SwfEditor,SwfToolbar",",")
Dim ObjectArray() ' = Array(swfbtn,swfedt,swfobj,swflst,swflbl,swfedtr,swftlbar)
Dim MultiObjArray()
MultiObjArrCounter = 0
For q = 0 To UBound(swObj)
ReDim Preserve ObjectArray(q)
Set swfallobj = Description.Create
swfallobj("Class Name").value = swObj(q)
set ObjectArray(q) = swfallobj
Next

If MainWindow <> "" Then
Set Obj = Window(MainWdw).SwfWindow(swfWdw)
Else
Set Obj = SwfWindow(swfWdw)
End If

pptval = ""
For i = 0 To UBound(ppt)
If pptval = "" Then
pptval = ppt(i)&":="&Obj.GetROProperty(ppt(i))
Else
pptval = pptval&"^"&ppt(i)&":="&Obj.GetROProperty(ppt(i))
End If
Next

ReDim Preserve MultiObjArray(MultiObjArrCounter)
MultiObjArray(MultiObjArrCounter) = pptval


MultiObjArrCounter = MultiObjArrCounter + 1

For m = 0 To Ubound(ObjectArray)
Set Sbtn =Obj.ChildObjects(ObjectArray(m))
For j = 0 To Sbtn.Count -1
pptval = ""
For i = 0 To UBound(ppt)
If pptval = "" Then
pptval = ppt(i)&":="&Sbtn(j).GetROProperty(ppt(i))
Else
pptval = pptval&"^"&ppt(i)&":="&Sbtn(j).GetROProperty(ppt(i))
End If
Next
ReDim Preserve MultiObjArray(MultiObjArrCounter)
MultiObjArray(MultiObjArrCounter) = pptval
MultiObjArrCounter = MultiObjArrCounter + 1
Next
Next
GetObProperties = MultiObjArray
End Function

14.Code for Removing duplicate values from Array and Comparing Two arrays

b = Split("a,b,c,d,a,f,g,h,i,b,c,l",",")

e = Split("e,b,v,c,d,a,f,g,h,i,b,c,l,m,n,h",",")

c = RemoveDupArrVal(b) '/Removing Duplicates From Arary

d = RemoveDupArrVal(e) '/Removing Duplicates From Arary

ArrayComp c, d '/Comapring Two arrays


Public Function RemoveDupArrVal(ByRef arr)
Dim i, dict
If IsArray(arr) Then
Set dict = CreateObject("Scripting.Dictionary")
For i = 0 To UBound(arr)
'/Comparing the values with previous values if it not exist then adding in to dictonary obj
If Not dict.Exists(arr(i)) Then
Call dict.Add(arr(i), arr(i))
End If
Next
RemoveDupArrVal = dict.Items
End If
End Function









Public Function ArrayComp(ByRef arrA, ByRef arrB)
Dim i, dict
If IsArray(arrA) Then
Set dict = CreateObject("Scripting.Dictionary")
For i = 0 To UBound(arrA)
Call dict.Add(arrA(i), arrA(i))
Next
For i = 0 To UBound(arrB)
If Not dict.Exists(arrB(i)) Then
Reporter.ReportEvent micFail,arrB(i)&" - NOT found ","AssetList Value"&arrB(i)&"Not Found in SmartList"
End If
Next
End If
End Function


15.Code: Sorting value in txt file

Before Sorting

"C:\testfile.txt"
red-ws-02
atl-ws-01
sf-ws-02
atl-ws-02
atl-ws-03
red-ws-02
sf-ws-01



Dim Arrval1() ‘/Array Dec
FileDirPath="C:\testfile.txt" ‘/Txt file

Const adVarChar = 200
Const MaxCharacters = 255
Const ForReading = 1
Const ForWriting = 2






Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "ComputerName", adVarChar, MaxCharacters
DataList.Open

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FileDirPath,ForReading)


counter=1 ‘Dynamic Arry counter
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
DataList.AddNew
DataList("ComputerName") = strLine
DataList.Update
counter=counter+1 ‘inc array counter
Loop

objFile.Close

DataList.Sort = "ComputerName"

After Sorting Getting the Sorted Value from DataList
coun=0
DataList.MoveFirst
Do Until DataList.EOF
ReDim Preserve Arrval1(coun)
Arrval1(coun)=DataList.Fields.Item("ComputerName")
DataList.MoveNext
Loop

For l=0 To UBound(Arrval1)
print Arrval1(l)
Next

AfterSorting

atl-ws-01
atl-ws-02
atl-ws-03
red-ws-02
red-ws-02
sf-ws-01
sf-ws-02


16.Code :Writing value to txt file

Dim a(5)

a(0) = "Testing"
a(1) = "Testing1"
a(2) = "Testing2"
a(3) = "Testing3"
a(4) = "Testing4"

g = Join(a,vbcrlf)
WriteToLog "c:\Test",g

Public Function WriteToLog(WrDir,Msg)
FileExists = "False"
Dim sExt : sExt = UCase( "txt" )
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim sDir : sDir = WrDir
Dim oFile
Counter = 1
FileCount = oFS.GetFolder( sDir ).Files.Count

For Each oFile In oFS.GetFolder( sDir ).Files
If UCase( oFS.GetExtensionName( oFile.Name ) ) = sExt Then
'WScript.Echo oFile.Path
FileName = oFile.Name
If FileName = "Tmp.Txt" Then
FileExists = "True"
Exit For
End If
End If
Counter = Counter+1
Next

If FileExists <> "True" Then
oFS.CreateTextFile sDir&"\"&"Tmp.Txt"
End If
ResInfo = Msg
Set WriteResInfo = oFS.OpenTextFile(sDir&"\"&"Tmp.txt", 8, True)
WriteResInfo.WriteLine(ResInfo)
WriteResInfo.Close
SET WriteResInfo = NOTHING
SET oFS = NOTHING
End Function

QTP Learning’s and Findings in v2013 Non Profit Gov.

''#######################################################################
In XXXABC v2013 – Gov/Non Profit application, in Asset detail grid, we had a limitation to set the values in the particular cell. To overcome this we added space value prefixed with the input value, Changed the input format and finally, we found the solution by giving input as text format which has the 2 characters.

The Corresponding code and the Input value as follows.

RawVal = Datatable(DataColumName, dtLocalSheet)
SetVal = " "&Trim(RawVal)
Window(AppMainFunc("Window","AssetListMainWindow")).SwfWindow(AppMainFunc("SwfWindow","AssetDetail")).SwfObject(AppMainFunc("SwfObject","AssetDetailViewGrid")).SetCurrentCell Row,Clm
Window(AppMainFunc("Window","AssetListMainWindow")).SwfWindow(AppMainFunc("SwfWindow","AssetDetail")).SwfObject(AppMainFunc("SwfObject","AssetDetailViewGrid")).Type SetVal

''#######################################################################

How to identify dynamically changing objects in QTP:-
-----------------------------------------------------------------------
Consider an example where you are having a tree with nodes[can be folder or directory]. The tree as a whole is designed as a web table and subfolders again as a subweb table. It is easy to identify the index of the tree node while recording, but during playback when and additional folder or directory is added the index will be changed. In these kinds of situations where the index of the objects changes dynamically there are two actions to be performed

Identify the properties of the object
Identify the index at run time


Identify the properties of the object

Use object spy
Add the object to OR
Identify the index at run time

we can use the following piece of code once the properties are identified


For i = 0 to 1000
    set sObjTable = Browser("Browser").Page("Page").WebTable("index:="&i)
           If  Browser("Browser").Page("Page").WebTable("index:="&i).exist Then
                If sObjTable.GetROProperty("property name that is not changed") = <Value that is expected> Then
                        Set sRootFolder = sObjTable
                       
                 End if
            Else
                 Exit for
            End If

Next

In a similar manner, we can identify checkbox and radio button objects whose index changes at run time.
This worked for me hope it will be useful for you too.

Dynamic CheckBox:-
---------------------------
The proposal number is generated from steps before submission. What I've tried is to output value proposal number and assigned a variable to it as below:

Test #1:
'Comment: output value in eRefNo is 1001553EINB8D009
eRefNo = datatable.value("eReferenceNum",  dtGlobalSheet)
Window("Point of Sales").Page("Sales Force Automation_13").WebCheckBox(eRefNo ).Set "ON"


Test #2:
'Comment: use Chr(34) as the object properties seems to have "1001553EINB8D009 "
chkbox = Chr(34) & "value:=" & datatable.Value("eRefNo",dtGlobalSheet) &Chr(34)
Window("Point of Sales").Page("Sales Force Automation_13").WebCheckBox(chkbox ).Set "ON"

Orignal Script / Recorded:
Window("Point of Sales").Page("Sales Force Automation_13").WebCheckBox(" selectedItems").Set "ON"

Dynamic webradio :-
---------------------------
for i=1 to vr_QCount
Browser("aa").page("aa").webradiogroup("Name:=Question"&i, "html id:= Question_1_id").select
Next

Set Dp=Description.Create()
Dp(xx).Value=??(create description for webRadioGroup)
Vb_quesCount=Dp.Count
For i=1 to vb_quesCount
vb_QuesText=Dp(i).GetRoProperty
‘Code to search the vb_QuesText in datasheet and if exists( This U can do it ur self)

Browser(x).Page(y).webRadioGroup (‘Name :=’&vb_QuesText,’html id:=Question[‘&i&’].Answer.Id’).Select vb_Ans

Next