Setup:
beforeEach(function () {
const targetUrl = browser.baseUrl + '/#/Editor/AddRule';
browser.ignoreSynchronization = true;
browser.get(targetUrl);
browser.wait(
function () {
return browser.getCurrentUrl().then(
function (url) {
return targetUrl == decodeURIComponent(url);
});
}, 4000, 'taking too long to load');
browser.addMockModule('httpMocker', function () {
angular.module('httpMocker', ['ngApp', 'ngMockE2E'])
.run(function ($httpBackend) {
console.log("started");
// Mock a response from server
$httpBackend.whenPOST(browser.baseUrl + '/Editor/SaveRule')
.respond(500, {});
});
});
});
I am trying to mock a controller which has a scope variable that is then passed into an angular service and finally posted the the server. The server has endpoint:
browser.baseUrl + '/Editor/SaveRule' and method is http post.
The test that runs against I want to run against it:
it('Should present a success modal dialog upon successful rule save', function () {
var name = element(by.css('[name="Name"]'));
name.sendKeys('Rule Name 1');
var ErrorCode = element(by.css('[name="ErrorCode"]'));
ErrorCode.sendKeys('Error or warning Code');
var englishLanguage = element(by.css('[name="Language0"]'));
englishLanguage.sendKeys('English warning language');
const ruleSetCheckbox = element(by.css('[name="RuleSet1"]'));
ruleSetCheckbox.click();
browser.pause();
const button = element(by.css('[ng-click="form.$valid && save()"]'));
button.click();
browser.pause();
});
If I take control when the protractor pauses and manually click the 'save' button on my UI, monitoring the network tab shows that this request is actually being made to the server and coming back with a 200 rather than a 500, which is what I want. I've already checked to make sure the endpoints are the same. what am I doing wrong?