Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MS One Note 2010 support from QTP 11.0
#1
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
Ankur or anyone,

if you have slightest idea,pls share..I am kind of stuck here with MS One Note Automation
Reply
#3
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
Thanks a lot Deepak Smile
I will surely run the code on monday and will let you know how it works.
Reply
#5
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
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
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


Attached Files
.zip   OneNote2PDF.zip (Size: 17.83 KB / Downloads: 204)
Reply
#9
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
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,739 08-20-2013, 11:08 PM
Last Post: adityasrinivasb
  Does QTP support Adobe CQ and Microstrategy kamalteja 0 3,156 03-29-2013, 03:42 AM
Last Post: kamalteja
  QTP does not seem to support xhtml based java objects siva.kanukollu@yaho.com 0 3,171 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,692 09-19-2012, 04:32 PM
Last Post: Dharnish
  QTP 11 support for firefox qtplearner88 3 5,746 07-19-2012, 07:43 AM
Last Post: vIns

Forum Jump:


Users browsing this thread: 1 Guest(s)