Basic doubt…If QTP generates vbscript code as we record actions, can't we directly write vbscript code and get rid of QTP which does the same thing too?
R – code actions directly using vbscript when QTP does the same thing too
qtpvbscript
Related Solutions
Apologies, but I don't have time to convert your full sample over to C#. I've thrown together a simple demo that should get you going. This just uses C# to open a QTP instance:
using System;
using QTObjectModelLib;
namespace QtpDemo
{
class QtpDriver
{
[STAThread]
static void Main(string[] args)
{
Application app = new Application();
app.Launch();
app.Visible = true;
}
}
}
You'll need to compile it linking to C:\Program Files\Mercury Interactive\QuickTest Professional\bin\QTObjectModelLib.dll (which is the .NET interop library for QTObjectModel.dll) and have that and QTObjectModel.dll in your app directory when you run it.
It shouldn't be that hard from here for you to convert any object declarations and function calls from VBScript to C#. Please ask if anything's unclear.
To your other point about samples on the internet - there are plenty of people out there doing more advanced stuff with QTP and QC, but I think any really clever solutions aren't shared. I, for example, would probably be prohibited from sharing such things by my employment contract, but I agree with you - there is a dearth of good QTP API samples out there, at least on Google. Having said that, I heartily recommend the SQA Forums for your QTP and QC needs.
Rich
I use following code for pass credentials to the Windows Authentication dialog. I hope it helps.
Dim objIE, objWshShell
Set objIE = WScript.CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "http://url"
Set objWshShell = WScript.CreateObject("WScript.Shell")
With objWshShell
WScript.Sleep 100
.SendKeys "myusername" 'Focused by Default - Username
WScript.Sleep 100
.SendKeys "{TAB}" 'Skip To Password Field
WScript.Sleep(100)
.SendKeys "mypassword" 'Password
WScript.Sleep 100
.SendKeys "{TAB}" 'Skip To "Remember Me" Checkbox
WScript.Sleep 100
.SendKeys "{TAB}" 'Skip To Submit Button
WScript.Sleep 100
.SendKeys "{ENTER}" 'GO
End With
Set objWshShell = Nothing
Set objIE = Nothing
Best Answer
Yes. You can write the code yourself, but you'd have to paste it into the QTP UI.
No. QTP is the engine that runs through it. The VBScript relies on the QTP UI to perform the actions in question, such as clicking on a link on a web page.