3

设置:

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, {});
            });
    });
});

我正在尝试模拟一个控制器,该控制器具有一个范围变量,然后将其传递给角度服务并最终发布服务器。服务器有端点:

browser.baseUrl + '/Editor/SaveRule' and method is http post.

运行的测试我想运行它:

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();
});

如果我在量角器暂停并手动单击 UI 上的“保存”按钮时进行控制,则监视网络选项卡显示此请求实际上是向服务器发出的,并返回 200 而不是 500,这就是我想。我已经检查以确保端点是相同的。我究竟做错了什么?

4

0 回答 0