How to invoke uft script present in ALM using java script? - javascript

My requirement is to execute the UFT scripts based on the input given in html page. I came to know from some of the blogs that Microsoft has stopped vbs script usage in html. for that reason i want to invoke the qtp scripts using java script. I searched for the same and didnt find much information. If anyone can provide the equivalent code in javascript will be helpful. I am in short of time to experiment as the client demo is near.
Dim objQtpApp
Set objQtpApp=Createobject("QuickTest.Application")
objQtpApp.Launch
objQtpApp.Visible=False 'True
varUserName=document.getElementsByName('Username').value
varPassword=document.getElementsByName('Password').value
call QC_Connect(varUserName,varPassword)
Sub QC_Connect(varUserName,varPassword,varCustomsON)
'
objQtpApp.TDConnection.Connect "http://dddd.fed.test.com:7117/qcbin", "Domain", "Project", varUserName, varPassword,False
If objQtpApp.TDConnection.IsConnected Then
objQtpApp.Open "[QualityCenter] Subject\Automated Test Case Development\Test",False
objQtpApp.Test.Environment.Value("varUserName")=varUserName
objQtpApp.Test.Environment.Value("varPassword")=varPassword
objQtpApp.Test.Environment.Value("varCustomsON")=varCustomsON
objQtpApp.Test.Run
objQtpApp.Quit
Else
MsgBox "Cannot connect to Quality Center"
End If
End Sub
Thanks,
Rakesh

Your main problem will be that JavaScript doesn't have an equivalent of CreateObject.
The only browser that supports Microsoft's alternative (new ActiveXObject("...")) is IE (not Edge) and it also supports VBScript so there's no point in porting your code to JavaScript.

Related

Run CATscript from IE11 with Javascript

shortly:
the code CATIA.SystemService.ExecuteScript(sPath, 0, sName + ".CATScript", "CATMain", aParams) ; throw error Type mismatch, and i don't understand since in IE11 (I know, but I have to) debugger, the watch of CATIA.SystemService gives me the same list of argument for method ExecuteScript, and this call is working in VBscript. How can i get details on argument types? how can I know which var is causing this error?
All my variables are declared (use strict).
in details:
I'm trying to figure out how to save a large set of functions using HTML interfaces to run CATscripts (Catia macros, VBscript like), that are launched via VBscripts, from the transition of my Company from IE8 to IE11 (no choices here). As discussed there in MSDN, and here in Stackoverflow (I've tried all solutions obviously, and the compatibility setting is not activatable), VBscript support stops in IE11
I have 2 sort of functions: some are static, and stored on our intranet website. They still work on IE11 (Edge mode if i understood, although i couldn't find exactly what it mean)
But some other are written on the fly, on users computer, to generate an interface reflecting what's currently in Catia. Those don't work anymore on IE11, and are the most important. It seems they are considered "internet zone", which I don't understand since they are locally written. is that to prevent malware?
here is how i call the function from the HTML:
<input type='button' value='00-10' onclick='StartScript(me)' id='import-zip-from-DB'/>
and here is the VBscript (simplified but functional):
Sub StartScript(button)
Dim aParams()
Dim sName
Dim sPath
Dim CATIA
sName = button.Id
sPath = "C:\temp\"
'Get Catia object
Set CATIA = GetObject(, "CATIA.Application")
'run the script in catia
On Error Resume Next
CATIA.SystemService.ExecuteScript sPath, 1, sName & ".CATScript", "CATMain", aParams
If Err.Number <> 0 Then MsgBox Err.Description, vbCritical, "QC2 toolset"
On Error GoTo 0
End Sub
I have tried Javascript, with a really similar function. the code to get Catia Object is var CATIA = new ActiveXObject("CATIA.Application");
thanks in advance!
I found a solution, finally!
It's not my favourite answer, but renaming files from file.html to file.hta allowed my functions to work again on my user's stations, as the files are now openned by Microsoft HTML Application host. Major downside: CSS formatting is not as good as IE, but that's a minor issue on a professional tool
So if anyone has a solution that don't involve HTA files, that would surely replace this workaround on my toolset, but for now i'm relieved :)

