Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MS One Note 2010 support from QTP 11.0
#1
Solved: 11 Years, 4 Months, 2 Weeks ago
Hi,

In my application,there is a print operation.When the print command is given ,it goes to MS One note.Now what I need to do find a way to verify the printed content .For this I first need to read the information from MS One Note.
I searched over internet,but couldn't find a way to start this task .
Does there exist an object model for MS One Note like it is for MS word/excel? Can we read and verify the data from MS Note using QTP .
Please suggest .
Thanks,
Prachi
Reply
#2
Solved: 11 Years, 4 Months, 2 Weeks ago
Ankur or anyone,

if you have slightest idea,pls share..I am kind of stuck here with MS One Note Automation
Reply
#3
Solved: 11 Years, 4 Months, 2 Weeks ago
I don't have onenote installed on my machine so was not able to test this code...but thought might provide you with a ray of hope.

Code:
dim oneNote,pageStyle,importedPageID,unfiledPath,unfiledID
      set oNote = CreateObject("OneNote.Application")
       oNote.GetSpecialLocation 1,unfiledPath
       oNote.OpenHierarchy unfiledPath, "", unfiledID, 0
       oNote.CreateNewPage unfiledID,importedPageID, 0[/b][/b][/b][/b][/i]
       Dim xml2importBase 'As String
       xml2importBase = "<?xml version=""1.0""?><one:Section xmlns:one=""http://schemas.microsoft.com/office/onenote/2007/onenote"" ID="""
       xml2importBase = xml2importBase + unfiledID + """>"
       xml2importBase = xml2importBase + "<one:Page ID=""" + importedPageID + """>"
       xml2importBase = xml2importBase + "<one:Title><one:OE><one:T><![CDATA[Title Comes here-2]]></one:T></one:OE></one:Title>"
       Dim tailXml
       tailXml = "</one:Page></one:Section>"
       Dim xml2import
       xml2import = xml2importBase + tailXml
       oNote.UpdateHierarchy xml2import
       oNote.NavigateTo importedPageID, "", False

The line "set oNote = CreateObject("OneNote.Application")" tells use that OneNote does have an Object model but you have to explore more on the methods and properties which it provides.

Do let me know if that helped
Reply
#4
Solved: 11 Years, 4 Months, 2 Weeks ago
Thanks a lot Deepak Smile
I will surely run the code on monday and will let you know how it works.
Reply
#5
Solved: 11 Years, 4 Months, 2 Weeks ago
Hi Deepak,
This line gives syntax error:
expected end of the statement

oNote.CreateNewPage unfiledID,importedPageID, 0[/b][/b][/b][/b][/i]

Also,when I tried with oNote.CreateNewPage unfiledID,importedPageID, 0 to overcome the syntax error:

oNote.GetSpecialLocation 1,unfiledPath
oNote.OpenHierarchy unfiledPath, "", unfiledID, 0
oNote.CreateNewPage unfiledID,importedPageID, 0 ' '[/b][/b][/b][/b][/i]

Above 3 lines give Type mismatch error and below line gives general run error:

oNote.UpdateHierarchy xml2import

Are these errors because QTP supports VB script and VB scripting cannot be done for One Note methods.Pls suggest.

Thanks,
Prachi


*
Reply
#6
Solved: 11 Years, 4 Months, 2 Weeks ago
Hi.

Do you still need this?

The integration of OneNote with VBScript is not good so we can't directly see the OneNote print from QTP. But, there is another way that I have come across, which will actually export the last print received by OneNote from your application to pdf and show you the pdf. This way you can verify what your application printed in an automated way since QTP can talk to PDF.

Basically, how this will work is based on the following points:

1. When your application gives a print command to OneNote Printer, OneNote saves the data as an image under the "Unfiled Notes.one" file as a new page. This file is usually located at C:\Users\your_user_name\Documents\OneNote Notebooks

2. There is one utility called "OneNote2PDF", which can convert a OneNote file to pdf.

I have tested this on my machine and it works fine. First, I give a print command to OneNote, then run the utility and see how the print looks like.

If you think this suits your situation, I can attempt to package what I did in one small utility so you could just run it without going into details.

This can also be packaged as a QTP add-in to aid everyone in the same boat. Let me know if it's worth the effort.
Reply
#7
Solved: 11 Years, 4 Months, 2 Weeks ago
Thanks Light .

I am still in need of the solution and the way you suggested seems feasible.It would be helping if you can send here the package you have worked.
Reply
#8
Solved: 11 Years, 4 Months, 2 Weeks ago
Hello.

What do you want to do with the PDF once you have it?

1. To manually see it and then decide whether the checkpoint passes or fails? [One Manual Step]
2. To just attach it somehow to the Report Results for archival and bug reporting? [Auto]
3. To automatically look for a specific string in the pdf to ascertain the success of the checkpoint? [Auto]

I wrote a test script with just a single action to test my theory and it works. It assumes the first option above. Here is the test script:

Code:
Dim returnedStatusCode 'This is the variable that will hold the status of pdf conversion

outputDirectoryForPrintedPdf =  Reporter.ReportPath & "\PdfDocs"  'This is where the pdf would be generated; You can change this to suit your needs.

temporaryCacheFolder = Reporter.ReportPath & "\PdfCache"  'This cache will be deleted at the end of conversion but can also be kept through the switch -ClearCacheFinally False. You can change this to suit your needs.

nameOfPdfFile = Environment("ActionName") 'This will be the name of the pdf file generated under the folder:outputPathForPrintedPdf. You can change this to suit your needs.

pathToConversionUtil = "D:\OneNote2PDF\OneNote2PDF\bin\Debug\OneNote2PDF.exe" 'You have to specify the path where you have placed the executable in your machine..

Set oShell = CreateObject("Wscript.Shell") 'Let's get the shell object to run OneNote2PDF command-line utility. O' Shell, come to my rescue!

lastPrintedTime = CStr(Now) ' Capture the current time before proceeding to print

'Since we need the lasprintedtime to be our lower limit for pages, give the print command to the application here AFTER we have captured the current time.
msgbox "Here, printed through application and waited for printing to complete"

' Actually  run the command-line utility in the background and wait for the utility to return a code.
' ClearCacheFinally switch deletes the cache files generated during conversion at the end.
' UseUnfiled switch tells the program to use the "Unfiled Notes.one" file
' Output switch determines where the final merged pdf would be placed
' CacheFolder is just a temporary location to hold various pages in the Unfiled Notes section
' PagesAfterThisTime tells the program to look for only those pages which were printed after the specified time
' ShowTOC makes sure that the pdf is not cluttered with a Table Of Contents if you specify it as false
returnedStatusCode = oShell.Run(pathToConversionUtil & " -NameOfPdfFile " & """" & nameOfPdfFile &"""" & " -ClearCacheFinally True -UseUnfiled -Output " &  """" & outputDirectoryForPrintedPdf & """" & " -CacheFolder " &  """" & temporaryCacheFolder &"""" & " -PagesAfterThisTime " &  """" & lastPrintedTime &"""" & " -ShowTOC False -ExportNotebook True -RefreshCache True", 0, True)

' I have hardcoded 0 to mean Success
If returnedStatusCode = 0 Then

    fullPathToPdf = outputDirectoryForPrintedPdf & "\" & nameOfPdfFile & ".pdf"

    ' Okay, now, we have a pdf  at the location contained in the location contained in fullPathToPdf variable
    ' Let's open the pdf.
    ' Now, if  you have Adobe Acrobat Standard or Professional on your machine, then you can use the ActiveX approach, which is more robust.
    ' I just have Adobe Reader X so I've used another way. It will just show the pdf on screen. Feel free to modify this according to your needs.
    pdfViewResult = oShell.Run("acrord32.exe " & fullPathToPdf, 1, True)

    ' This one manual step is actually hurting me! More information needed to improve this...
    testerChoice = MsgBox("Was the PDFOkay?", vbYesNo, "Pdf Verification")
    If testerChoice = vbYes And pdfViewResult = 1 Then
        Reporter.ReportEvent micPass, "CheckingPrintedPages", "The pages printed are fine and a pdf is available @ " & fullPathToPdf
    Else
        Reporter.ReportEvent micFail, "CheckingPrintedPages", "The application's Print functionality has a problem. Pdf available @ " & fullPathToPdf
    End If

End If

' I have modified the command-line utility to return various codes in case of error
' -1 means Could not obtain reference to OneNote
' -2 means The file Unfiled Notes.one does not exist, which in our case will mean that no prints were received by the OneNote Printer Driver. This is so because even if the file does not exist, OneNote regenerates it every time it receives a print request.
'-3 means that the OneNote couldn't return the OneNote Xml for the notebook we're interested in. Basically, this means that there was some problem with OneNote.
' -9 means that an unknown error occurred.
' -99 means that  there were no pages printed after the date time we specified.
If returnedStatusCode = -2 Or returnedStatusCode = -99 Then
    Reporter.ReportEvent micFail, "CheckingPrintedPages", "No pages were printed by the application"
Else If returnedStatusCode = -1 Or returnedStatusCode = -3 Or returnedStatusCode = -9 Then
    Reporter.ReportEvent micFail, "CheckingPrintedPages", "There was a problem accessing the OneNote Application"
End If
End If

This script works fine on QTP 10.0 with OneNote 2007. I don't see anything that may prevent it from running successfully with QTP 11.0 and OneNote 2010.

How to use

There are two things that this script depends on:

1. The OneNote2PDF.exe that I created after modifying its sourcecode.

.zip   OneNote2PDF.zip (Size: 17.83 KB / Downloads: 157)

2. Its required dependency iTextSharp.dll. Now, I couldn't attach this dll in this reply since it exceeded the limit. You need to get this dll from here: http://onenote2pdf.codeplex.com/releases/view/10273 Just use the Recommended Donwload link. It will get you this dll.

Keep both these files together in some location and update the value of the variable: pathToConversionUtil so that it reflects the full path for the exe.

If you feel that you are confused, please don't hesitate to write back with your doubts.

Some points to note:

1. The approach assumes that after beginning the action and before the conversion is attempted, there is no other program that's printing to OneNote. This is crucial.

2. You will have to call your action / script to ask the application to print pages after you have captured the current date and time (See Ln. 16). Ask me if you have doubts.

3. You can modify the values of various variables I have declared at the beginning of the script according to what suits your environment.

4. All of this depends on a utility called "OneNote2PDF", whose source code I have modified to suit our requirements. The original utility can be found at http://onenote2pdf.codeplex.com/

I also considered some alternatives to getting this done.

Alternative Approaches

1. Export & Purge
In this case, I thought that we'd start with a blank Unfiled Notes.one file. Print pages, call the script and view the pdf. However, the utility will delete the Unfiled Notes.One file immediately afterward. This approach is kinky because it doesn't allow OneNote to be used for anything else or by any other application then.

2. WMI
Using WMI, listen to the InstanceCreationEvent for Win32_PrintJob and as soon as that fires for the printer called "Send To OneNote 2007", run the script and get the pdf. This would have been GREAT if only it worked. But, since it depends on polling mechanism, it misses updates. Event doesn't always fire so I dropped the idea.

3. Pick N' Choose
There is a third avenue which we can still explore. With this approach, we go to OneNote, get all pages. Start checking the footers of the pages beginning from the latest page until we again reach Page 1, which signals an earlier print job. And then, all these pages we selected, we export to pdf. We can also combine this with the current approach.

4. Image File Format
If you answered yes to the second question I asked first, then we may need to consider exporting the OneNote file to JPEGs instead and then attach it to the Test Results

5. Deeper Inspection of the pdf
If you answered yes to the third question, then we need to replace Ln. 37 with an ActiveX call to Adobe Acrobat. This way we can deeply inspect what pdf contains but this also requires that the machine has either Adobe Acrobat Standard or Professional.

You just check the script, test it and let me know how it goes. If it suffices, then great, otherwise, we'll find a way to sort out the problems you report.

Cheers,
Light.
Reply
#9
Solved: 11 Years, 4 Months, 2 Weeks ago
Hi,

This line gives general runtime error :

returnedStatusCode = oShell.Run(pathToConversionUtil & " -NameOfPdfFile " & """" & nameOfPdfFile &"""" & " -ClearCacheFinally True -UseUnfiled -Output " & """" & outputDirectoryForPrintedPdf & """" & " -CacheFolder " & """" & temporaryCacheFolder &"""" & " -PagesAfterThisTime " & """" & lastPrintedTime &"""" & " -ShowTOC False -ExportNotebook True -RefreshCache True", 0, True)

The steps I followed:
1. Action 1 : action which performs giving print to OneNote.
2. Action 2: I copied the code given by you in this action with single update in path as:
pathToConversionUtil = "C:\Documents and Settings\pandeypr\Desktop\OneNoteAll\OneNote2PDF.exe"

and made a call to action2 from action 1.
3. Run the script .It gives general run error in the line mentioned above.

*I have OneNote2PDF.exe and iTextSharp.dll copied to same path as mentioned above.

Also, it gives error saying "error opening file and file not found for the pdf " if I skip the general runtime error .
Which location are these pdfs getting stored?
Reply
#10
Solved: 11 Years, 4 Months, 2 Weeks ago
Hello.

That's easy to fix.

I anticipated this kind of issue around the command-line arguments that the script is passing to the conversion utility but missed to see that even the path to the utility needs to be enclosed in double quotes.

If you'll notice, the path at which you placed the files is broken by a space after "Documents". That's why you received the runtime error. Basically, your script couldn't locate the conversion utility.

I've updated the script and here it is:

Code:
Dim returnedStatusCode 'This is the variable that will hold the status of pdf conversion

outputDirectoryForPrintedPdf =  Reporter.ReportPath & "\PdfDocs"  'This is where the pdf would be generated; You can change this to suit your needs.

temporaryCacheFolder = Reporter.ReportPath & "\PdfCache"  'This cache will be deleted at the end of conversion but can also be kept through the switch -ClearCacheFinally False. You can change this to suit your needs.

nameOfPdfFile = Environment("ActionName") 'This will be the name of the pdf file generated under the folder:outputPathForPrintedPdf. You can change this to suit your needs.

pathToConversionUtil = "D:\OneNote2PDF\OneNote2PDF\bin\Debug\OneNote2PDF.exe" 'You have to specify the path where you have placed the executable in your machine..

Set oShell = CreateObject("Wscript.Shell") 'Let's get the shell object to run OneNote2PDF command-line utility. O' Shell, come to my rescue!

lastPrintedTime = CStr(Now) ' Capture the current time before proceeding to print

'Since we need the lasprintedtime to be our lower limit for pages, give the print command to the application here AFTER we have captured the current time.
msgbox "Modify the script here to call the action that prints pages through the application!"

' Actually  run the command-line utility in the background and wait for the utility to return a code.
' ClearCacheFinally switch deletes the cache files generated during conversion at the end.
' UseUnfiled switch tells the program to use the "Unfiled Notes.one" file
' Output switch determines where the final merged pdf would be placed
' CacheFolder is just a temporary location to hold various pages in the Unfiled Notes section
' PagesAfterThisTime tells the program to look for only those pages which were printed after the specified time
' ShowTOC makes sure that the pdf is not cluttered with a Table Of Contents if you specify it as false
returnedStatusCode = oShell.Run("""" & pathToConversionUtil & """" & " -NameOfPdfFile " & """" & nameOfPdfFile &"""" & " -ClearCacheFinally True -UseUnfiled -Output " &  """" & outputDirectoryForPrintedPdf & """" & " -CacheFolder " &  """" & temporaryCacheFolder &"""" & " -PagesAfterThisTime " &  """" & lastPrintedTime &"""" & " -ShowTOC False -ExportNotebook True -RefreshCache True", 0, True)

' I have hardcoded 0 to mean Success
If returnedStatusCode = 0 Then

    fullPathToPdf = outputDirectoryForPrintedPdf & "\" & nameOfPdfFile & ".pdf"

    ' Okay, now, we have a pdf  at the location contained in the location contained in fullPathToPdf variable
    ' Let's open the pdf.
    ' Now, if  you have Adobe Acrobat Standard or Professional on your machine, then you can use the ActiveX approach, which is more robust.
    ' I just have Adobe Reader X so I've used the another way. It will just show the pdf on screen. Feel free to modify this according to your needs.
    pdfViewResult = oShell.Run("acrord32.exe " & fullPathToPdf, 1, True)

    ' This one manual step is actually hurting me! More information needed to improve this...
    testerChoice = MsgBox("Was the PDFOkay?", vbYesNo, "Pdf Verification")
    If testerChoice = vbYes And pdfViewResult = 1 Then
        Reporter.ReportEvent micPass, "CheckingPrintedPages", "The pages printed are fine and a pdf is available @ " & fullPathToPdf
    Else
        Reporter.ReportEvent micFail, "CheckingPrintedPages", "The application's Print functionality has a problem. Pdf available @ " & fullPathToPdf
    End If

End If

' I have modified the command-line utility to return various codes in case of error
' -1 means Could not obtain reference to OneNote
' -2 means The file Unfiled Notes.one does not exist, which in our case will mean that no prints were received by the OneNote Printer Driver. This is so because even if the file does not exist, OneNote regenerates it every time it receives a print request.
'-3 means that the OneNote couldn't return the OneNote Xml for the notebook we're interested in. Basically, this means that there was some problem with OneNote.
'9 means that an unknown error occurred.
' -99 means that  there were no pages printed after the date time we specified.
If returnedStatusCode = -2 Or returnedStatusCode = -99 Then
    Reporter.ReportEvent micFail, "CheckingPrintedPages", "No pages were printed by the application"
Else If returnedStatusCode = -1 Or returnedStatusCode = -3 Or returnedStatusCode = -9 Then
    Reporter.ReportEvent micFail, "CheckingPrintedPages", "There was a problem accessing the OneNote Application"
End If
End If

This fixes your first problem.

I think when trying to use this script, you're printing pages before running this script. That will be an issue. You have to call the "Printing Action" at Ln. 16

Code:
msgbox "Modify the script here to call the action that prints pages through the application!"

Replace the line above with the code that will actually print pages through your application. You have a separate action for it, I guess? You can call that action here and wait for it to complete before proceeding.

Assuming that you got it right, you will see the pdf generated at

Your_Report_Path\PdfDocs\Your_Action_Name.pdf

Actually, you can modify the values of the variables: outputDirectoryForPrintedPdf and nameOfPdfFile to get the pdf generated where you like. Try putting an absolute path here if you want.

In a nutshell, you have to do this now:

1. Copy the new script from this reply and update the value of the variable: pathToConversionUtil like you did earlier.

2. Go to Line 16 in this new script and replace it with the code that will print pages through the application in question and wait for it to complete.

3. Run only this script. It will take care of both printing pages and opening PDF.

If you have any issues surrounding Step 2, let me know. All we need is the date and time immediately before the printing starts to make this script work.

If you could successfully get past the line where you got the general runtime error today, please capture the value of the variable: returnedStatusCode and quote it in your next reply so as to make it easy for me to discern what went wrong if it did.

*A request: While posting replies, please ensure that you don't include any personally identifiable information inadvertently. For example, in the path you posted, it is evident that your user name on your system is "pandeypr". This may put you and your system at risk. You can replace any such information with something random, like, "my_user_name"

Thank you so much for reading my detailed replies and working toward perfecting this script.

Cheers,
Light.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  QTP support for extjs applications adityasrinivasb 0 3,436 08-20-2013, 11:08 PM
Last Post: adityasrinivasb
  Does QTP support Adobe CQ and Microstrategy kamalteja 0 2,853 03-29-2013, 03:42 AM
Last Post: kamalteja
  QTP does not seem to support xhtml based java objects siva.kanukollu@yaho.com 0 2,809 01-16-2013, 05:03 PM
Last Post: siva.kanukollu@yaho.com
  Does QTP support Teleric and Dev-Xpress 3rd party tools, if yes how? Dharnish 0 2,384 09-19-2012, 04:32 PM
Last Post: Dharnish
  QTP 11 support for firefox qtplearner88 3 5,177 07-19-2012, 07:43 AM
Last Post: vIns

Forum Jump:


Users browsing this thread: 1 Guest(s)