Showing posts with label CreateObject. Show all posts
Showing posts with label CreateObject. Show all posts

Saturday, 3 May 2014

QTP - UFT - Can you write a script to sort "uftquestions" as "efinoqssttuu"

One of the best method I would use for sorting is using object of "System.Collections.ArrayList"

Code:
Set o1 = Createobject("system.collections.ArrayList")
strInput = "UFTQuestions"
For k = 1 To len(strInput)
    o1.Add mid(strInput,k,1)
Next
o1.sort

For uj = 0 to o1.count-1
    strOutput = strOutput & o1(uj)
Next
msgbox strOutput

Output:- strOutput is "eFinoQsstTuU"

Happy reading,
Sreenu Babu

Wednesday, 30 April 2014

QTP - UFT - How to open a browser with google.com as url using VBSript

This question is some time confusing for on going interview guys.

How to open a browser with google.com as url using VBSript or How to open a browser with google.com using UFT or QTP.

Answer is simple


Syntax
Set o1= Createobject("InternetExplorer.Application")
o1.Visible = true
o1.Navigate "www.google.com"
Set o1 = nothing


Regards,
Sreenu Babu

Sunday, 27 April 2014

Can you create a ALM - Quality Center Connection using OTA object

We can use QC/ALM OTA Object "TDApiOle80.TDConnection" to establish connection. Please see the code below

Syntax
Dim ALMConnection
'Return the TDConnection object.
Set ALMConnection= CreateObject("TDApiOle80.TDConnection")
ALMConnection.InitConnectionEx "http:///qcbin"
ALMConnection.login "<username>""<password>"
'DEFAULT = Domain, QualityCenter_Demo = Project
ALMConnection.Connect "DEFAULT""QualityCenter_Demo"


Note: "http://qcbin" url should be replace with the correct ALM Server URL. User may enter they Quality center / ALM username and password in the "<username>" and "<password>"


Regards,
Sreenu Babu



 

QTP - UFT - How to open a text file using VBScript or How to open a flat file using VBScript





Open text file can be opened using "Scripting.FileSystemObject"

Syntax
filename = "c:\sample.txt"
strmode = 2
Set o1 = Createobject("Scripting.Filesystemobject")
If o1.FileExists(filename) = true Then
    set r1 = o1.OpenTextFile filename,strmode
 else
    ExitTest
End If
Msgbox r1.readall()

strMode represents the File Read mode and Any Text file can be opened in the following modes

ForReading  1  Open a file for reading only. You can't write to this file.
ForWriting 2 Open a file for writing.
ForAppending 8 Open a file and write to the end of the file.


QTP - UFT - How to create a text file using VBScript


 
We can use "Scripting.FileSystemObject"

strfilepath = "C:\Sample.txt"
Set obj = Createobject("Scripting.FileSystemObject")
If obj.FileExists(strfilepath)  = false Then
 obj.CreateTextFile strfilepath,true
End If
Set obj = nothing


Note:- To run the script copy and paste the script in Notepad and save it with extension ".vbs". Example "CreateFolder.vbs". Double click the file to run the script.

Or

Copy and paste the script in UFT / QTP and press F5 ( i.e. Run Button)
 
Happy Reading,
Sreenu Babu




 




 















QTP - UFT - How to create a folder using VBScript

We can use "Scripting.FileSystemObject".

Syntax
strFolderpath = "C:\SampleFolder"
Set obj = Createobject("Scripting.FileSystemObject")
If obj.FolderExists(strFolderpath) = false Then
 obj.CreateFolder strFolderpath
End If
Set obj = nothing


Note:- To run the script copy and paste the script in Notepad and save it with extension ".vbs". Example "CreateFolder.vbs". Double click the file to run the script.
Or
Copy and paste the script in UFT / QTP and press F5 ( i.e. Run Button)