Wednesday, May 20, 2015

Object Identification and tips



- Make use of regular expression


How to handle properties which are dynamic ?
There is an option to replace the property value with a Repository parameter. In this way you can handle the dynamic values for the properties.
In order to do so you need to select the property you want to parameterize and then Select “”(<#>) button on the right side. You get the window “Repository Parameter”
Image 8
RepositoryParameter1
Image 9
RepositoryParameter2
The value can be a constant that is the same value as before. If you want you can add regular expressions to it.
Regular expression : It is a way to define the search criteria for the string. You can use special characters such “.”, “*”, “[]” etc to define the same.
For example : If you select “Regular Expression” checkbox and add “.*” to your string. So it will search for an object that has “alt” property starting with text “Google” and can have any number of characters after that.
Second way is to select the parameter from the datatable/Environment/Random Number. You can select the radio button “Parameter” and make appropriate settings.
Image 10
RepositoryParameter5
-

Source:

http://www.learnqtp.com/uft-object-identification-tips/

17 Things To Try When UFT Does Not Identify an Object:

QTP First

I have repeated this many times in the past and it is still remains the #1 object identification tip. While testing on any app, make sure QTP is opened first and then your application. QTP works by hooking into your application. If you open QTP after your application has started there are chances that QTP may not be able to identify objects.
qtp-object-identification-tips

Load relevant Add-ins

Make sure you have loaded ALL the relevant add-ins required for your Application Under Test (AUT).

Record and Run Settings

While working on web based applications, make sure Record and run test on any open browser is selected under Record > Record and run settings.

BHO Manager

Make sure BHO Manager in IE under Tools > Manage Add-Ons > Enable or Disable Addons is enabled.

Enable Extensions

If you are working on Firefox or Google chrome browser, don’t forget to enable browser extensions.
In case of Firefox go to Firefox menu > Add-ons > Extensions and enable Unified Functional Testing Extension .
For Chrome go to Tools > Extensions and enable Unified Functional Testing Agent.

QuickTest supports recording tests only on Microsoft Internet Explorer. It supports running tests on the following Web browsers:
➤ Microsoft Internet Explorer
➤ Netscape Browser
➤ Mozilla Firefox
➤ Applications with embedded Microsoft Internet Explorer Web browser controls

Disable Protected Mode

In IE, clear the Enable Protected Mode option under Tools > Internet Options > Security

User Account Control(UAC)

UAC was introduced in Windows Vista and continued in Win 7 and Win 8/8.1. UAC can interfere with your application. It is a good idea to disable it while working on QTP.
  • To turn-off UAC in Windows 7, go to Start Menu > Search for “Change User Account Settings” > Disable UAC
  • To turn-off UAC in Windows 8/8.1, you need to take help of registry. UI setting doesn’t truly turns-off UAC in Win 8/8.1. Hit Win + R key, type regedit and click OK. Navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\SystemFind the key: EbableLUA and change the Value Data value to 0

Zoom Level

Make sure the zoom level is set to 100% while testing in any browser. Check the illustration below on how zoom-level affects highlight object functionality in QTP. (Focus on the blinking black rectangle on the left once the Highlight button is clicked on the right.)
zoom
A shortcut key to get back to 100% zoom is Ctrl + 0 (that’s zero).

.Object Notation

There are times when identification properties are not enough to identify an object. You may make use of native properties in that case. Use .object notation to locate the erring property. Make sure to correctly identify it.

Low level recording

After you have exhausted all options you can try Low level recording. It’s not a good method from maintenance point of view but it may come handy at times.

My QTP has worked for ages identifying objects correctly, stopped working since yesterday

If something like that has happened probably there is some change in your browser or UFT software itself. Try to disable auto-updates on machines where QTP is installed.

Type property for WebButton class

If you’re testing cross browser, don’t use Type property to identify Webbutton class since the default value is different for IE (button) and Firefox (Submit).

Object with dynamic properties

If QTP was successfully able to identify object at record time but unable to identify the same object during replay time, there are chances that object properties are dynamic in nature. Make use of regular expression or parameterization to handle those dynamic values.

Version of Browser and Windows OS

Make sure the version of QTP you use supports the version of your browser and/or your Windows operating system. Check the complete UFT vs browser support matrix and UFT vs Windows support matrix.

Pop-up Window not identified?

Check this article

Install relevant patch

In case your application version is not supported by the version of QTP, keep an eye on various patches that HP comes up with from time to time. Check the complete support matrix of QTP/UFT with various technologies. We strive to keep this up-to-date.


Few websites that are usefull for object identification are:

http://www.learnqtp.com/uft-object-identification-tips/
http://www.learnqtp.com/category/object-identification-in-qtp/
http://www.learnqtp.com/understanding-enigmatic-to-and-ro-property/
http://www.learnqtp.com/qtp-unable-to-identify-pop-up-window/



 

- Webex Trainining notes:



What are Ordinal Identifiers ?

Sometimes there are series of objects with same class name and properties. Lets us say in a window there are series of checkboxes with the same set of properties. If we want to act on those objects we need to uniquely identify them so that QTP will be able to act on it.

An Ordinal Identifier assigns a numerical value to the test objects which indicates its location or order relative to its group. The Ordered value enables QTP to recognize it uniquely when the inbuilt properties are NOT sufficient to do so.

There are 3 Ordinal Identifiers in QTP that can be used in different context:

  • Index
  • Location
  • Creation Time

Index:

An object appearing first in the page/Window will have a smaller Index value when compared to another object that comes later in the same page/Window.


The Value of index for the group of text boxes will be as follows:

Object Name
Index Value
TextBox 1
0
TextBox 4
1
TextBox 2
2
TextBox 5
3
TextBox 3
4
TextBox 6
5

Location:

The Location property works vertically from top to bottom and from left to right. Hence for the same case, the value of location for the group of text boxes will be as follows:

Object Name
Index Value
TextBox 1
0
TextBox 2
1
TextBox 3
2
TextBox 4
3
TextBox 5
4
TextBox 6
5

Creation Time:

The Creation Time property holds good only for web based application. When we open 2 browser sessions of the same website, QTP will not be able to recognize the window as both the window will have the same set of properties. Hence we can use creation time with which QTP will be able to act on the window.

'Will have CreationTime value = 0
SystemUtil.Run "iexplore.exe", "http://www.google.com"    
'Will have CreationTime value = 1 
SystemUtil.Run "iexplore.exe", "http://www.yahoo.com"     
'Will have CreationTime value = 2  
SystemUtil.Run "iexplore.exe", "http://www.microsoft.com" 
'Will have CreationTime value = 3 
SystemUtil.Run "iexplore.exe", "http://www.facebook.com"  

Hence to work on a specific browser, we need to explicitly mention the Creation time in OR or we can use description of objects which we will see in detail in descriptive programming section.

'Sync's www.google.com
Browser("creationtime:=" ).Sync                       
'Gets the RO text property of www.yahoo.com
Browser("creationtime:=1").GetROProperty("text") 
'Highlights microsoft.com
Browser("creationtime:=2").Highlight             


-
5/12/15:

Make sure your objects and respective properties are listed in the object repository before your script.

Even when you record your script, the objects will be stored in Object Repository.

So it is must to have the objects(of web application) stored in object repository, before you run your script on web application.

What are the different ways of identifying objects in a web page?

  11/6/2015

- One last option if the QTP/UFT does not recognize object is try using Virtual Object.

Virtual object -- there is seperate post in the same blog.




12/24/2015:

- DOM concept could also be used to identify objects in QTP. Refer DOM blog for the same.

Looks like object identification is based on the source code, so could be more easy for us as developers and testers refer to same source code. And we know to read source code.

Monday, May 18, 2015

Handling Database with QTP

- 7/9/15 -- -webex training notes
 
          Handling db using QTP:
QTP uses ADO – activex Data Objects
     To connect to Database QTP can be connected to any database.
    Frequently used commands:
    ADO Object
    RecordSetObject
    ConnectionString
    Execute
    Recordsetobject. EOF
    Note: EOF --- End of File 
    Recordsetobject.Fields.Item
    
  • ADO and Recordset objects are common for all DB.
  • Connection String – is different for different DB.
           Note: Go to www.connectionstrings.com
  • For Insert and Update Query we don’t need Recordset concept.
 

Database Connections

What is adodb connection ?
 
 
The ADO(ActiveX Data Objects) Connection object is used to create a connection to a data source. Through this connection, you can access and manipulate a database.
What is adodb recordset?
The ADO Recordset object is used to hold a set of records from a database table.To be able to read database data, the data should be loaded into a recordset.

QTP Scripts for connecting to MS Access:
Option Explicit
Dim con,rs
 
Set con=createobject("adodb.connection") 
Set rs=createobject("adodb.recordset")


con.open "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=;"

rs.open "select * from emp",con

Do while not rs.eof
VbWindow("Form1").VbEdit("val1").Set rs.fields("v1")
VbWindow("Form1").VbEdit("val2").Set rs.fields("v2")
VbWindow("Form1").VbButton("ADD").Click
rs.movenext
Loop

'Release objects'Release objects
Set rs= nothing
Set con= nothing

Note: The database we are using here is MS Access.Before running this script create a table in MS Acess.In the above script I used table called "emp" and column 'names as "v1" and "v2". "d:testdata.mdb" is path of the table which we created. The main use of this script is to use testdata of table(which is in ' database) in the application. In the above script we are passing values from database to Textboxes in Windows Application.



