searching text files
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2010
11:34 AM
02-15-2010
11:34 AM
searching text files
I'm testing a product and want to create a checkpoint which can check for events within the product's log files while the product test runs.
The log files are simple text files with a time and date stamp on each line followed by the event eg:
16/02/10 12:01:17 Connecting to Server on 127.0.0.1 port 12001
16/02/10 12:01:17 Connected to Server
16/02/10 12:04:39 Error creating a new run
so far I have been opening the log in notepad and using a property check point similar to:
Call aqObject.CompareProperty(Aliases.notepad.wndNotepad.Edit.wText, cmpContains, "error connecting", false)
However obviously this is only good for checking if there has ever been an error anywhere in the log. Is there anyway I can check specific lines of a text file? For example could I use the aqDateTime.Time() to get the current time and then check if there is an error line in the log files at the current time (whilst ignoring any previous errors which might have occured)? Or is there another way I haven't thought of?
The log files are simple text files with a time and date stamp on each line followed by the event eg:
16/02/10 12:01:17 Connecting to Server on 127.0.0.1 port 12001
16/02/10 12:01:17 Connected to Server
16/02/10 12:04:39 Error creating a new run
so far I have been opening the log in notepad and using a property check point similar to:
Call aqObject.CompareProperty(Aliases.notepad.wndNotepad.Edit.wText, cmpContains, "error connecting", false)
However obviously this is only good for checking if there has ever been an error anywhere in the log. Is there anyway I can check specific lines of a text file? For example could I use the aqDateTime.Time() to get the current time and then check if there is an error line in the log files at the current time (whilst ignoring any previous errors which might have occured)? Or is there another way I haven't thought of?
3 REPLIES 3
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2010
06:56 PM
02-15-2010
06:56 PM
Hi Matthew,
You need to work with your log files directly via the aqFile object. It allows reading their contents as strings, you can either read the entire file at once or read it line by line. In the lines you obtain from a file, you can search for the needed values.
See the "Working With Files From Scripts" and "Working With Strings" help topics.
You need to work with your log files directly via the aqFile object. It allows reading their contents as strings, you can either read the entire file at once or read it line by line. In the lines you obtain from a file, you can search for the needed values.
See the "Working With Files From Scripts" and "Working With Strings" help topics.
------
Yuri
TestComplete Customer Care Engineer
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Yuri
TestComplete Customer Care Engineer
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2010
07:53 AM
02-16-2010
07:53 AM
thanks for that. although I tried opening my log files using the line
logfile = aqFile.OpenTextFile(AFileName, aqFile.faRead, aqFile.ctANSI)
and this will work for a random text file I created but when I try and open the actual log files from my program I get a VB runtime error "could not open file". any idea what might be causing this?
logfile = aqFile.OpenTextFile(AFileName, aqFile.faRead, aqFile.ctANSI)
and this will work for a random text file I created but when I try and open the actual log files from my program I get a VB runtime error "could not open file". any idea what might be causing this?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2010
07:54 AM
02-16-2010
07:54 AM
I just tried again using the FileSystemObject instead of the aqFile object and it seems to work now...
