测试Angularjs警报与量角器 [英] to test Angularjs Alerts with protractor

查看:166
本文介绍了测试Angularjs警报与量角器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的量角器,我想测试警报
这是我的控制器:

i am new to protractor, i want to test alerts this is my controller:

testapp.controller('SampleCtl', ['$scope', function($scope) {
    $scope.age = 10;

    $scope.sub = function(a, b) {
        if(a>b){
            return a - b;
        }
        else{
            alert("please enter as first number is graterthan second number ");
        }
    };
}]);

这是我的html code:

this is my html code:

    <form onsubmit=""sub(a,b)>
           <input type="number" name="a" id="a">
           <input type="number" name="b" id="b">
           <input type=""submit>
    </form>

如果我们输入8,7的成功。
如果我们进入7,8失败最终给出了一个警告。
我们如何能够端到端测试警报,量角器。
任何一个请帮助我。先谢谢了。

if we enter 8,7 success. if we enter 7,8 failure end gives an alert. how can we end to end test that alert with protractor. any one please help me. thanks in advance.

推荐答案

您必须调用SWITCHTO()。量角器对象戒备()。这将返回其提供满足时,警报对象的承诺。

You have to call switchTo().alert() on the protractor-object. This will return a promise which provides an alert-object when fulfilled.

driver.switchTo().alert().then(function(alert) {
      return alert.dismiss();
    });

断言alert.getText() - 值来检查邮件本身

Assert the alert.getText()-value to check the message itself.

文档: http://angular.github.io/protractor/ #/ API?查看= webdriver.AlertPromise

这篇关于测试Angularjs警报与量角器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