QTP Script for connecting to oracle:
Option Explicit
Dim con,rs

Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")

con.open "Driver={Microsoft ODBC for Oracle};Server=QTPWorld; Uid=your_username;Pwd=your_password;"
rs.open "select * from emp",con

Do while not rs.eof
VbWindow("Form1").VbEdit("val1").Set rs.fields("v1")
VbWindow("Form1").VbEdit("val2").Set rs.fields("v2")
VbWindow("Form1").VbButton("ADD").Click
rs.movenext
Loop

'Release objects
Set rs= nothing
Set con= nothing
 
Source: http://www.qtpworld.com/index.php?cid=74
------------------Well this website has descripting programming and PMP stuff.



----- Without datasource creation, one cannot connect using the script. Will receive following error if you try to execute above mentioned connection commands.

get error "Data source name not found and no default driver specified"

Reason why you will get the errro is explained in the following link:

http://www.easysoft.com/support/kb/kb01039.html


But if  you following below steps(Creat data source) you could avoid the mentioned error:


Setting Up an ODBC Data Source For MS Access


This example shows you how to set up a new ODBC connection to an MS Access database. The steps and screenshots will be similar but slightly different when you set up other supported databases.
Iguana supports some databases, such as MySQL and Oracle, through their native interfaces (i.e. not through ODBC). In such cases, the Data Source name specified in the channel configuration only needs to be the name of the database itself and no ODBC data source needs to be configured.

