2015-09-10 14 views
6

modülünü gerektirir. Bir süredir okuyordum ve bunu doğru göremiyorum. İçinde betiklerimle bir dosya var login_process.js ve başka bir dosyada routines.js gerektirmesi gereken modül işlevleri var.Casper js,

var routine = require('../routines'); numaralı hatta ayrıştırma hatası alıyorum. Bu hata routines.js dosyasında ancak düğüm (sözdizimini test etmek için kullanılır) olabilir ve jshint sadece casper ve diğer kütüphanelerin undefined (yani phantomjs, ect gerektirir) olduğunu söylüyor demektir. routines.js:

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

exports.login = function(email, pass, test) { 
    casper.then(function() { 
     this.withFrame(0, function() { 
      this.waitUntilVisible('form#login-form', function() { 
       this.fill('form#login-form', { 
        email: email, 
        password: pass 
       }, false); 
      }); 
     }); 
    }); 
    casper.then(function(){ 
     casper.withFrame(0, function() { 
      this.click("#modalButtonLogin"); 
     }); 
    }); 
}; 

exports.signup = function(first_name, last_name, email, pass, other_pass, test) { 
    casper.then(function() { 
     this.withFrame(0, function() { 
      this.waitUntilVisible('form#signup-form', function() { 
       this.fill('form#signup-form', { 
       first_name: first_name, 
       last_name: last_name, 
       login: email, 
       password: pass, 
       re_enter_password: 'pass' 
      }, false); 
      }); 
     }); 
    }); 
    casper.then(function(){ 
     casper.withFrame(0, function() { 
      this.click("#modalButton"); 
     }); 
    }); 
}; 

login_process.js şu şekildedir:

dosyaları

olan

// var require = patchRequire(require); 
var routine = require('../routines'); 

casper.test.begin('Logs in', 1, function(test) { 

    var fs = require('fs') 
    var data = fs.read('../cookies.txt'); 
    phantom.cookies = JSON.parse(data); 

    casper.start("https://web.witkit.com/#") 

    .wait(1000, function(){ 
     routine.login('****@witkit.com', '******', test); 
    }) 

    .wait(1000, function(){ 
     this.withFrame(0, function() { 
      test.assertExists('.wkKitTitle'); 
     }); 
    }) 

    .then(function(){ 
     phantom.clearCookies(); 
     casper.echo(JSON.stringify(routine.login)+ "here") 
    }) 

    .run(function() { 
     test.done(); 
    }); 

}); 

casper.test.begin('Wrong login warning', 2, function(test) { 

    casper.start("https://web.witkit.com/#") 

    .then(function(){ 
     phantom.clearCookies(); 
    }) 

    .wait(1000, function(){ 
     routine.login('****@witkit.com', '******', test); 
    }) 

    .wait(1000, function(){ 
     this.withFrame(0, function() { 
      test.assertExists('.wkErrorMessageText'); 
      test.assertSelectorHasText('.wkErrorMessageText', 'Wrong email or password'); 
     }); 
    }) 

    .then(function(){ 
     phantom.clearCookies(); 
    }) 

    .run(function() { 
     test.done(); 
    }); 

}); 


casper.test.begin('Directs to correct url on form submission', 2, function(test) { 

    casper.start("https://web.witkit.com/#") 

    .then(function(){ 
     test.assertUrlMatch('https://web.witkit.com/#') 
    }) 

    .wait(1000, function(){ 
     routine.login('*******@witkit.com', '**', test); 
    }) 

    .wait(1000, function(){ 
     test.assertUrlMatch('https://web.witkit.com/#kit/176********') 
    }) 

    .then(function(){ 
     phantom.clearCookies(); 
    }) 

    .run(function() { 
     test.done(); 
    }); 

}); 

Çıktı:

Test file: login_process.js 
SyntaxError: Parse error 
FAIL SyntaxError: Parse error 
# type: error 
# file: login_process.js 
# subject: false 
# error: "SyntaxError: Parse error" 
# stack: 
# Logs in 
FAIL TypeError: 'undefined' is not a function (evaluating 'routine.login('[email protected]', 'caspertest', test)') 
# type: uncaughtError 
# file: login_process.js:13 
# error: 'undefined' is not a function (evaluating 'routine.login('*******@witkit.com', '*****', test)') 
#   TypeError: 'undefined' is not a function (evaluating 'routine.login('[email protected]', 'caspertest', test)') 
#    at login_process.js:13 
#    at _check (/usr/local/lib/node_modules/casperjs/modules/casper.js:2034) 
# stack: not provided 
# Wrong login warning 
FAIL TypeError: 'undefined' is not a function (evaluating 'routine.login('****@witkit.com', '****', test)') 
# type: uncaughtError 
# file: login_process.js:42 
# error: 'undefined' is not a function (evaluating 'routine.login('****@witkit.com', '****', test)') 
#   TypeError: 'undefined' is not a function (evaluating 'routine.login('[email protected]', 'caspertest', test)') 
#    at login_process.js:42 
#    at _check (/usr/local/lib/node_modules/casperjs/modules/casper.js:2034) 
# stack: not provided 
# Directs to correct url on form submission 
PASS Current url matches the provided pattern 
FAIL TypeError: 'undefined' is not a function (evaluating 'routine.login('[email protected]', 'caspertest', test)') 
# type: uncaughtError 
# file: login_process.js:72 
# error: 'undefined' is not a function (evaluating 'routine.login('******@witkit.com', '******', test)') 
#   TypeError: 'undefined' is not a function (evaluating 'routine.login('[email protected]', 'caspertest', test)') 
#    at login_process.js:72 
#    at _check (/usr/local/lib/node_modules/casperjs/modules/casper.js:2034) 
# stack: not provided 
FAIL 5 tests executed in 4.196s, 1 passed, 4 failed, 0 dubious, 0 skipped. 

Details for the 4 failed tests: 

In login_process.js 
    Untitled suite in login_process.js 
    error: SyntaxError: Parse error 
In login_process.js:13 
    Logs in 
    uncaughtError: TypeError: 'undefined' is not a function (evaluating 'routine.login('******@witkit.com', '******', test)') 
In login_process.js:42 
    Wrong login warning 
    uncaughtError: TypeError: 'undefined' is not a function (evaluating 'routine.login('*****@witkit.com', '*****', test)') 
In login_process.js:72 
    Directs to correct url on form submission 
    uncaughtError: TypeError: 'undefined' is not a function (evaluating 'routine.login('*****@witkit.com', '*****', test)') 
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/local/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match. 
+0

CasperJS bağımsız bir programdır. Node.js. ile ilgisi yok. Nasıl koşuyorsun? –

+0

@ArtjomB. Başarısız olduğunda sözdizimi hataları için sınamaları denetlemek için bu düğümü kullanıyorum (birisi bunu yaptığımı önerdi ve oldukça iyi çalışıyor) sonra tüm testleri çalıştırmak için grunt-casper kullanıyorum. Ama ben hata ayıklama Ben komut satırından 'casperjs testi login_process.js --engine = phantomjs' koştuğum zaman – ReganPerkins

+0

Sözdizimi hatası nerede olduğunu belirlemek için eslint veya benzeri bir şey kullanın. –

cevap