gpt4 book ai didi

javascript - 模块 'httpMock' 不可用

转载 作者:行者123 更新时间:2023-11-27 23:53:59 25 4
gpt4 key购买 nike

这是使用 Protractor http 模拟进行 Protractor 测试时的错误消息:

JavascriptError: javascript error: [$injector:nomod] Module 'httpMock' is not available! You eit her misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

conf.js:

// An example configuration file.
exports.config = {
directConnect: true,
// Selenium server
SeleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
//baseUrl: 'http://develop.garbo.livebranches.com/sv-SE/',
//Framework to use. Jasmine 2 is recommended.
framework: 'jasmine2',
//frameworks: ['mocha', 'jasmine'],

// Spec patterns are relative to the current working directly when
// protractor is called.
//specs: ['testmain.js','testlogin.js'],
//specs: ['testmain.js','testteaPartyList.js','testpositionSearchIndex.js','testpositionList.js'],
specs: ['testlogin.js'],

//Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 250000
},
mocks: {
dir: '../node_modules/protractor-http-mock',
//dir: 'mocks',
default: []
},
//=====login begin =====
onPrepare: function() {
require("protractor-http-mock").config = {
rootDirectory: '../node_modules/protractor-http-mock/lib',
//rootDirectory: __dirname,

protractorConfig: "conf.js", // name of the config here
};

}

//=====login end========


};

teSTLogin.js

describe('angularjs homepage', function() {

//browser.ignoreSynchronization = true;
it('should login', function() {
var mock = require('protractor-http-mock');
var todoList;

beforeEach(function() {

var url ='http://dev.etest.com:285/Actor/tbUsers/LoginAndGet';

var req = {Mobile:'14500000006',Password:'123456'};

var rep = {UserId:164,AccountId:328,Token:'328:dc91d536ab424aa0b8d7f1ecaf64c55b',Id:328};

mock([{
request: {
path: url,
method: 'POST',
data:req,
},
response: {
data: rep,
}
}]);
});
afterEach(function() {
mock.teardown();
});

browser.get('http://localhost:2024/daNiuJob/www/ionicWeb/index.html#/login');

console.log('mock='+mock);

element(by.model('data.userName')).sendKeys('14500000006');
element(by.model('data.password')).sendKeys('123456');
var btnlogin = element(by.id('Regist')).element(by.tagName('a'));

expect(browser.getTitle()).toEqual('userlogin');

browser.getTitle().then(function(text){

console.log('title='+text);
});

//cause mock error
expect(mock.requestsMade()).toEqual([
{ url : 'http://dev.etest.com:285/Actor/tbUsers/LoginAndGet', method : 'GET' },
]);

btnlogin.click();


browser.sleep(8000);

});


});

为什么找不到httpMock,谢谢!

注意:

C:\Users\HQ-XXX\AppData\Roaming\npm\node_modules\protractor\node_modules\protractor-http-mock

这是“protractor-http-mock”的路径

最佳答案

您应该提供 http-mock 模块文件夹的路径,而不是其中的 lib 文件夹。将 onPrepare() 函数内 protractor-http-mock 的 rootDirectory 路径更改为 -

rootDirectory: 'C:\Users\HQ-XXX\AppData\Roaming\npm\node_modules\protractor\node_modules\protrac‌​tor-http-mock ',

如果您需要提供相对路径,请按如下方式更改 -

rootDirectory: '..\node_modules\protrac‌​tor-http-mock ',

希望这有帮助。

关于javascript - 模块 'httpMock' 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32433546/

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