atecarlos / protractor-http-mock

A library designed to work alongside Protractor for setting up mocks for your HTTP ajax requests.
MIT License
173 stars 70 forks source link

Module 'httpMock' is not available #43

Closed TimMcCauley closed 9 years ago

TimMcCauley commented 9 years ago

I'm experiencing a problem testing with this cool library. I'm simply trying to test my login screen. Can anybody help? By the way, running the test environment of this lib does work flawlessly, I'm just experiencing problems with my own tests.

my test:

/* http://docs.angularjs.org/guide/dev_guide.e2e-testing */
var mock = require('../../node_modules/protractor-http-mock');
describe('login screen test', function() {
    beforeEach(function() {
        mock([{
            request: {
                path: /token/,
                method: 'POST',
            },
            response: {
                data: {
                    'hallo': 'dude'
                },
                status: 200
            }
        }]);
        browser.driver.get('http://localhost:8580');
        browser.driver.findElement(by.id('email')).sendKeys('willi@goedle.io');
        browser.driver.findElement(by.id('password')).sendKeys('pushit');
        browser.driver.findElement(by.id('submit')).click();
    });
    it('expects push model to be filled', function() {
        expect(mock.requestsMade()).toEqual([{
            url: /token/,
            method: 'POST'
        }]);
    });
    afterEach(function() {
        mock.teardown();
    });
});

config:

exports.config = {
    allScriptsTimeout: 11000,
    specs: ['e2e/*.js'],
    capabilities: {
        'browserName': 'chrome'
    },
    chromeOnly: true,
    //baseUrl: 'http://localhost:8580/',
    framework: 'jasmine',
    jasmineNodeOpts: {
        defaultTimeoutInterval: 30000
    },
    mocks: {
        dir: 'mocks', // path to directory with mocks
        default: []
    },
    onPrepare: function() {
        require('../node_modules/protractor-http-mock/index').config = {
            rootDirectory: __dirname,
            protractorConfig: "protractor-conf.js", // name of the config here
        };
    }
};

error:

   UnknownError: javascript error: [$injector:nomod] Module 'httpMock' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.18/$injector/nomod?p0=httpMock
JavaScript stack:
Error: [$injector:nomod] Module 'httpMock' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.3.18/$injector/nomod?p0=httpMock
    at http://localhost:8580/bower_components/angular/angular.js:63:12
    at http://localhost:8580/bower_components/angular/angular.js:1778:17
    at ensure (http://localhost:8580/bower_components/angular/angular.js:1702:38)
    at Object.module (http://localhost:8580/bower_components/angular/angular.js:1776:14)
    at eval (eval at executeAsyncScript (unknown source), <anonymous>:2:26)
    at eval (eval at executeAsyncScript (unknown source), <anonymous>:5:5)
    at eval (eval at executeAsyncScript (unknown source), <anonymous>:5:31)
    at executeAsyncScript (<anonymous>:321:26)
    at <anonymous>:337:29
    at callFunction (<anonymous>:229:33)
  (Session info: chrome=43.0.2357.134)
  (Driver info: chromedriver=2.15.322455 (ae8db840dac8d0c453355d3d922c91adfb61df8f),platform=Mac OS X 10.10.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 66 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'NeilMcCauley.local', ip: '192.168.0.12', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/var/folders/n7/rh782dqj3zx_3fk60qj0rk400000gn/T/.org.chromium.Chromium.Ouy9Xv}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=43.0.2357.134, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 0b656ce7fcca8c0da3438508e25028f5
    at Array.forEach (native)
From: Task: Asynchronous test function: it()
Error
    at [object Object].<anonymous> (/Users/NeilMcCauley/Documents/goedle/code/ui/test/e2e/scenarios_login.js:22:5)
    at Object.<anonymous> (/Users/NeilMcCauley/Documents/goedle/code/ui/test/e2e/scenarios_login.js:3:1)

Finished in 3.931 seconds
1 test, 1 assertion, 1 failure

Shutting down selenium standalone server.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
>>
Warning: Tests failed, protractor exited with code: 1 Use --force to continue.

my node modules:

{
  "version": "0.0.0",
  "private": true,
  "license": "MIT",
  "devDependencies": {
    "bower": "^1.3.1",
    "grunt": "^0.4.5",
    "grunt-cli": "^0.1.13",
    "grunt-contrib-clean": "^0.6.0",
    "grunt-contrib-concat": "^0.5.1",
    "grunt-contrib-copy": "^0.8.0",
    "grunt-contrib-cssmin": "^0.13.0",
    "grunt-contrib-jshint": "^0.11.2",
    "grunt-contrib-testem": "^0.5.16",
    "grunt-contrib-uglify": "^0.9.1",
    "grunt-githooks": "^0.3.1",
    "grunt-htmlhint": "^0.4.1",
    "grunt-ng-constant": "^1.1.0",
    "grunt-protractor-runner": "^2.1.0",
    "grunt-shell": "^1.1.2",
    "grunt-usemin": "^3.0.0",
    "http-server": "^0.6.1",
    "protractor": "^2.1.0",
    "protractor-http-mock": "^0.1.17",
    "shelljs": "^0.2.6",
    "sinon": "^1.15.4",
    "tmp": "0.0.23"
  },
  "scripts": {
    "postinstall": [
      "bower install",
      "grunt hookmeup"
    ],
    "preupdate-webdriver": "npm install",
    "update-webdriver": "webdriver-manager update",
    "preprotractor": "npm run update-webdriver",
    "protractor": "protractor test/protractor-conf.js",
    "update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + cat('bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\""
  }
}
TimMcCauley commented 9 years ago

Apparantly the reason for this is the browser.driver function. When I use the following it works:

browser.findElement(by.id('email')).sendKeys('willi@goedle.io');
browser.findElement(by.id('password')).sendKeys('pushit');
browser.findElement(by.id('submit')).click();```