为什么casperjs(phantomjs引擎-ubuntux86_64 16.04)在命令行崩溃?

为什么casperjs(phantomjs引擎-ubuntux86_64 16.04)在命令行崩溃?,phantomjs,casperjs,Phantomjs,Casperjs,phantomjs访问的amazon_login.js中的代码: root@krusty:/www/nuper.com# /root/phantomjs-2.1.1-linux-x86_64/bin/phantomjs ./amazon_login.js Title: Amazon Sign In Capping Done FAIL TypeError: undefined is not a function (evaluating 'casper.done()') # type: unc

phantomjs访问的amazon_login.js中的代码:

root@krusty:/www/nuper.com# /root/phantomjs-2.1.1-linux-x86_64/bin/phantomjs ./amazon_login.js
Title: Amazon Sign In
Capping
Done
FAIL TypeError: undefined is not a function (evaluating 'casper.done()')
#    type: uncaughtError
#    error: undefined is not a function (evaluating 'casper.done()')
#           phantomjs://code/amazon_login.js:54:16
#           checkStep@phantomjs://platform/casper.js:423:28
#    stack: not provided
PASS Untitled suite in null
您在最后一行中已经使用了.done方法,并且您正在Casper对象而不是测试对象上调用它。Done方法是Casper中Tester模块的方法,您在不使用Tester模块的情况下调用Casper

在第一种情况下,当您的代码中断时,我建议您侦听所有错误事件,如page.error、resource.error


希望有帮助

如果您提供代码,也许有人可以帮助您:好的,更新了一点。
root@krusty:/www/nuper.com# /root/phantomjs-2.1.1-linux-x86_64/bin/phantomjs ./amazon_login.js
Title: Amazon Sign In
Capping
Done
FAIL TypeError: undefined is not a function (evaluating 'casper.done()')
#    type: uncaughtError
#    error: undefined is not a function (evaluating 'casper.done()')
#           phantomjs://code/amazon_login.js:54:16
#           checkStep@phantomjs://platform/casper.js:423:28
#    stack: not provided
PASS Untitled suite in null
//phantom.casperPath = '/root/node_modules/casperjs';
//phantom.injectJs('/root/node_modules/casperjs/bin/bootstrap.js');

// if you need the test environment then you need this
//phantom.casperTest = true;

var casper = require('casper').create();

casper.userAgent('Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0');
phantom.cookiesEnabled = true;

var AMAZON_USER = '<removed>';
var AMAZON_PASS = '<removed>';

casper.start('https://www.amazon.com/').thenClick('a#nav-link-accountList', 
function() {
this.echo('Title: ' + this.getTitle());

var emailInput = 'input#ap_email';
var passInput  = 'input#ap_password';

this.mouseEvent('click', emailInput, '15%', '48%');
this.sendKeys('input#ap_email', AMAZON_USER);

    this.wait(3000, function() {
        this.mouseEvent('click', passInput, '12%', '67%');
        this.sendKeys('input#ap_password', AMAZON_PASS);

        this.mouseEvent('click', 'input#signInSubmit', '50%', '50%');
    });
});

casper.then(function(e) {
    this.wait(5000, function() {
        this.echo('Capping');
        this.capture('amazon.png');
    });
});

/* casper.thenOpen('https://www.amazon.com/ss/help/contact/?_encoding=UTF8&marketplaceID=ATVPDKIKX0DER&ref_=v_sp_contact_seller&sellerID=A39LA0PG14JNN7',
        function() {
        this.echo('Second Page: ' + this.getTitle());
        this.wait(3000, function() {
        this.mouseEvent('click', 'span#a-autoid-7', '12%', '67%');
        this.mouseEvent('click', 'a#preOrderSubject_0', '12%', '67%');
        this.mouseEvent('click', 'input#a-button-input', '50%', '50%');
        this.echo('Title: ' + this.getTitle());

    });
});
*/
casper.run(function() {
    console.log('Done');

    casper.done();
});