3

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

更新:我使用评估函数在 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: No element found using locator: By.id("notificationAlert")

4

0 回答 0