Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Is it possible to marry WSH (wscript) with nodejs

Is it possible to marry WSH (wscript) with nodejs

Problem

As QA I use Wsh Scripts to do auto upload, deployment and some time Web testing in IE. WSH(wscript) with JavaScript can open IE window, activate it and access DOM model to do some actions or verify some expected results. It is kind of Selenium 1.0 approach but does not require JAVA and any envrionment configuration so can be executed on any developers/qa windows machine immidiately.

Recently I found Nodejs and all its abilities, except manipulating with Windows IE DOM. Cannot find the way on how to run my old WSH scripts to test IE DOM and at the same time use some NodeJS modules to parse XMLs or run test report server.

So question: is it possible to run WSH JavaScripts and Node.js and use all goodies from both worlds? I am afraid, it is not, but hope somebody has workaround...

As workaround, maybe somebody found the way in NodeJS to start IE window access its DOM (...add own js script or run SendKeys to it)!?

I understand that NodeJS is not designed to do windows administrative tasks.

Problem courtesy of: kirill

Solution

While not actually marrying as the question requires, @o_nix in the comments made the suggestion for https://github.com/idobatter/node-win32ole.

I'd suggest that this module satisfies many issues for people arriving here from Google (as I did). It is also available from npm here: https://www.npmjs.com/package/win32ole

The module also has quite a few examples, such as: https://github.com/idobatter/node-win32ole/blob/dev0.1.3/examples/activex_filesystemobject_sample.js

  var win32ole = require('win32ole');
  . . . 
  var withReadFile = function(filename, callback){
    var fso = new ActiveXObject('Scripting.FileSystemObject');
    var fullpath = fso.GetAbsolutePathName(filename);
    var file = fso.OpenTextFile(fullpath, 1, false); // open to read
    try{
      callback(file);
    }finally{
      file.Close();
    }
  };
  var withEachLine = function(filename, callback){
    withReadFile(filename, function(file){
//    while(file.AtEndOfStream != true) // It works. (without unary operator !)
//    while(!file.AtEndOfStream) // It does not work.
      while(!file.AtEndOfStream._) // *** It works. oops!
        callback(file.ReadLine());
    });
  };
  withEachLine(testfile, function(line){
    console.log(line);
  });

So, to me, this is as good as marrying old WSH scripts as anything. Tweaks will be involved of course, but then it's goodbye WSH.

More specifically, to the question at hand, this is a snippet of a demo IE script: https://github.com/idobatter/node-win32ole/blob/master/examples/ie_sample.js

  var win32ole = require('win32ole');
  . . . 
  var ie = new ActiveXObject('InternetExplorer.Application');
  ie.Visible = true;
  for(var i = 0; i 
Solution courtesy of: cmroanirgo

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Is it possible to marry WSH (wscript) with nodejs

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×