WScript.Sleep() ~ WSScript is undefined

I'm trying to follow some example code from microsofts mdn site..
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("calc");
while (oExec.Status == 0)
{
WScript.Sleep(100);
}
WScript.Echo(oExec.Status);
I'm currently writing a javascript/JScript to run a few batch commands. Everything works fine if I don't use WScript.Sleep(). However, If i try to use it, to prevent locking up the browser, i'm getting an error that WScript is not defined.
I figured that I needed to define it myself. However, I have been searching mdn website all day with no luck. This is my first time using any "windows only" products I could be coompletly overlooking something.
If you want to see the documentation I'm looking through it is located here.
http://msdn.microsoft.com/en-us/library/ateytk4a(v=vs.85).aspx
Any help is greatly appreciated.
Thanks,
Freddy
WScript is an object that is defined when the Javascript is run within the Windows Script Host, aka WSH. The object is not available within the Javascript engine in a web browser.
If you are really trying to produce "batch like" files, then you don't need a browser, and I'd say you probably don't want a browser. You can write your code into a .js file and just run it from the cmd.exe prompt or Explorer window with a double-click.
Change the script language from JavaScript to JScript

Call a java class directly from javascript without <APPLET> or <OBJECT>

I've had some experience with Java and Javascript and searching this forum has helped me tremendously, but haven't been able to find this exact problem explicitly. In a nutshell: I want to call a java class straight from Javascript i.e. use a Java class in Javascript without OBJECT or APPLET.
Here's what what I'm experimenting with:
function screenSize() {
alert("Screen Dimension\n" + " width:"
+ java.awt.Toolkit.getDefaultToolkit().getScreenSize().width
+ " height:" + java.awt.Toolkit.getDefaultToolkit().getScreenSize().height);
}
which is an example given on http://www.rgagnon.com/javadetails/java-0170.html. This is hooked to a button on a page. When clicking the button I (in essence) get:
A Runtime Error has occured at line 35: 'java' is undefined.
I'm assuming that my path is incorrect or missing and there's a PATH or CLASSPATH or something I've overlooked.
I'd eventually like to move the javascript into a bookmarklet so that the user will be able to click a favorite on the appropriate page and have magic happen because of my own java classes manipulating the data from the screen. For various reasons political and technical, I'm stuck using IE6-7 and have to work with scraping the web page in the browser and processing it on the client -- no sever side action for me! I can assume that a JRE 6 will be available.
Is it a path issue? Is what I want even possible and if so, how? And how will packages work with all this?
Any advice or examples will be muchly appreciated.
The tip shown at Real's HowTo used to work, but doesn't anymore. Insert an applet and define public methods to interact with.
In the link you referenced, did you notice this information at the top?
On IE4 or better, you can't call java.* methods directly from Javascript or Jscript.
It goes on to explain that an Applet is needed. Of course, IE4 is rather old, not sure how much of this is still relevant. Good luck!

Tutorial for using JavaScript on a Desktop