Every channel in Iguana needs to be associated with a database. At minimum, this database is used for logging the HL7 messages that flow across the interface. In many cases, the database also acts as a source or target for data mappings. In cases where you want to use an ODBC Database API for your channel, you will need to ensure that you have configured an appropriate ODBC data source.

To set up a new ODBC data source using MS Access:

  • Click Start > Settings > Control Panel > Administrative Tools > Data Sources (ODBC). The ODBC Data Source Administrator window appears.


ODBC Data Source Administrator Window

  • Click the System DSN tab, and click Add to create a new data source. The Create New Data Source window appears.




Create New Data Source Window

  • Select Microsoft Access Driver (*.mdb) and click Finish. The ODBC Microsoft Access Setup window appears.




ODBC Microsoft Access Setup Window

  • Enter the Data Source Name. In this example we created a data source called TestChannel.



Alternatively, you can choose an existing database by using the Select button. In addition you can access and configure other parameters, such as the Login name and Password fields, by clicking the Advanced button.

  • (Optional) Enter a description of your data source.
  • Under Database, click the Create button to create your database. The New Database window appears.




New Database Window

  • Enter the Database Name (e.g. TestChannel.mdb).
  • Choose where to save the database and click OK. A dialog window appears, confirming you have successfully created your database.



  • Click OK to complete the data source setup. Your newly created database appears under System Data Sources as shown below.




System Data Sources

Now you can easily add and configure a new channel for Iguana. For details, see Creating a Channel if you are using Iguana 4.0 or later, or Configuring Channels if you are using an older version of Iguana.

