Ask a Question

WordDocs.compare throw error on failure

SOLVED
lleppert
Contributor

WordDocs.compare throw error on failure

Hello,

 

I am using the WordDocs script extension to compare two word documents and it is working great. However, when the files do not match it throws a warning, and I need it to log an error instead. Anybody know how to do this? Here is my current code:

 

Sub CompareWordDocs(file1, file2)
      Call WordDocs.Compare(file1, file2, 2)
End Sub

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

Re: WordDocs.compare throw error on failure

Internally in the script extension, the code executed is the Files.Compare method.  A lot of the extension does the heavy lifting of manipulating the word documents in order to cleanly execute Files.Compare.  Files.Compare by default returns a warning message whenever the two files do not match. The script extension uses that default:

  var tempResult = Files.Compare(fullName1, fullName2);

So, the extension will always log a warning.  However, the extensions compare method returns a boolean so that WordDocs.Compare returns true if the files match or false if they do not:

 

  return tempResult && picEquals; 

What you can do is wrap your code with some if/then logic... something like this (untested):


Sub CompareWordDocs(file1, file2)
      Dim CompareResult
      CompareResult = Call WordDocs.Compare(file1, file2, 2)
      if !CompareResult
           Log.Error("The files are different")
End Sub

I'm not a very good VBScript coder so I'm sure my syntax above needs work but hopefully you get the idea.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

8 REPLIES 8
tristaanogre
Community Hero

Re: WordDocs.compare throw error on failure

Internally in the script extension, the code executed is the Files.Compare method.  A lot of the extension does the heavy lifting of manipulating the word documents in order to cleanly execute Files.Compare.  Files.Compare by default returns a warning message whenever the two files do not match. The script extension uses that default:

  var tempResult = Files.Compare(fullName1, fullName2);

So, the extension will always log a warning.  However, the extensions compare method returns a boolean so that WordDocs.Compare returns true if the files match or false if they do not:

 

  return tempResult && picEquals; 

What you can do is wrap your code with some if/then logic... something like this (untested):


Sub CompareWordDocs(file1, file2)
      Dim CompareResult
      CompareResult = Call WordDocs.Compare(file1, file2, 2)
      if !CompareResult
           Log.Error("The files are different")
End Sub

I'm not a very good VBScript coder so I'm sure my syntax above needs work but hopefully you get the idea.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

lleppert
Contributor

Re: WordDocs.compare throw error on failure

That worked! Thanks so much. Here is the syntax if anybody else needs it:

 

Sub CompareWordDocs(file1, file2)
     Dim CompareResult
     CompareResult = WordDocs.Compare(file1, file2, 1)


     If CompareResult = "True" then

          Log.Message("File " & file2 & " matches.")
     Else
          Log.Error("File " & file2 & " has changed.")       
     End If


End Sub

shilpawdhw
Occasional Contributor

Re: WordDocs.compare throw error on failure

Hi Can anyone help me

 

I executed above script . I am getting an error Object require wordDocs. I am using test complete 12

lleppert
Contributor

Re: WordDocs.compare throw error on failure

Hi shilpawdhw,

 

Do you have the script extension installed?

 

https://support.smartbear.com/viewarticle/17635/

shilpawdhw
Occasional Contributor

Re: WordDocs.compare throw error on failure

I installed script extension but still I am unable to make it . Throws an error saying Unable to open specified file

tristaanogre
Community Hero

Re: WordDocs.compare throw error on failure

Are you able to post your full code?  It's possible that there is something incorrect in how you are implementing it.  The file must be present, available, not-locked, not read only, and your pathing to it in code must be correct.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
shilpawdhw
Occasional Contributor

Re: WordDocs.compare throw error on failure

Thanks for your reply . I will try posting my code soon. I guess it is not working because the file is locked by user . I will work on that part if still issue persist will post my code here . Thanks again

tristaanogre
Community Hero

Re: WordDocs.compare throw error on failure

If the file is locked by user, that's certainly it.  The WordDocs.compare plug in utilizes the internal documentation comparison of MS Word which updates the document with notes, comments, etc.  It needs to be able to write to it.  If it cannot, then you will get errors.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: