gpt4 book ai didi

javascript - 无法在 karma 中加载 phantomjs 网页和系统模块

转载 作者:搜寻专家 更新时间:2023-11-01 04:43:41 25 4
gpt4 key购买 nike

我正在尝试设置我的 phantomjs 测试以通过 karma 工作,但我无法通过 requirejs 加载 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

我正在使用 karma v0.12.16

最佳答案

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

关于javascript - 无法在 karma 中加载 phantomjs 网页和系统模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24791011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com