无法在业力中加载phantomjs网页和系统模块

时间:2014-07-16 21:23:11

标签: javascript phantomjs karma-runner

我正在尝试设置我的phantomjs测试以通过业力工作,但我无法加载phantomjs'网页'和'系统'模块虽然需要。

这是karma.config.js

的一部分
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',
],

这是phantomjs测试代码:

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('');        
    }); 
  }
];

这是我看到

的错误
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

我正在使用业力v0.12.16

1 个答案:

答案 0 :(得分:-3)

“Require”仅在NodeJS环境中工作,因此无法从Karma测试中访问,因为Karma启动浏览器并直接将代码注入其中,因此没有NodeJS的东西。同样的问题描述为here