I need to do some scripts in java script.
I am working on it but couldn't find a few solutions to a few problems.
First of all I need a GOOD tutorial, but not for an internet page but for a DESKTOP script.
Things couldn't find out like :
1) I wanted a simple message box in order to debug my program, I used:
var name = prompt("What is your name","Type Name Here");
When running it I get error of "Object expected"
2) Couldn't find how to open a file
Based on your comments, I guess that you are attempting to run a JavaScript file directly on Windows. Double-clicking on a .js file in windows will (probably) run it in Windows Script Host.
The prompt() function will not work this way, since WSH provides a completely different API than browser-embedded engines.
The following code should accomplish your intentions. However if you want anything more than a simple popup, HTAs are the only way to do complex GUIs with JScript on the desktop.
var fso, ws, ts;
fso = new ActiveXObject('Scripting.FileSystemObject');
ws = WScript.CreateObject('WScript.Shell');
var ForWriting= 2;
ts = fso.OpenTextFile('foo.txt', ForWriting, true);
ts.WriteLine(new Date().getTime());
ts.Close();
ws.Popup('Wrote to file!');
var ForReading= 1;
ts = fso.OpenTextFile('foo.txt', ForReading, false);
var fileContents = ts.ReadLine();
ts.Close();
ws.Popup('The file contained: ' + fileContents);
WScript.Quit();
I have to ask: why is JavaScript the right tool for the job? Why not use a scripting language intended to be used this way, such as Python, Ruby, Lua, ... etc?
If you are using Microsoft's JScript (and it sounds like you are), look to the MSDN web site for help. The page here looks fairly good. Google can also help with that.
Assuming you don't mind using Java, you could also use the Mozilla Rhino shell. But it doesn't look like there is a standard way of reading from the console in JavaScript. (presumably since this is not something typically required in a JavaScript application...) The built in JavaScript functions in the shell seem fairly basic, but you can read a file.
There area also examples of using Rhino, which may be helpful. You can interface with the Java API to do whatever else you need to do.
Edit: I wrote this answer a long time ago; today I would use node.js. See their learning page.
The latest prerelease of Opera acts as a runtime for JS applications.
They have tutorials describing how to use it.
I used: var name = prompt("What is your name","Type Name Here");
When running it I get error of "Object expected"
Presumably your runtime doesn't implement prompt that in a way that is compatible with those arguments.
2) Couldn't find how to open a file
This depends on the runtime you use. JS itself doesn't have anything built in to read files (or display a prompt). You need an environment that provides those objects.

How can I execute javascript in Bash?

I try to get to a page straight from Bash at http://www.ocwconsortium.org/. The page appears when you write mathematics to the field at the top right corner. I tested
open http://www.ocwconsortium.org/#mathematics
but it leads to the main page. It is clearly some javascript thing. How can I get the results straight from Bash on the first page?
[Clarification]
Let's take an example. I have the following lines for a Math search engine in .bashrc:
alias mathundergradsearch='/Users/user/bin/mathundergraduate'
Things in a separate file:
#!/bin/sh
q=$1
w=$2
e=$3
r=$4
t=$5
open "http://www.google.com/cse?cx=007883453237583604479%3A1qd7hky6khe&ie=UTF-8&q=$q+$w+$e+$r+$t&hl=en"
Now, I want something similar to the example. The difference is that the other site contains javascript or something that does not allow me to see the parameters. How could I know where to put the search parameters as I cannot see the details?
open "http://www.ocwconsortium.org/index.php?q=mathematics&option=com_coursefinder&uss=1&l=&s=&Itemid=166&b.x=0&b.y=0&b=search"
You need quotes because the URL contains characters the shell considers to be special.
The Links web browser more or less runs from the commandline (like lynx) and supports basic javascript.
Even though the title of the post sounds general, your question is very specific. It's unclear to me what you're trying to achieve in the end. Clearly you can access sites that rely heavily on javascript (else you wouldn't be able to post your question here), so I'm sure that you can open the mentioned site in a normal browser.
If you just want to execute javascript from the commandline (as the title suggests), it's easy if you're running bash via cygwin. You just call cscript.exe and provide a .js scriptname of what you wish to execute.
I didn't get anything handled by JavaScript - it just took me to
http://www.ocwconsortium.org/index.php?q=mathematics&option=com_coursefinder&uss=1&l=&s=&Itemid=166&b.x=0&b.y=0&b=search
Replacing mathematics (right after q=) should work. You may be able to strip out some of that query string, but I tried a couple of things and and it didn't play nice.
Don't forget to encode your query for URLs.
You will need to parse the response, find the URL that is being opened via JavaScript and then open that URL.
Check this out: http://www.phantomjs.org/.
PhantomJS it's a CLI tool that runs a real, fully-fledged Browser without the Chrome.

Categories

Resources