是否可以将WSH(wscript)与nodejs结合 [英] Is it possible to marry WSH (wscript) with nodejs

查看:228
本文介绍了是否可以将WSH(wscript)与nodejs结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为QA,我使用WSH脚本在IE中进行自动上传,部署和一些Web测试。使用JavaScript的WSH(wscript)可以打开IE窗口,激活它并访问DOM模型来执行某些操作或验证一些预期的结果。它是一种Selenium 1.0方法,但不需要JAVA和任何环境配置,所以可以在任何开发人员/ qa Windows机器上执行。



最近我发现了NodeJS和所有它的能力,除了使用Windows IE DOM进行操作。找不到如何运行我的旧WSH脚本来测试IE DOM,同时使用一些NodeJS模块来解析XML或运行测试报告服务器。



所以问题:是否可以运行WSH JavaScript和Node.js并使用这两个世界的所有好东西?
我恐怕不是,但希望有人有解决方法...



作为解决方法,也许有人在NodeJS中找到启动IE窗口访问的方式它的DOM(...添加自己的js脚本或运行SendKeys)!



我明白,NodeJS不是设计为执行Windows管理任务。

解决方案

虽然不符合 要求,@o_nix在评论中提出了 https://github.com/idobatter/node-win32ole



我建议这个模块满足从Google到达这些人的许多问题(和我一样)。
它也可以从这里下载到这里: https://www.npmjs.com/package/win32ole



该模块还有很多示例,例如:
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)//它可以工作(没有一元操作符!)
// while(!file.AtEndOfStream)//它不起作用
while(!file.AtEndOfStream._)// ***它的工作oops!
回调(file.ReadLine());
});
};
withEachLine(testfile,function(line){
console.log(line);
});

所以,对我来说,这和任何东西结合旧的WSH脚本一样好。当然,调整将会涉及到,但是这是再见WSH。



更具体地说,对于现在的问题,这是一个演示IE脚本的代码片段:
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< uris.length; ++ i){
console.log(uris [i]);
ie.Navigate(uris [i]);
win32ole.sleep(15000,true,true);
}
ie.Quit();


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.

解决方案

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 < uris.length; ++i){
    console.log(uris[i]);
    ie.Navigate(uris[i]);
    win32ole.sleep(15000, true, true);
  }
  ie.Quit();

这篇关于是否可以将WSH(wscript)与nodejs结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