Forum Discussion
- rraghvaniChampion Level 3
These two files may look the same,
But they are totally different. The first file contains a tab (->) character followed by carriage return (CR) and linefeed (LF). The second file just contains a space (.). ASCII characters are made visible by using Notepad++.
Byte-by-byte will compare the first character in the file, then the second, third, fourth and so on. If you've opened the file using Windows Notepad, the contents may look the same, but there's probably hidden characters which Notepad will not show.
- KittRegular Contributor
You do not need to store files within TestComplete to compare them, as long as your local file paths do not change you should be able to use their direct paths like so:
if (!Files.Compare("C:\\Work\\OrdersList_Var1.txt", "C:\\Work\\OrdersList.txt")) Log.Warning("List of orders was changed");
official TestComplete reference [here].
- TestQA1Frequent Contributor
Kitt I tried that but it says 'File is not defined' until I create a Store.
Instead I am using aqFile.Compare which works fine but the problem is that it seems to compare attributes of two files besides content. So for example, if my file1 has 'abc' and file2 also has 'abc' it fails the comparison until file2 is the copy of file1 which does not make sense. If I create file2 (i.e I do not copy/paste file1 and rename it to file2) the comparison fails.
Any idea what else the compare method checks besides content as my only requirement is to match content not any metadata.
Thanks
- TestQA1Frequent Contributor
Found aqFile that seems to be working, but it's showing that the files are different even though the contents are same. I think it's strickly looking for the same attributes not just content/data in the files.
Is there a possibility to only make aqFile check for similar data in files not any other attribute?
Thank you
- TestQA1Frequent Contributor
What if I write my own logic and don't use Compare methods.
I tried a below code but the loop seems to be running more than the indexes/lines I have in the first file and the values at index shows single character.
function CompareFiles() {
var firstFile = "abc.txt";
var secFile = "aac.txt";
for(let i =0; i<firstFile.length;i++) {
if(firstFile[i] !== secFile[i])
return true;
else {
return false;
}
}}
- rraghvaniChampion Level 3
The aqFile.Compare method, compares two files byte-by-byte.
Can you add those two files that fail to compare?
- TestQA1Frequent Contributor
rraghvani I have found a solution by writing my own logic w/o using Compare method.
As I mentioned in one of the old replies that the files are same in content:
FileA
[
abc
zzz
]
FileB
[
abc
zzz
]
But it only Pass if FileA is the copy of FileB by copypasting. If I created FileB without making a copy of FileA, it would have failed.
- AlexKarasChampion Level 3
Hi,
Check https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/opentextfile.html and https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/readwholetextfile.html help topic for the idea of custom text files comparison.
Regular expressions (e.g. https://support.smartbear.com/testcomplete/docs/reference/program-objects/hisutils/regexpr/replace.html) can be used if certain data inside files (e.g. dates/time/etc.) must be ignored during compare.
- TestQA1Frequent Contributor
Also could you briefly explain a byte-by-byte comparison please
Related Content
- 2 years ago
- 2 years ago
- 2 years ago
Recent Discussions
- 3 days ago