2016-07-20 44 views
0

我正在使用casperjs作爲測試工具包/框架的自動化項目。在我的一個測試中,腳本應該發送自動郵件給組織中的特定主管。在casperjs中執行node.js腳本或反之亦然

問題是,是否可以將node.js和casperjs/phantomjs腳本組合到一個文件中?或者是否可以從casperjs調用外部腳本?

感謝提前任何答覆, 亞歷

回答

0

雖然這兩種方式都是可能的,我相信最簡單的解決辦法是從CasperJS腳本啓動郵件/腳本。

CasperJS在引擎蓋下使用PhantomJS,後者能夠執行/產生子進程。

var childProcess; 
    try { 
    childProcess = require("child_process"); 
    } catch (e) { 
    this.log(e, "error"); 
    } 
    if (childProcess) { 
    childProcess.execFile("/bin/bash", ["mycommand.sh", args1, args2, args3], null, function (err, stdout, stderr) { 
     this.log("execFileSTDOUT:", JSON.stringify(stdout), 'debug'); 
     this.log("execFileSTDERR:", JSON.stringify(stderr), 'debug'); 
    }); 
    this.log("Done", "debug"); 
    } else { 
    this.log("Unable to require child process", "warning"); 
    } 

https://gist.github.com/clochix/6882184