Angularjs 修改量角器测试中的角度变量

Angularjs 修改量角器测试中的角度变量,angularjs,jasmine,protractor,angularjs-e2e,e2e-testing,Angularjs,Jasmine,Protractor,Angularjs E2e,E2e Testing,我正在写e2e测试。我正在运行AngularJS应用程序,作为Javascript测试运行者,我正在使用grunt。在我的html中有div标记,它表示通知警报。当没有通知时,此标记将隐藏,并根据通知类型以绿色或红色弹出。我想测试它是否会在有一些通知时显示,以及颜色是否会根据通知类型而改变。为了测试这一点,我需要更新在作用域上公开的模型值。这是我的html代码: <div id="notificationAlert" ng-repeat="notification in model.not

我正在写e2e测试。我正在运行AngularJS应用程序,作为Javascript测试运行者,我正在使用grunt。在我的html中有div标记,它表示通知警报。当没有通知时,此标记将隐藏,并根据通知类型以绿色或红色弹出。我想测试它是否会在有一些通知时显示,以及颜色是否会根据通知类型而改变。为了测试这一点,我需要更新在作用域上公开的模型值。这是我的html代码:

<div id="notificationAlert" ng-repeat="notification in model.notifications" class="alert alert-{{notification.type}}" role="alert">
   <button type="button" ng-hide="notification.type == 'success'" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
   </button> {{notification.msg}}
</div>

但是现在我的测试失败了,出现了以下错误:NoSuchElementError:使用locator:By.id(“notificationAlert”)

找不到任何元素,而应该使用模拟变量或步骤来复制绿色或红色警报,而不是自己更改模型以满足测试用例的需要。您能提供一些链接给我从哪里开始吗。我以前从未做过。因此,我真的不知道如何模拟它。如果
model.notifications
基于HTTP响应,您可以在grunt级别模拟它,就像在这里的博客文章中一样,如果它是严格的前端行为,您应该在量角器中重现步骤以实现相同的行为。通过直接从测试中设置模型,您将面临测试通过而测试不能通过的正-假测试风险
'use strict';

 describe('my app', function() {


beforeEach(function(){
    browser.driver.get('http://localhost:9000');
    browser.waitForAngular();
});

describe('home page initialization', function(){

    it('should alert green when success', function(){
        var alert = element(by.id('notificationAlert'));
        alert.evaluate('model.notifications = [{type: "success", msg: "Test Message"}];');
        expect(alert.getAttribute('class')).toEqual("alert alert-success");
    })

   })
});