简体   繁体   English

使用场景测试运行程序进行AngularJS e2e测试-忽略alert()

[英]Angularjs e2e testing with scenario test runner - ignore alert()

I'm creating the e2e test for my application and I have a problem when I'm testing the login page. 我正在为我的应用程序创建e2e测试,并且在测试登录页面时遇到问题。 I want to test both the correct login and the incorrect one but the problem is that when you enter incorrect credentials you get an alert("Your email or password is incorrect") and that also gets triggered in the e2e test which means I have to click the "OK" button on the alert() in order to continue the test. 我想同时测试正确的登录名和不正确的登录名,但是问题是,当您输入不正确的凭据时,您会收到警报(“您的电子邮件或密码不正确”),并且在e2e测试中也被触发,这意味着我必须单击alert()上的“确定”按钮以继续测试。 Is there anyway to ignore the alert() in the test ? 无论如何,有没有忽略测试中的alert()?

Please take a look at https://github.com/katranci/Angular-E2E-Window-Dialog-Commands 请看看https://github.com/katranci/Angular-E2E-W​​indow-Dialog-Commands

You can add alertOK(); 您可以添加alertOK(); in your test, before the alert will be shown and this let you skipped it. 在测试中,在显示警报之前,您可以跳过警报。

Granted this wouldn't necessarily qualify as E2E anymore - but you could abstract alert to a service in whatever directive or controller or service has the alert() call and then just mock that particular service. 当然,不必再将其视为E2E了-但您可以使用任何具有alert()调用的指令,控制器或服务,将alert()抽象到服务,然后仅模拟该特定服务。 Here's an example: 这是一个例子:

Javascript 使用Javascript

var myApp = angular.module('myApp', []);

myApp.factory('alert', function () {
  return function (message) {
    alert(message);
  };
});

myApp.controller('MyController', function ($scope, alert) {
  $scope.alert = alert;
});

View 视图

<body ng-app="myApp" ng-controller="MyController">
  <div ng-init="alert('test')"></div>
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM