1. Datatables:Trying to import excel data to datatables and making use of those values.--Solved
'file should be in the format of Excel 2003, i,e .xls format
'importing complete excel file
Datatable.Import ("C:\Users\sxkulkar\Documents\srikanthjk\Technical\QTP\Sample\Test1.xls")
Datatable.SetCurrentRow(2)
'value1=Datatable.Value(id,"Action1") 'throwing an error saying that the column 'Name' does not exist, but in real "Name" is 1st column.
value1 = Datatable.Value(2,2) 'working . But if you remove the import command at the top, thinking that after code is being excecuted multiple times table might have got imported, so no need to to import. But looks like we need to import the data everytime.
MsgBox(value1)
Services.StartTransaction "hi"
Err: Throwing Invalid file error at line no: 1 --- ie is due to file should be in 2003 format.
Solution:
Datatable.Import ("C:\Users\sxkulkar\Documents\srikanthjk\Technical\QTP\Sample\Test1.xls")
Datatable.SetCurrentRow(2)
value1 = Datatable.Value(2,2) ' here Test1.xls file has two sheets, now trying to access column: 2 of 'Sheet: 2.
MsgBox(value1)
2. Opening the Browser- Internet Explorer and navigating through web page. --- Solved.
I tried to record the to find out the code for opening browser and navigating through the web page.(covered Qno: 9)
But looks like QTP does not show up any code when you record for opening the browser ?
So I found the below code, this will open the browser enter the url and displays the page.
Set o1= Createobject("InternetExplorer.Application")
o1.Visible = true
o1.Navigate "www.google.com"
Set o1 = nothing
OR
If DataTable.LocalSheet.GetCurrentRow = 1 Then
SystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com"
End If
3. End to End flow of an application that is being automated. (Login, navigating b/w pages, clicking objects in the pages displayed, collecting input values from datatable, using library function concept)
' Executefile to load the functions already created
ExecuteFile "C:\Users\sxkulkar\Documents\srikanthjk\Technical\QTP\Handson\EndtoEnd sample flow\Library Functions\Open IE.vbs"
'Importing data tables, but i am not sure why data table got imported to Global sheet???
Datatable.Import("C:\Users\sxkulkar\Documents\srikanthjk\Technical\QTP\Handson\EndtoEnd sample flow\Data Table\User Credentials.xls")
'Generally code is iterated based on number of rows in datatable. Here also it was iterating but only '1st row is picked all the time.So wanted to create a loop.
Rows = Datatable.GetSheet("Global").GetRowCount
For i = 1 to Rows
Datatable.SetCurrentRow(i)
uid = Datatable.Value("Uid","Global")
pwd = Datatable.Value("Pwd","Global")
'directly using Calling fuction without declaring is due to function is already loaded.
Call OpenIE
Browser("Google").Page("Google").Link("Sign in").Click
MsgBox(uid)
MsgBox(pwd)
Browser("Google").Page("Sign in - Google Accounts").Link("Sign in with a different").Click
Browser("Google").Page("Sign in - Google Accounts").Link("Add account").Click
Browser("Google").Page("Sign in - Google Accounts").WebEdit("Email").Set uid
Browser("Google").Page("Sign in - Google Accounts").WebEdit("Passwd").Set pwd
Browser("Google").Page("Sign in - Google Accounts").WebButton("Sign in").Click
'Identifying diff objects
'Navigating b/w pages
'' search for Instagram
Browser("Google").Page("Google").WebEdit("q").Set "instagram"
Browser("Google").Page("Google").WebButton("Google Search").Click
'click Instagram link in the next page that got displayed
Browser("instagram - Google Search").Page("instagram - Google Search").Link("Instagram - Android Apps").Click
'unable to indentify the object and there are many WebElements on the page with the name "WebElement".?
Browser("instagram - Google Search").Page("Instagram - Android Apps").WebElement("WebElement").Click
'signing out
Browser("instagram - Google Search").Page("Instagram - Android Apps").WebElement("Sign out").FireEvent "onmouseover"
'Close the browser
Browser("instagram - Google Search").Page("Instagram - Android Apps").Link("Sign out").Click
Browser("instagram - Google Search").Close
Next
4. Working on Data tables, as we have few issues importing excel files into Global and Local sheets in Data table. And also iteration wise it is creating problem.
5. I do not know how Actions(Action1, Action2 .....) are created. I wanted to work on multiple actions at a time. Everytime when i open the script, by default it will pop up Action1.
6. Complete analysis on Mahipal's Framework, design the same framework with simple functionality.
7. Connecting QTP to Database. Extract values from DB and making use of the values. --Solved
Scenario 1:
' Tried the below code but getting an error due to odbc driver not installed.
Set conn1 = CreateObject("adodb.Connection")
Set rst1 = CreateObject("adodb.Recordset")
'conn1.Open "C:\Users\sxkulkar\Documents\Database1.accdb"
'conn1.Open
conn1.Open "Driver={Microsoft Access Driver (*.mdb),(*.accdb)};DBQ=C:\Users\sxkulkar\Documents\Database1.accdb;" 'error: Getting error "Data source name and drivers not found.
rst1.Open "Select * FROM TABLE1", conn1
'Do while not rst1.EOF
Msbox rst1.FIELDS("Description")
'Browser("Gmail").WebEdit("username").Set objRS.FIELDS("UN")
'Browser("Gmail").WebEdit("password").Set objRS.FIELDS("PW")
'Browser("Gmail").WebBotton("LogIn").CLICK
' rst1.MOVENEXT Loop
'Release created objects
Set rst1= NOTHING
Set conn1= NOTHING
' Tried odbc connection, to see if driver is already installed. Now going back and trying to install and add driver. And then will run the above code.
Scenario 2:
Set conn1 = CreateObject("adodb.Connection")
Set rst1 = CreateObject("adodb.Recordset")
DSN ="DSN=MS2007DB_Srikanth" conn1.open DSN
rst1.Open "Select * FROM Table1", conn1
Do while not rst1.eof
Msgbox rst1.FIELDS("ID")rst1.movenext
Loop
EX:
'Connecting to DB and parameterizing the test scripts using the DB
'I have already created DSN for the database that is stored in C drive - Mydocuments
'let me create db object for connection
Set objdb = CreateObject("adodb.Connection")
Set objrc = CreateObject("adodb.Recordset")
'DSN is created in ODBS System DSN section in ODBC drivers. Same name is given here.
DSN = "DSN=Sampledb"
objdb.Open DSN
objrc.Open "select * from Table1", objdb
' This does not make sense. As it gives me -1.
msgbox objrc.RecordCount
Do
msgbox objrc.Fields("User_ID")
msgbox objrc.Fields("Password")
objrc.MoveNext
Loop While not objrc.EOF
8. Unable to identify the object('your orders' object-under Account) properties for those displayed after mouseover.----solved
I was working on amazon site, and found that "your orders" is listed under "My Account" webelement. Whenever I used to mouse on the webelement, objectspy used to just capture that particular object but not the objects displayed after mouse over. Solution i have found out is record the navigation. Then i was able to. Here is the code.
Browser("Amazon.com: Online Shopping").Page("Amazon.com: Online Shopping").WebElement("Your Account").FireEvent "onmouseover"
Browser("Amazon.com: Online Shopping").Page("Amazon.com: Online Shopping").Link("Your Orders").Click 'this line of code i got it by recording the navigation.
9. Recording in multiple browsers:
I am not able to record in IE browser, it is throwing error. But i could record script.?
Sol: This is because i need to install patch for IE(similarly for other browsers too).
ReadMe file:
QTPWEB_00073 - Add Support for Internet Explorer in Protected Mode
QTPWEB_00078 - Add Support for Internet Explorer 9
QTPWEB_00101 - Fix Hang Related to QTPWEB_00073 Patch
Only after installing the patch, i was able to record ths script in IE9.
And for Mozilla, i dont see recorded script at all. ?
If you are running Windows7 you must have the QuickTest Pro patch “QTP_00699″ installed for complete Windows7 support.
useful: http://www.asi-test.com/ASI/working-with-qtp-and-firefox/
10. Compare two files.. (working for txt files but not for excel files) --- not resolved
Public FilePath1, FilePath2
FilePath1 = "C:\Users\sxkulkar\Documents\srikanthjk\GCOT Automation\File1.txt"
FilePath2 = "C:\Users\sxkulkar\Documents\srikanthjk\GCOT Automation\File2.txt"
'Call CompareFiles("C:\Users\sxkulkar\Documents\srikanthjk\GCOT Automation\GCOT - POC List.xlsx", "C:\Users\sxkulkar\Documents\srikanthjk\GCOT Automation\GCOT - POC_2 List.xlsx")
If CompareFiles(FilePath1, FilePath2) = False Then
MsgBox "Files are Identical"
Else
MsgBox "Files are different"
End If
Public Function CompareFiles (FilePath1, FilePath2)
Dim FS, File1, File2
Set FS = CreateObject("Scripting.FileSystemObject")
'Using FS object we can use many methods associated with it. http://qeworks.com/scripts-to-handle-folder-structure
'Size is one of the methods of object FS. Used to compare two files
'If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then
'CompareFiles = True
'Exit Function
'End If
'OpenAsTextStream Method - Opens a specified file and returns a TextStream object that can be 'used to read from, write to, or append to the file.
'Parareter 1 is for Reading and 0 Opens the file as ASCII
Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0)
Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0)
CompareFiles = False
'
Do While File1.AtEndOfStream = False
'Read method - Reads a specified number of characters from a TextStream file and returns the r'esulting string.
Str1 = File1.Read(1000)
Str2 = File2.Read(1000)
CompareFiles = StrComp(Str1, Str2, 0)
If CompareFiles <> 0 Then
CompareFiles = True
Exit Do
End If
Loop
File1.Close()
File2.Close()
End Function
10 . 'Script to read and write data from the file. Instead of reading date, we shall do file comparision and reading the text "Terms and conditions" in a file. ---- not solved
'To read data from the file or write to file we need FileSystemObject
Set fileobj = CreateObject("Scripting.FileSystemObject")
'Get access to the particular file
Set f = fileobj.GetFile("C:\Users\sxkulkar\Documents\srikanthjk\Technical\QTP\Handson\Terms and Conditions.txt")
'once you get the file object, you can get the path, name, size of the file i,e related properties of the file.
'Now since we wanted to get the content from the file
msgbox f.path
msgbox f.size
' Now its time to check whether it has th following text in the file
'we need OpenAsTextStream Method to help us read the file or write into it
Set rf = f.OpenAsTextStream(1, 0)
'this pops up with complete information thats available in the file
msgbox rf.ReadAll
'To read data from the file or write to file we need FileSystemObject
Set fileobj = CreateObject("Scripting.FileSystemObject")
'Get access to the particular file
Set f = fileobj.GetFile("C:\Users\sxkulkar\Documents\srikanthjk\Technical\QTP\Handson\Terms and Conditions.txt")
'once you get the file object, you can get the path, name, size of the file i,e related properties of the file.
'Now since we wanted to get the content from the file
msgbox f.path
msgbox f.size
' Now its time to check whether it has th following text in the file
'we need OpenAsTextStream Method to help us read the file or write into it
Set rf = f.OpenAsTextStream(1, 0)
'this pops up with complete information thats available in the file
msgbox rf.ReadAll
'failing here
txt = rf.ReadAll
'Now its time to check specific text in the file i,e to check if a clause is included in the tnc
Str ="AXP Internal"
' For i = 0 To rf.AtEndOfStream Step 1
if (InStr(txt, Str)) Then
msgbox "Text exist"
else
msgbox "Text does not exist"
End If
'Now its time to check specific text in the file i,e to check if a clause is included in the tnc
Str ="AXP Internal"
' For i = 0 To rf.AtEndOfStream Step 1
if (InStr(txt, Str)) Then
msgbox "Text exist"
else
msgbox "Text does not exist"
End If
No comments:
Post a Comment