Casperjs:“TypeError:casper.on不是函数”

时间:2017-03-04 01:38:41

标签: node.js casperjs

我的代码非常简单:

let casper = require('casper').create({
  pageSettings: {
    loadImages:  false,
    loadPlugins: false,
    userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
  }
});

casper.on("page.error", (msg, trace) => {
  this.echo("Page Error: " + msg, "ERROR");
});

casper.on("resource.received", (resource) => {
  console.log('***', resource);
});

casper.start('https://my-app.com/');

casper.then(() => {
  this.test.assertExists('#login-form', 'Form is found');
  this.fill('#login-form', {
    'user-email': 'user@mailcom',
    'pin-number': '1234',
  }, true);
});

casper.run();

当我使用node test.js时,我会收到下一个错误:

WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
Login...
E:\app\test.js:32
    casper.on("page.error", (msg, trace) => {
           ^

TypeError: casper.on is not a function
    at login (E:\Proyectos\btc-watcher\app\test.js:32:12)
    at Object.<anonymous> (E:\Proyectos\btc-watcher\app\test.js:61:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Eduardo\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
npm ERR! node v6.10.0
npm ERR! npm  v4.3.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! btc-watcher@ test: `node --debug=5858 test.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the btc-watcher@ test script 'node --debug=5858 test.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the btc-watcher package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node --debug=5858 test.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs btc-watcher
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls btc-watcher
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Eduardo\AppData\Roaming\npm-cache\_logs\2017-03-04T01_36_28_318Z-debug.log

请帮忙!

0 个答案:

没有答案