从Protractor测试修改角度变量

时间:2015-03-02 14:25:03

标签: angularjs jasmine protractor angularjs-e2e e2e-testing

我正在写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>

如何从我的e2e测试中设置model.notifications?

更新:我使用evaluate函数在html元素上设置值,并且有我当前的e2e测试:

'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");
    })

   })
});

但是现在我的测试失败并出现以下错误:NoSuchElementError:找不到使用locator的元素:By.id(“notificationAlert”)

0 个答案:

没有答案