Skip to main content

Posts

Showing posts from May, 2012

Download File - VBScript function

Here is the function to download any file over internet using XMLHTTP COM objects in VBScript. 

Function Download(sFileURL, sLocation) 'create xmlhttp object Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") 'get the remote file   objXMLHTTP.open"GET", sFileURL, false 'send the request   objXMLHTTP.send() 'wait until the data has downloaded successfully dountil objXMLHTTP.Status = 200 :  wscript.sleep(1000) :  loop 'if the data has downloaded sucessfully If objXMLHTTP.Status = 200Then 'create binary stream object Set objADOStream = CreateObject("ADODB.Stream")     objADOStream.Open 'adTypeBinary     objADOStream.Type = 1     objADOStream.Write objXMLHTTP.ResponseBody 'Set the stream position to the start     objADOStream.Position = 0

ExecuteGlobal in VBScript

Most of guys will face this problem like,
- Having a class in a .vbs file say class1.vbs
- In another .vbs file, trying to create object for that class
Here it will say class is undefined because your class should be in global namespace so that your second script should know. To achieve this, use ExecuteGlobal command in VBScript.
Here I am putting sample function to include your class or other .vbs files which you are going to refer.
'To include a file which are referenced here. Sub Include(file) Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(file, 1)   str = f.ReadAll   f.Close ExecuteGlobal str EndSub 'Just call this function like this in your scripts Call Include("C:\class1.vbs") 'Then try to create object for the above class Dim obj Set obj = New Class1 'continue... Hope this give you ideas !!!

Start learning VBScript or JavaScript

Lot of guys who are interested to move to automation testing from manual have dilemmas on how to start learning the scripting language, which one I have to install, where to study, etc.
For those who are covered under the above case, this article is for you.
Both VBScript and JavaScript will run on windows based script host. So follow the simple steps to learn.


1. Just create a text file in your system and save it as .vbs(VBScript)or .js(JavaScript)extension.
2. Open the .vbs or .js file using notepad or other your favorite notepad editor like wordpad, notepad++, etc.
3. Just do your code and save.
4. Just double-click the .vbs or .js file. It will execute and give you results.
5. For your understanding like what value it returns, use msgbox which will show the value in dialog while executing for VBScript. For JavaScript, just create an object for "WScript.Shell" and use Popup.
6. If errors in your code, the it will give you error dialog by specifying error line and other info.
For t…

VBScript Dictionary Object vs JavaScript Object

In test automation world, always we have situations to return more than one value from a function call. For this we have some simple ways but yet always we searching for better ways. Here I am listing some ways we can 
consider.
1. Array
We have simple array concept in all languages but this not effective while retrieving values for a particular field because array is related to index. We can't know at which index which value is there. We have to implement our own methods to find them.
2. Class and Objects
This is an another effective method but the user need some information about classes and objects. You can create a class, then class variables for all fields you are going to return values. So just create an instance for this class i.e. object and assign the values for all properties associated with this object and return this object.
Here you can directly get your particular field value by passing the field name. No concept of indexes like array. So simple to access a value and assig…

QTP - File Formats

Lot of QTP users are very interested to know all file formats related to QTP. Here are list as of my knowledge. Kindly do correct me if I am wrong.


Inside each Action:
-->  .BDB - Berkeley  Data Base - This is the Local Object Repository
-->  .MTR - Mercury Test Resource - This file contains Resources i.e. External Libraries, ORs and other files associated to each action.
-->  .MTS - Mercury Test Script - This is the script belongs to particular action.
-->  Folder Snapshots - Used to store the Active Screen images for the action.


Inside each Test:
-->  Actions folder will be there.
-->  default.CFG - Contains full details about run configurations
-->  default.USP - Contains user info with run logics. (related to LoadRunner execution)
-->  test.TSP - Used to store test settings info.
-->  Parameters.MTR - Contains Input, Output parameters info belongs to the test.
-->  TestName.USR - This file contains info about add-ins, files associated, environment info and other …

Option Explicit

Option Explicit: Why we need this statement while writing VBScript?

-- By default, VBScript will allow use of variables without declaration which leads to lot of mis-spell, type and wrong variable name errors.
-- This will force the VBScript Engine not to accept the variables without declaration before its first use.
-- Normally, Used to avoid typo errors, giving wrong variable names, redefining variables by mistake, etc.

Consider the below script:
Dim var1 var1 = 10 'This line will not throw any error like "Variable undefined" var2 = 20 'This line will not throw any error like "Variable redefined" Dim var1 After inserting Option Explicit Statement, it will throw error.
OptionExplicit Dim var1 var1 = 10 var2 = 20'This line will throw error "Variable undefined" Also,
OptionExplicit Dim var1 var1 = 10