April 30, 2013

Script test in TestComplete

In the last post, we learned how to create a keyword test in TestComplete. I had mentioned then that Script tests are more suitable for people who know a scripting language like VBScript or JScript and who have written test automation before. In this post, let us see how to build a script test to test the Windows Calculator. We will use data parametrization, external data sources, conditional statements and loops. Rest assured that it will not be simple at all.

April 26, 2013

How to create a keyword test in TestComplete (from SmartBear Software)?

TestComplete is a test automation tool that can test a variety of applications like Windows applications, web applications, web services, Adobe AIR applications and Java applications. Tests can be created as either Keyword tests or Scripts. The former are more suitable for beginners in test automation and the latter are more suitable for people who know a scripting language like VBScript or JScript and who have written test automation. It is very simple to build a keyword test in TestComplete. In this post, let us see how to build a keyword test in a browser based application quickly.

April 20, 2013

How to send an email using VBScript?


In the last article, we have learnt that VBScript is useful to write small automation utilities like writing commands in cmd.exe, launching an executable, killing all instances of an executable etc. But do you remember a forwarded email that contained an attachment file and sender asked you to save that file with .vbs extension and then to double click that file to see some magic? If you do perform those steps, a program automatically executes, open a new email message, write recipient email address in "To" field, write some silly text in body and then sends that mail using your Outlook. By the time you understand something and react, an email shoots to recipient. Actually that attachment could be a VBScript. We will learn how such a script works.
If you want to learn VBScript from basics to some advanced topics, use my free VBScript tutorial for beginners.
First we have to create an object of Outlook.Application class (This only works if you have Outlook configured with an email address in your machine) and then create an object of mail item. The code snippet follows. Note that all the source code is in italics font.

   Set objOutlook = CreateObject("Outlook.Application")
   Set objMail = objOutlook.CreateItem(0)

To see the email message, use .Display method, otherwise processing will be happen in background.
   objMail.Display   'To display message

Now fill Recipient email id, Copy email id, Subject and Body, using following commands:
   objMail.to = "abc@example.com"
   objMail.cc = "pqr@example.com"
   objMail.Subject = "Mail Subject"
   objMail.Body = "This is Email Body"

To add attachments, one can use following command (Repeat similar command to add more attachments):
   objMail.Attachments.Add("C:\Attachment\abc.jpg")

Now email is ready, now use .Send method to send your message to recipient:
   objMail.Send

Now open notepad and integrate all these to see how it works. Below is the complete script to send email message (I intentionally commented the objMail.Send line below, so you are not surprised. If you want to actually send the mail, just uncomment objMail.Send line):

   Set objOutlook = CreateObject("Outlook.Application")
   Set objMail = objOutlook.CreateItem(0)
   objMail.Display   'To display message
   objMail.To = "recipient@example.com"
   objMail.cc = "copyrecipient@example.com"
   objMail.Subject = "Test Mail Subject"
   objMail.Body = "This is Email Body"
   'objMail.Attachments.Add("C:\Attachment\abc.jpg")   'Make sure attachment exists at given path. Then uncomment this line.
   'objMail.Send   'I intentionally commented this line
   objOutlook.Quit
   Set objMail = Nothing
   Set objOutlook = Nothing
Save notepad file as .vbs extension. Double click .vbs file to execute VBScript.

To send a mail to multiple recipients, use following commands instead of objMail.To line:
   objMail.Recipients.Add("recipient1@example.com")
   objMail.Recipients.Add("recipient2@example.com")
   objMail.Recipients.Add("recipient3@example.com")

Below is the complete script is to send mail to multiple recipients (I intentionally commented the objMail.Send line below, so you are not surprised. If you want to actually send the email, just uncomment objMail.Send line). Write below code in a notepad file, save it as .vbs extension and then double click to execute script.

   Set objOutlook = CreateObject("Outlook.Application")
   Set objMail = objOutlook.CreateItem(0)
   objMail.Display   'To display message
   objMail.Recipients.Add ("recipient1@example.com")
   objMail.Recipients.Add ("recipient2@example.com")
   objMail.Recipients.Add ("recipient3@example.com")
   objMail.Subject = "Mail Subject"
   objMail.Body = "This is Email Body"
   'objMail.Attachments.Add("C:\Attachment\abc.jpg")   'Make sure attachment exists at given path. Then uncomment this line.
   'objMail.Send   'I intentionally commented this line
   objOutlook.Quit
   Set objMail = Nothing
   Set objOutlook = Nothing

Please provide your feedback. Thanks!

Note: This article has been contributed by Vinod Joshi, who is a test automation professional. Vinod is a respected test automation designer. He is very active in the software testing space community. Additionally, Vinod is the moderator of the Software Testing Space group in LinkedIn.

Want to learn VBScript in detail? Use my free VBScript tutorials. Thank you.

April 04, 2013

How to work the Command Window using VBScript?


VBScript is ActiveX-enabled scripting language developed by Microsoft that connects to scripting hosts like Internet Explorer and performs functions locally using the Windows Script Host (WSH). It is an interpreted client side language. VBScript uses the Component Object Model (COM) to access elements of the environment within which it is running. Generally, scripting languages are coded faster as these are interpreted. VBScript is structured and used with smaller programs with limited capability. It is embedded within windows by default in every desktop release since Windows 98. 


A VBScript script must be executed within a host environment, of which there are several provided with Microsoft Windows, including Windows Script Host (WSH), Internet Explorer (IE), and Internet Information Services (IIS). Additionally, the VBScript hosting environment is embeddable in other programs, through technologies such as the Microsoft Script Control (msscript.ocx). VBScript allows us to write small automation utilities and to execute them without using any functional automation tool. We will now learn how to work with command mode.