2014-07-16 18 views
5

Karma olsa da phantomjs testlerimi kurmaya çalışıyorum, ancak phantomjs 'web sayfası' ve 'system' modüllerini requirejs yükleyemiyorum.phantomjs web sayfası ve sistem modülleri karma yüklenemedi karma

var page = require('webpage').create(), testindex = 0, loadInProgress = false; 

var clientURL = "http://localhost:7001/client/"; 

page.onConsoleMessage = function(msg) { 
    console.log(msg); 
}; 

page.onLoadStarted = function() { 
    loadInProgress = true; 
    console.log("load started"); 
}; 

page.onLoadFinished = function() { 
    loadInProgress = false; 
    console.log("load finished"); 
}; 

console.log(''); 
console.log("loginSuccess test BEGIN"); 
console.log(''); 

var steps = [ 
    function() { 
    console.log("Load Page"); 
    page.open(clientURL); 
    }, 
    function() { 
    console.log("Populate Username and Password"); 
    page.evaluate(function() { 
     var usernameField = Ext.ComponentQuery.query('textfield#login-username-textfield')[0]; 
     var passwordField = usernameField.next('textfield#login-password-textfield');   
     usernameField.setValue('testuser'); 
     passwordField.setValue('testpassword'); 

    }); 
    }, 
    function() { 
    console.log("Fire Submit Button"); 
    page.evaluate(function() { 
     var button = Ext.ComponentQuery.query('#login-button')[0]; 
     button.fireEvent('click', button); 
    }); 
    }, 

    function() { 
    console.log("Verify redirect on successful login"); 
    page.evaluate(function() { 
     console.log(location.href); 
     console.log(''); 
     if (location.href.indexOf("/clientMB/") > -1) { 
      console.log("loginSuccess test SUCCESSFUL"); 
     } 
     else { 
      console.log("loginSuccess test FAILURE"); 
     } 
     console.log('');   
    }); 
    } 
]; 

bu i

PhantomJS 1.9.7 (Windows 7) ERROR 
    Error: Module name "webpage" has not been loaded yet for context: _. Use requi 
re([]) 
    http://requirejs.org/docs/errors.html#notloaded 
    at C:/Users/shining.sun/AppData/Roaming/npm/node_modules/requirejs/require.js? 
d84131f3e98422a49aa91d4f87cf96b245726d96:141 

görüyorum hatadır: Burada

bu phantomjs testi kodudur

module.exports = function(config) { 
    config.set({ 

// base path that will be used to resolve all patterns (eg. files, exclude) 
basePath: '.', 


// frameworks to use 
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter 
frameworks: ['requirejs'], 

// list of files/patterns to load in the browser 
files: [ 
    '../ext/ext-all.js', 
    'test/jasmine/jasmine/jasmine.css', 
    'test/jasmine/jasmine/jasmine.js', 
    'test/jasmine/jasmine/jasmine-html.js', 
    'resources/webclientLogin-all.css', 
    'resources/webclient/webclient.css', 
    'app/controller/login/main.js', 
    'app/view/login/FormContainer.js', 
    'app/view/login/MustChangePasswordForm.js', 
    'app/view/MainView.js', 
    'app/Application.js', 
    'development.js', 
    'app.js', 
    'test/phantomjs/loginSuccess.js', 
], 

karma.config.js parçasıdır karma kullanıyorum v0.12.16

cevap

-3

"Require" sadece NodeJS ortamında çalışıyor, bu yüzden Karma testlerinden ulaşılamaz çünkü Karma bir tarayıcı başlatır ve doğrudan kodunuzu içine enjekte eder, dolayısıyla NodeJS öğesi yoktur. Aynı sorun, here

açıklanmaktadır.