Protractor : browser.addMockModule is not executing in cucumber

483 Views Asked by At

I have protractor with cucumber step-up and unable to mock $http call using browser.addMockModule

step definition

var {defineSupportCode} = require('cucumber');

defineSupportCode(function ({
    Given,
    When,
    Then,
    setDefaultTimeout,
    Before,
    After
}) {

    Before(function () {

        console.log("hello from before hook");

        browser.addMockModule('httpMocker', function () {
            console.log("mock executing");
            angular.module('httpMocker', ['ngMockE2E', "mocking"])
                .run(function ($httpBackend) {
                    console.log("inside");
                    $httpBackend.whenGET(
                        'localhost:61324/api/album')
                        .respond([
                            {
                                albumId: 1,
                                id: 1,
                                title: "accusamus beatae ad",
                                url: "http://placehold.it/600/92c952",
                                thumbnailUrl: "http://placekitten.com/g/200/300"
                            }
                        ])

                })
        });


    });

    Given(/^I have all album data$/, function (data, done) {

        browser.driver.get(appurl);

          done();
    });

addMockModule is never executed.

Also, let me know where to add reference of angular-mocks.

my environment is

protractor-cucumber-framework : 3.1.0
protractor : 5.1.1
cucumber : 2.0.0-rc.9
angular : 1.6.3
angular-mocks : 1.4.9

1

There are 1 best solutions below

0
Abhishek Shukla On

change browser.driver.get(appurl) to browser.get(appurl) and this will work.