How to open QTP from JavaScript without using ActiveXObject? - javascript

i need to invoke QTP from a javascript without using ActiveXObject. can anybody guide me how to proceed with this?
Thanks,
Ramya.

Java Script programming cannot be done in QTP but it will
support Java script. We can make a DLL by using Java script
and add that to QTP and there after you can use that.
Regards,
Mannusanghi

QTP supplies a COM interface for automation, in order to create the automation object you need to use ActiveXObject (see this article on using OLE Automation in Javascript).
Why do you want to avoid using ActiveXObject?

Any particular reason why you don't want to use the ActiveXObject?
Anyhow, if you're running JavaScript through the Windows Script Host, instead of the way mentioned in the manual:
var qtApp = new ActiveXObject("QuickTest.Application");
...you can do this:
var qtApp = WScript.CreateObject("QuickTest.Application");
qtApp.Launch();
qtApp.Visible = true;
But you be might using ActiveX behind the scenes there anyway, I'm not entirely sure.

Related

Changing Proxy Settings without Closing the Driver in Selenium/Splinter

In an older version of Splinter/Selenium this was said not to be possible. This answer a few years later claims it is possible with JavaScript, but this code doens't work for me (I might have just failed to translate it to Python). This answer closes the browser and then re-opens it, and I need the window/browser to stay open.
With plugins like FoxyProxy, its very easy to change the proxy on-the-fly, but I don't think Selenium can interact with plugins because they are page elements?
As Splinter is designed to be a less verbose wrapper for Selenium, it would be awesome if there was an easy way to accomplish this. That being said, any hack to just have this functionality would be appreciated.
You need to use it like below
browser.visit("about:config")
script = """
var prefs = Components.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.setIntPref("network.proxy.type", 1);
prefs.setCharPref("network.proxy.http", "{0}");
prefs.setIntPref("network.proxy.http_port", "{1}");
prefs.setCharPref("network.proxy.ssl", "{0}");
prefs.setIntPref("network.proxy.ssl_port", "{1}");
prefs.setCharPref("network.proxy.ftp", "{0}");
prefs.setIntPref("network.proxy.ftp_port", "{1}");
"""
browser.execute_script(script.format("ProxyIP", "PORT"))
PS: Credits to Python Selenium Webdriver - Changing proxy settings on the fly

Ideas needed. Javascript+XPCOM+C++ add-on

So, there is a WebRTC inside Firefox and there is a convenient class for making RTC communication possible called RTCPeerConnection which can be instantiated and used from the JavaScript app. You can find some decent example of it on [1].
And here am I with my custom transport (if you're interested - [2]) would like to use it for RTC communication. Briefly, I need to "substitute" the transport layer of WebRTC engine by my custom transport while providing the same RTCPeerConnection-like JavaScript interface for the user. And preferably, it should not look like custom build of Firefox (no patches).
So I've come up with the idea of extension, which will be written in C++ (since it need to be linked with WebRTC library and my custom transport library) and somehow will expose its interface to Javascript. And I've found XPCOM which, as I thought, can provide me this.
So I've started to fight with out-dated and sparsed info on this topic and after 3 days of struggling finally ended up with builded add-on. Unfortunately, I can't access it from Javascript, because of Javascript's "Components.classes is undefined" error. And it seems that there is no way to access it at all. Or I'm wrong on that?
Here is Javascript:
function check()
{
console.debug("checking...");
const {Cc,Ci,Cu} = require("chrome");
var rtc = Components.classes["#named-data.net/ndnrtc;1"].createInstance();
rtc = rtc.QueryInterface(Ci.ndINrtc);
console.debug("rtc: "+rtc);
}
My component is visible with XPCOM Viewer addon and the code above I can execute in the console while empty page is open in Firefox.
Given all that, I would like to ask Firefox experts regarding possible approaches which I can take in order to implement my idea.
Thank you in advance
1 https://apprtc.appspot.com/
2 http://named-data.net
Finally, I've figured out one possible solution for that and describe it in my post

Windows XP and Up: JavaScript instead of VBScript?

I asked how to check modify timestamps with BAT files and launch a command based on an if statement and Wimmel asked if I could use VBScript instead of Batch Files. I think this is a grand idea. This leads to another question
Can I access the VBScript functionality with JavaScript, while still being compatible Windows XP to Current? (specifically checking file modify timestamp and running a command depending on how recently modified)
Not sure that it is a good idea, but yes, you can use JavaScript (actually, JScript) instead of VBScript. Just use ActiveXObject class instead of CreateObject function that is used in VBScript to create objects.
Here is a code that reads the file modify timestamp using Windows Scripting and JScript:
var o = new ActiveXObject("Scripting.FileSystemObject");
var file = o.GetFile("c:\\temp\\test.js");
WScript.Echo(file.DateLastModified);
For more information, see JScript documentation and Windows Script Host documentation
Even though there are probably easier ways to achieve what you want to do, I had a go at trying the more theoretical part of your question, and apparently all the things we need are there.
Here is what I tried:
test.js:
WshShell = WScript.CreateObject("WScript.Shell");
var result = WshShell.Run("test.vbs", 0, true);
WSH.Echo(result);
test.vbs:
WSH.Echo "test.vbs"
WSH.Quit 5

javascript equivalent of html_entity_decode that doesn't rely on innerHTML?

I'm looking for a javascript version of PHP's html_entity_decode. I found this:
function html_entity_decode(str){
var tarea=document.createElement('textarea');
tarea.innerHTML = str; return tarea.value;
tarea.parentNode.removeChild(tarea);
}
However, I can't use this because I need to write this code for an FBML/FBJS Facebook canvas app, and they have disabled innerHTML and anything similar (insanity, I know).
Is there any other way to do this that doesn't resort to sticking the string into an element and pulling it back out again? Please make sure to only use functions that would be allowed in FBJS
I guess you'll have to do it manually. A quick Google search brought up this library that does what you want.

Set working directory in javascript

Does anyone know how to set the working directory in JavaScript before?
Code I use for launching an application is this:
// Create an object script
oL = new ActiveXObject("WScript.Shell");
oFile = '"C:/Application.exe"';
oL.run(oFile);
According to MSDN, you should be able to use:
var oL = new ActiveXObject("WScript.Shell");
oL.CurrentDirectory = "C:\\Foo\\Bar";
oFile = '"C:\\Application.exe"';
oL.run(oFile);
...assuming you're running this script in Windows Script Host, in which case you probably ought to make that clear in your question - about 99% of JavaScript programmers only ever use the language in a web browser, where this kind of stuff is only possible under extremely unusual circumstances.
Javascript typically runs in a sandbox that means it doesn't have access to the filesystem anyway, thus setting the cwd is meaningless.
What context are you trying to do this in (website javascript, local script running with Rhino etc.) and what are you trying to achieve?
Javascript dosent have access to your harddrive so why should you be able to set the working directory?

Categories