This is just an example. Source: http://www.interfaceware.com/manual/setting_up_odbc_datasource.html


Some more on the MSAccess drivers:

http://answers.microsoft.com/en-us/office/forum/officeversion_other-access/64-bit-driver-for-dsn-for-ms-access-database/be8c0ad4-d8fd-48e0-9026-b95d84135820

How to fix the MSAccess 2007 driver unavailability issue for Win 64 bit:
http://stackoverflow.com/questions/6721702/windows-7-64-bit-odbc-drivers-for-ms-access-missing

 
 

Monday, May 11, 2015

About QTP

üYou read about the common tasks that you need to do in order to write test scripts. These tasks are –
 
§ Identifying and Storing Objects.
§ Performing Operations on the Objects.
§ Handing Test Data in the Scripts.
§ Combining all operations to form Reusable & Non-Reusable Actions.
ü You also read how QTP can help you create test scripts using its various features like –
 
§ Object Spy and Object Repository.
§ Inbuilt Function Libraries.
§ Data Tables and related methods
§ Actions, Function Libraries and Scripted/Business Components.

Actions


An action (function) is a collection of operations that when combined form a logical business flow (such as Login, Logout, Search etc).There are 3 types of QTP actions:

  1. Reusable – only these can be called multiple times within the same or different      tests
  1. Non-reusable – These cannot be called by any other actions
  1. External actions – a reusable action when called from another action becomes an external action in the called action.
  • You can create New Actions for a test
  • Test Flow that gets generated while Action is created is just for reference and sometimes         disguises as Actions in the test flow show linkage but until unless you mention (Runaction  command) in the script you will not able to call actions.
  •        Right click on Action-> Go to Properties -> Select Checkbox(Reusable)
  •         Looks like Non Reusable Actions could not be called/ reused.
  •         By default all Actions are Reusable
  1. Looks like when action is pulled in to another test using call to existing action(Object Repository is disabled when called, and viewed in 'External action' folder) and call to copy of action (Object Repository is not disabled, viewed in same folder as that of current action), they will be created as sub actions in the main action.
  1. Syntax used to run the actions/subactions is: RunAction '<action name>', <No. of Iterations>
- Call to Copy of the action: -          Actions Contains:
  •       Script.mts – This file stores the code inside the action file
  •    ObjectRepository.bdb – This file stores the Local Per-Action object repository for the action
  •       Resource.mtr – This file contains neccessary information about the action (Reusable or not, Input/Parameters, Name, Description, Associate object repositories). This file is store in QTP proprietary format not know to anyone
  •      Snapshot – This folder contains all the Active screen related information about the Test 


     To run an action dynamically the only thing required is to execute its code present in Script.mts file. So below statement would run the Action:   Dynamic Action Call – Part 1   
   Actions have their own Datatables and OR, but functions don’t. More importantly, Functions are VBScripting element, not only applicable to QTP.











- Reusable Actions: Note:11/8/2015:Right click on Action -> Select Properties -> Select 'Reusable Action' checkbox.How to make action Reusable:      Actions that can be used in QTP scritp file into another Actions performed in action:
    Ex: Use RunAction method, to call actions from existing action. Create New action: Design - > Create New Action-         Copy the existing action, that exist in the present qtp file or copy from other qtp files – Design -> Copy of action-          RunAction – method is used to call other Actions from present action.

- We can useInsert->New ActionMake sure you select Reusable action checkbox is selected.(if it is a reusable action)Once Reusable action is created, using Insert option in menu select Call to existing action, browse the QTP script file that has reusable action, and then reusable actions from that file. So that those actions would be displayed in the script.Use Insert -> Copy of the actions. Select the the script file that has actions, then the script displayed in the new action is:RunAction 'Copy of Login", oneiteration  '"Copy of Login" is one of hte copy that is copied and copy is created in the actions list.       Action is nothing but a re-usable component. A saved QTP test script action consist of 4 components      Running an Action dynamically       ExecuteFile "<ActionFolderPath>\Script.mts"    Source: http://www.knowledgeinbox.com/articles/qtp/advanced-qtp/dynamic-action-call-part-1/
   Actions how are they different from Fucntions:




Handson


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(10)
Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(10)

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(10)
  '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