0
votes

I am using a VBScript file named BrowserError.vbs which is accepting one argument from the Java class am using. The vbs file is used send an email when there is a test case failure with a screenshot.

Problem:

If I run the vbs file from command prompt it works fine and sends the email with attachment.

But if I run from the Java class it gives the following error:

No Script engine for .vbs TL02_Validate_ChaterInvalidLogin-1-11Apr16_045433

BrowserError.vbs:

Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim name
Dim folder
Dim displayMsg

Dim ol, ns, newMail

name = WScript.Arguments.Item(0)
FromAddress = "[email protected]"
ToAddress = "[email protected]"
CcAddress = "[email protected]"
MessageSubject = "Sanity Error Alert !!!"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
MessageAttachment = "C:\Users\****\Desktop\********\CnetWorkSpaceBranch\SanityBranch\target\surefire-reports\html\screenshots\" & name & ".png"
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(MessageAttachment, 1)
strFileText = "Hi, Error notification on Sanity- User has encountered problem  : Refer screenshot "
objFileToRead.Close
Set objFileToRead = Nothing
newMail.Subject = MessageSubject & Now
newMail.HTMLBody  = strFileText
newMail.To = ToAddress
newMail.CC = CcAddress
newMail.Display
newMail.Attachments.Add(MessageAttachment).Displayname = "Check this out"
newMail.Send
Set ol = Nothing

The Java code which is used to pass the argument is like this:

String tnm="TL02_Validate_ChaterInvalidLogin-1-11Apr16_045433";
Runtime.getRuntime().exec("wscript C:/BrowserError.vbs"+tnm);

My core interest is to just send the email and get the value from the Java class while running and sending the email.

1
In Java, it appears to a vbs programmer, that there should be a space after .vbs. The error message says it is trying to execute a script with an extension of vbsTL02_Validate_ChaterInvalidLogin-1-11Apr16_045433 of which there isn't one. - user6017774
See this Stackoverflow Q&A and perhaps this. My advice (and Stackoverflow rules) is that you google the error message before posting. Otherwise things get cluttered with redundent low nurishment posts. If my pointers do not help let me know. - MikeJRamsey56

1 Answers

0
votes

As @Noodles pointed out in his comment to your question, you're appending the argument directly to the script path, thus creating an unrecognized extension.

Change this:

Runtime.getRuntime().exec("wscript C:/BrowserError.vbs"+tnm);

into this:

Runtime.getRuntime().exec("wscript C:/BrowserError.vbs "+tnm);
//                                                    ^

and the problem will disappear.